mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Compare commits
28
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b47557f40 | ||
|
|
13ea7c192e | ||
|
|
0d6bee2025 | ||
|
|
fba950aeb5 | ||
|
|
a047f913b4 | ||
|
|
44805ce481 | ||
|
|
a8eec32842 | ||
|
|
5d075e02ab | ||
|
|
6edc623c13 | ||
|
|
027cd819f8 | ||
|
|
ef55e80c35 | ||
|
|
3666aac2a1 | ||
|
|
f58f75ae8b | ||
|
|
22885e0978 | ||
|
|
a988238bb4 | ||
|
|
11197139f9 | ||
|
|
9ccad00888 | ||
|
|
32ff6570cf | ||
|
|
80bb72ef79 | ||
|
|
e45f167d2b | ||
|
|
7e755916c0 | ||
|
|
5915b96d98 | ||
|
|
b327607be3 | ||
|
|
e23b5031ee | ||
|
|
104a08c75a | ||
|
|
ddc23e3800 | ||
|
|
a1959369c5 | ||
|
|
6c4c1dab3b |
No files matched your search
+43
-3
@@ -15,6 +15,7 @@ The OAuth system consists of three main components:
|
|||||||
- **GitHub** - Git repository hosting (with PKCE support)
|
- **GitHub** - Git repository hosting (with PKCE support)
|
||||||
- **Netlify** - Static site deployment
|
- **Netlify** - Static site deployment
|
||||||
- **Vercel** - Static site deployment
|
- **Vercel** - Static site deployment
|
||||||
|
- **OpenRouter** - AI model routing (with PKCE support)
|
||||||
|
|
||||||
## File Structure
|
## File Structure
|
||||||
|
|
||||||
@@ -24,11 +25,13 @@ src/
|
|||||||
│ ├── useOAuth.ts # Generic OAuth hook (core logic)
|
│ ├── useOAuth.ts # Generic OAuth hook (core logic)
|
||||||
│ ├── useGitHubOAuth.ts # GitHub-specific configuration
|
│ ├── useGitHubOAuth.ts # GitHub-specific configuration
|
||||||
│ ├── useNetlifyOAuth.ts # Netlify-specific configuration
|
│ ├── useNetlifyOAuth.ts # Netlify-specific configuration
|
||||||
│ └── useVercelOAuth.ts # Vercel-specific configuration
|
│ ├── useVercelOAuth.ts # Vercel-specific configuration
|
||||||
|
│ └── useOpenRouterOAuth.ts # OpenRouter-specific configuration
|
||||||
├── pages/
|
├── pages/
|
||||||
│ ├── GitHubOAuth.tsx # GitHub OAuth callback page
|
│ ├── GitHubOAuth.tsx # GitHub OAuth callback page
|
||||||
│ ├── NetlifyOAuth.tsx # Netlify OAuth callback page
|
│ ├── NetlifyOAuth.tsx # Netlify OAuth callback page
|
||||||
│ └── VercelOAuth.tsx # Vercel OAuth callback page
|
│ ├── VercelOAuth.tsx # Vercel OAuth callback page
|
||||||
|
│ └── OpenRouterOAuth.tsx # OpenRouter OAuth callback page
|
||||||
└── AppRouter.tsx # Routes for OAuth callbacks
|
└── AppRouter.tsx # Routes for OAuth callbacks
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -190,6 +193,7 @@ const config: OAuthConfig = {
|
|||||||
- ✅ GitHub - Supports PKCE (enabled)
|
- ✅ GitHub - Supports PKCE (enabled)
|
||||||
- ❌ Netlify - Doesn't support PKCE (disabled)
|
- ❌ Netlify - Doesn't support PKCE (disabled)
|
||||||
- ❌ Vercel - Doesn't support PKCE (disabled)
|
- ❌ Vercel - Doesn't support PKCE (disabled)
|
||||||
|
- ✅ OpenRouter - Requires PKCE (enabled)
|
||||||
|
|
||||||
### Scope Parameter
|
### Scope Parameter
|
||||||
|
|
||||||
@@ -199,6 +203,42 @@ The `scope` parameter is optional in the OAuth configuration. Some providers (li
|
|||||||
- ✅ GitHub - Uses scopes (e.g., `repo workflow`)
|
- ✅ GitHub - Uses scopes (e.g., `repo workflow`)
|
||||||
- ❌ Netlify - No scope parameter (permissions set in app settings)
|
- ❌ Netlify - No scope parameter (permissions set in app settings)
|
||||||
- ✅ Vercel - Uses scopes (e.g., `deployments:write projects:read`)
|
- ✅ Vercel - Uses scopes (e.g., `deployments:write projects:read`)
|
||||||
|
- ❌ OpenRouter - No scope parameter (uses PKCE for authorization)
|
||||||
|
|
||||||
|
### OpenRouter Custom OAuth Implementation
|
||||||
|
|
||||||
|
OpenRouter uses a custom OAuth flow that differs from the standard OAuth 2.0 specification. Instead of using the generic `useOAuth` hook, it has a dedicated `useOpenRouterOAuth` hook with the following key differences:
|
||||||
|
|
||||||
|
1. **No Client Credentials**: OpenRouter doesn't require client ID or client secret - it uses PKCE only
|
||||||
|
2. **Authorization URL**: Uses `callback_url` parameter instead of `redirect_uri`
|
||||||
|
3. **Token Exchange**: Posts to `/api/v1/auth/keys` with a simplified request body
|
||||||
|
4. **Response Format**: Returns `{ key }` instead of standard `{ access_token }`
|
||||||
|
5. **PKCE Required**: Must use PKCE with S256 code challenge method
|
||||||
|
6. **No User Info**: Doesn't provide a user info endpoint after authentication
|
||||||
|
7. **No Environment Variables**: No configuration needed - works out of the box
|
||||||
|
|
||||||
|
**Authorization URL Format:**
|
||||||
|
```
|
||||||
|
https://openrouter.ai/auth?callback_url=<REDIRECT_URI>&code_challenge=<CHALLENGE>&code_challenge_method=S256
|
||||||
|
```
|
||||||
|
|
||||||
|
**Token Exchange Request:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": "<CODE_FROM_QUERY_PARAM>",
|
||||||
|
"code_verifier": "<CODE_VERIFIER>",
|
||||||
|
"code_challenge_method": "S256"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Token Exchange Response:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"key": "sk-or-v1-..."
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
This custom implementation is fully contained in `useOpenRouterOAuth.ts` and doesn't rely on the generic OAuth hook. Unlike other providers, OpenRouter's OAuth doesn't require any environment variables or application registration - it works immediately without configuration.
|
||||||
|
|
||||||
## Adding a New OAuth Provider
|
## Adding a New OAuth Provider
|
||||||
|
|
||||||
@@ -244,7 +284,7 @@ export function useNewProviderOAuth() {
|
|||||||
redirectUri: window.location.origin + '/oauth/newprovider',
|
redirectUri: window.location.origin + '/oauth/newprovider',
|
||||||
usePKCE: false, // Set to true if provider supports PKCE
|
usePKCE: false, // Set to true if provider supports PKCE
|
||||||
getUserInfo: async (accessToken: string, corsProxy: string) => {
|
getUserInfo: async (accessToken: string, corsProxy: string) => {
|
||||||
const userUrl = proxyUrl(corsProxy, 'https://api.provider.com/user');
|
const userUrl = proxyUrl({ template: corsProxy, url: 'https://api.provider.com/user' });
|
||||||
const userResponse = await fetch(userUrl, {
|
const userResponse = await fetch(userUrl, {
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Bearer ${accessToken}`,
|
'Authorization': `Bearer ${accessToken}`,
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://opencode.ai/config.json",
|
||||||
|
"mcp": {
|
||||||
|
"nostr": {
|
||||||
|
"type": "local",
|
||||||
|
"command": ["npx", "-y", "@nostrbook/mcp@latest"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Generated
+343
-21
@@ -20,6 +20,7 @@
|
|||||||
"@mozilla/readability": "^0.6.0",
|
"@mozilla/readability": "^0.6.0",
|
||||||
"@nostrify/nostrify": "^0.48.2",
|
"@nostrify/nostrify": "^0.48.2",
|
||||||
"@nostrify/react": "^0.2.20",
|
"@nostrify/react": "^0.2.20",
|
||||||
|
"@opensecret/react": "^1.5.4",
|
||||||
"@radix-ui/react-accordion": "^1.2.0",
|
"@radix-ui/react-accordion": "^1.2.0",
|
||||||
"@radix-ui/react-alert-dialog": "^1.1.1",
|
"@radix-ui/react-alert-dialog": "^1.1.1",
|
||||||
"@radix-ui/react-aspect-ratio": "^1.1.0",
|
"@radix-ui/react-aspect-ratio": "^1.1.0",
|
||||||
@@ -2812,9 +2813,9 @@
|
|||||||
"license": "BSD-2-Clause"
|
"license": "BSD-2-Clause"
|
||||||
},
|
},
|
||||||
"node_modules/@modelcontextprotocol/sdk": {
|
"node_modules/@modelcontextprotocol/sdk": {
|
||||||
"version": "1.25.1",
|
"version": "1.25.2",
|
||||||
"resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-1.25.1.tgz",
|
"resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-1.25.2.tgz",
|
||||||
"integrity": "sha512-yO28oVFFC7EBoiKdAn+VqRm+plcfv4v0xp6osG/VsCB0NlPZWi87ajbCZZ8f/RvOFLEu7//rSRmuZZ7lMoe3gQ==",
|
"integrity": "sha512-LZFeo4F9M5qOhC/Uc1aQSrBHxMrvxett+9KLHt7OhcExtoiRN9DKgbZffMP/nxjutWDQpfMDfP3nkHI4X9ijww==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@hono/node-server": "^1.19.7",
|
"@hono/node-server": "^1.19.7",
|
||||||
@@ -3020,6 +3021,173 @@
|
|||||||
"resolved": "https://registry.npmjs.org/@nostrify/types/-/types-0.36.8.tgz",
|
"resolved": "https://registry.npmjs.org/@nostrify/types/-/types-0.36.8.tgz",
|
||||||
"integrity": "sha512-tmpz5pkU8oXu7+V1qxvAzuoo8s5x4Gvo7h+JRm+JAW6x/2VZ8aQoA54yhn89qZ9agciMJhVdhqCm1PlK55w17A=="
|
"integrity": "sha512-tmpz5pkU8oXu7+V1qxvAzuoo8s5x4Gvo7h+JRm+JAW6x/2VZ8aQoA54yhn89qZ9agciMJhVdhqCm1PlK55w17A=="
|
||||||
},
|
},
|
||||||
|
"node_modules/@opensecret/react": {
|
||||||
|
"version": "1.5.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@opensecret/react/-/react-1.5.4.tgz",
|
||||||
|
"integrity": "sha512-nIrb1NfKIJ1G8IK+b8OnjXvPgc/C3GkLVbZVF9HCh6WBDV2yimg8B7Eo6Pqu5mUtiFrQslFL9UbeDj4Py0mbGA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@peculiar/x509": "^1.12.2",
|
||||||
|
"@stablelib/base64": "^2.0.0",
|
||||||
|
"@stablelib/chacha20poly1305": "^2.0.0",
|
||||||
|
"@stablelib/random": "^2.0.0",
|
||||||
|
"cbor2": "^1.7.0",
|
||||||
|
"tweetnacl": "^1.0.3",
|
||||||
|
"zod": "^3.23.8"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"react": "^18.0.0 || ^19.0.0",
|
||||||
|
"react-dom": "^18.0.0 || ^19.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@peculiar/asn1-cms": {
|
||||||
|
"version": "2.6.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@peculiar/asn1-cms/-/asn1-cms-2.6.0.tgz",
|
||||||
|
"integrity": "sha512-2uZqP+ggSncESeUF/9Su8rWqGclEfEiz1SyU02WX5fUONFfkjzS2Z/F1Li0ofSmf4JqYXIOdCAZqIXAIBAT1OA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@peculiar/asn1-schema": "^2.6.0",
|
||||||
|
"@peculiar/asn1-x509": "^2.6.0",
|
||||||
|
"@peculiar/asn1-x509-attr": "^2.6.0",
|
||||||
|
"asn1js": "^3.0.6",
|
||||||
|
"tslib": "^2.8.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@peculiar/asn1-csr": {
|
||||||
|
"version": "2.6.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@peculiar/asn1-csr/-/asn1-csr-2.6.0.tgz",
|
||||||
|
"integrity": "sha512-BeWIu5VpTIhfRysfEp73SGbwjjoLL/JWXhJ/9mo4vXnz3tRGm+NGm3KNcRzQ9VMVqwYS2RHlolz21svzRXIHPQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@peculiar/asn1-schema": "^2.6.0",
|
||||||
|
"@peculiar/asn1-x509": "^2.6.0",
|
||||||
|
"asn1js": "^3.0.6",
|
||||||
|
"tslib": "^2.8.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@peculiar/asn1-ecc": {
|
||||||
|
"version": "2.6.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@peculiar/asn1-ecc/-/asn1-ecc-2.6.0.tgz",
|
||||||
|
"integrity": "sha512-FF3LMGq6SfAOwUG2sKpPXblibn6XnEIKa+SryvUl5Pik+WR9rmRA3OCiwz8R3lVXnYnyRkSZsSLdml8H3UiOcw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@peculiar/asn1-schema": "^2.6.0",
|
||||||
|
"@peculiar/asn1-x509": "^2.6.0",
|
||||||
|
"asn1js": "^3.0.6",
|
||||||
|
"tslib": "^2.8.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@peculiar/asn1-pfx": {
|
||||||
|
"version": "2.6.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@peculiar/asn1-pfx/-/asn1-pfx-2.6.0.tgz",
|
||||||
|
"integrity": "sha512-rtUvtf+tyKGgokHHmZzeUojRZJYPxoD/jaN1+VAB4kKR7tXrnDCA/RAWXAIhMJJC+7W27IIRGe9djvxKgsldCQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@peculiar/asn1-cms": "^2.6.0",
|
||||||
|
"@peculiar/asn1-pkcs8": "^2.6.0",
|
||||||
|
"@peculiar/asn1-rsa": "^2.6.0",
|
||||||
|
"@peculiar/asn1-schema": "^2.6.0",
|
||||||
|
"asn1js": "^3.0.6",
|
||||||
|
"tslib": "^2.8.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@peculiar/asn1-pkcs8": {
|
||||||
|
"version": "2.6.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@peculiar/asn1-pkcs8/-/asn1-pkcs8-2.6.0.tgz",
|
||||||
|
"integrity": "sha512-KyQ4D8G/NrS7Fw3XCJrngxmjwO/3htnA0lL9gDICvEQ+GJ+EPFqldcJQTwPIdvx98Tua+WjkdKHSC0/Km7T+lA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@peculiar/asn1-schema": "^2.6.0",
|
||||||
|
"@peculiar/asn1-x509": "^2.6.0",
|
||||||
|
"asn1js": "^3.0.6",
|
||||||
|
"tslib": "^2.8.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@peculiar/asn1-pkcs9": {
|
||||||
|
"version": "2.6.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@peculiar/asn1-pkcs9/-/asn1-pkcs9-2.6.0.tgz",
|
||||||
|
"integrity": "sha512-b78OQ6OciW0aqZxdzliXGYHASeCvvw5caqidbpQRYW2mBtXIX2WhofNXTEe7NyxTb0P6J62kAAWLwn0HuMF1Fw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@peculiar/asn1-cms": "^2.6.0",
|
||||||
|
"@peculiar/asn1-pfx": "^2.6.0",
|
||||||
|
"@peculiar/asn1-pkcs8": "^2.6.0",
|
||||||
|
"@peculiar/asn1-schema": "^2.6.0",
|
||||||
|
"@peculiar/asn1-x509": "^2.6.0",
|
||||||
|
"@peculiar/asn1-x509-attr": "^2.6.0",
|
||||||
|
"asn1js": "^3.0.6",
|
||||||
|
"tslib": "^2.8.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@peculiar/asn1-rsa": {
|
||||||
|
"version": "2.6.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@peculiar/asn1-rsa/-/asn1-rsa-2.6.0.tgz",
|
||||||
|
"integrity": "sha512-Nu4C19tsrTsCp9fDrH+sdcOKoVfdfoQQ7S3VqjJU6vedR7tY3RLkQ5oguOIB3zFW33USDUuYZnPEQYySlgha4w==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@peculiar/asn1-schema": "^2.6.0",
|
||||||
|
"@peculiar/asn1-x509": "^2.6.0",
|
||||||
|
"asn1js": "^3.0.6",
|
||||||
|
"tslib": "^2.8.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@peculiar/asn1-schema": {
|
||||||
|
"version": "2.6.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@peculiar/asn1-schema/-/asn1-schema-2.6.0.tgz",
|
||||||
|
"integrity": "sha512-xNLYLBFTBKkCzEZIw842BxytQQATQv+lDTCEMZ8C196iJcJJMBUZxrhSTxLaohMyKK8QlzRNTRkUmanucnDSqg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"asn1js": "^3.0.6",
|
||||||
|
"pvtsutils": "^1.3.6",
|
||||||
|
"tslib": "^2.8.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@peculiar/asn1-x509": {
|
||||||
|
"version": "2.6.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@peculiar/asn1-x509/-/asn1-x509-2.6.0.tgz",
|
||||||
|
"integrity": "sha512-uzYbPEpoQiBoTq0/+jZtpM6Gq6zADBx+JNFP3yqRgziWBxQ/Dt/HcuvRfm9zJTPdRcBqPNdaRHTVwpyiq6iNMA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@peculiar/asn1-schema": "^2.6.0",
|
||||||
|
"asn1js": "^3.0.6",
|
||||||
|
"pvtsutils": "^1.3.6",
|
||||||
|
"tslib": "^2.8.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@peculiar/asn1-x509-attr": {
|
||||||
|
"version": "2.6.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@peculiar/asn1-x509-attr/-/asn1-x509-attr-2.6.0.tgz",
|
||||||
|
"integrity": "sha512-MuIAXFX3/dc8gmoZBkwJWxUWOSvG4MMDntXhrOZpJVMkYX+MYc/rUAU2uJOved9iJEoiUx7//3D8oG83a78UJA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@peculiar/asn1-schema": "^2.6.0",
|
||||||
|
"@peculiar/asn1-x509": "^2.6.0",
|
||||||
|
"asn1js": "^3.0.6",
|
||||||
|
"tslib": "^2.8.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@peculiar/x509": {
|
||||||
|
"version": "1.14.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/@peculiar/x509/-/x509-1.14.3.tgz",
|
||||||
|
"integrity": "sha512-C2Xj8FZ0uHWeCXXqX5B4/gVFQmtSkiuOolzAgutjTfseNOHT3pUjljDZsTSxXFGgio54bCzVFqmEOUrIVk8RDA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@peculiar/asn1-cms": "^2.6.0",
|
||||||
|
"@peculiar/asn1-csr": "^2.6.0",
|
||||||
|
"@peculiar/asn1-ecc": "^2.6.0",
|
||||||
|
"@peculiar/asn1-pkcs9": "^2.6.0",
|
||||||
|
"@peculiar/asn1-rsa": "^2.6.0",
|
||||||
|
"@peculiar/asn1-schema": "^2.6.0",
|
||||||
|
"@peculiar/asn1-x509": "^2.6.0",
|
||||||
|
"pvtsutils": "^1.3.6",
|
||||||
|
"reflect-metadata": "^0.2.2",
|
||||||
|
"tslib": "^2.8.1",
|
||||||
|
"tsyringe": "^4.10.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=20.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@pkgjs/parseargs": {
|
"node_modules/@pkgjs/parseargs": {
|
||||||
"version": "0.11.0",
|
"version": "0.11.0",
|
||||||
"resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz",
|
"resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz",
|
||||||
@@ -4385,9 +4553,9 @@
|
|||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@remix-run/router": {
|
"node_modules/@remix-run/router": {
|
||||||
"version": "1.23.0",
|
"version": "1.23.2",
|
||||||
"resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.23.0.tgz",
|
"resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.23.2.tgz",
|
||||||
"integrity": "sha512-O3rHJzAQKamUz1fvE0Qaw0xSFqsA/yafi2iqeE0pvdFtCO1viYx8QL6f3Ln/aCCTLxs68SLf0KPM9eSeM8yBnA==",
|
"integrity": "sha512-Ic6m2U/rMjTkhERIa/0ZtXJP17QUi2CbWE7cqx4J58M8aA3QTfW+2UlQ4psvTX9IO1RfNVhK3pcpdjej7L+t2w==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=14.0.0"
|
"node": ">=14.0.0"
|
||||||
@@ -5035,6 +5203,89 @@
|
|||||||
"node": ">=18.0.0"
|
"node": ">=18.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@stablelib/aead": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@stablelib/aead/-/aead-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-U/RMANRxbT/ahIpYsPSiFwDFNjADHdnCFfmo09MO1ai2XmerPAOPtMl0qmX7XVvygnACC6ijKDyHBoT2rGyElg==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/@stablelib/base64": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@stablelib/base64/-/base64-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-P2z89A7N1ETt6RxgpVdDT2xlg8cnm3n6td0lY9gyK7EiWK3wdq388yFX/hLknkCC0we05OZAD1rfxlQJUbl5VQ==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/@stablelib/binary": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@stablelib/binary/-/binary-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-U9iAO8lXgEDONsA0zPPSgcf3HUBNAqHiJmSHgZz62OvC3Hi2Bhc5kTnQ3S1/L+sthDTHtCMhcEiklmIly6uQ3w==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@stablelib/int": "^2.0.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@stablelib/chacha": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@stablelib/chacha/-/chacha-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-lS1FqtNqofxe2vLkRsLli2m3x/XanUyAYRphLhdHumKeIsLbjbCXdCq3Pf/eWiO7G3QlSG5ViqnoVjktzfLWMg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@stablelib/binary": "^2.0.1",
|
||||||
|
"@stablelib/wipe": "^2.0.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@stablelib/chacha20poly1305": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@stablelib/chacha20poly1305/-/chacha20poly1305-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-kOoBsXbDPVRlelzXl+5WViycgM19lD7lF3Bc3KWI+DzId0Stc2HlxAfSc+Xpn3RgqSCl1ZNTXr33LegqBhBBaw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@stablelib/aead": "^2.0.0",
|
||||||
|
"@stablelib/binary": "^2.0.1",
|
||||||
|
"@stablelib/chacha": "^2.0.1",
|
||||||
|
"@stablelib/constant-time": "^2.0.1",
|
||||||
|
"@stablelib/poly1305": "^2.0.1",
|
||||||
|
"@stablelib/wipe": "^2.0.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@stablelib/constant-time": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@stablelib/constant-time/-/constant-time-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-0NWPogffRm+UWBH0+iM5otZmNrVe5OHFIvyoNIVankMAYOQzMwcdVALOVPrB5Ho0dST+Oc3H8/hPh65Z8R/uew==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/@stablelib/int": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@stablelib/int/-/int-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-Ht63fQp3wz/F8U4AlXEPb7hfJOIILs8Lq55jgtD7KueWtyjhVuzcsGLSTAWtZs3XJDZYdF1WcSKn+kBtbzupww==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/@stablelib/poly1305": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@stablelib/poly1305/-/poly1305-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-D8xfZcL/5zeVARJ9I2fZOUCnZvsJx8G4JDQvD+ecsnaCildPtqZDwqqjtOc4cfHAdScrMjOzUVsssjXUTBw3YQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@stablelib/constant-time": "^2.0.1",
|
||||||
|
"@stablelib/wipe": "^2.0.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@stablelib/random": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@stablelib/random/-/random-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-W6GAtXEEs7r+dSbuBsvoFmlyL3gLxle41tQkjKu17dDWtDdjhVUbtRfRCQcCUeczwkgjQxMPopgwYEvxXtHXGw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@stablelib/binary": "^2.0.1",
|
||||||
|
"@stablelib/wipe": "^2.0.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@stablelib/wipe": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@stablelib/wipe/-/wipe-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-1eU2K9EgOcV4qc9jcP6G72xxZxEm5PfeI5H55l08W95b4oRJaqhmlWRc4xZAm6IVSKhVNxMi66V67hCzzuMTAg==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/@std/encoding": {
|
"node_modules/@std/encoding": {
|
||||||
"name": "@jsr/std__encoding",
|
"name": "@jsr/std__encoding",
|
||||||
"version": "1.0.10",
|
"version": "1.0.10",
|
||||||
@@ -6317,6 +6568,20 @@
|
|||||||
"integrity": "sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==",
|
"integrity": "sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/asn1js": {
|
||||||
|
"version": "3.0.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/asn1js/-/asn1js-3.0.7.tgz",
|
||||||
|
"integrity": "sha512-uLvq6KJu04qoQM6gvBfKFjlh6Gl0vOKQuR5cJMDHQkmwfMOQeN3F3SHCv9SNYSL+CRoHvOGFfllDlVz03GQjvQ==",
|
||||||
|
"license": "BSD-3-Clause",
|
||||||
|
"dependencies": {
|
||||||
|
"pvtsutils": "^1.3.6",
|
||||||
|
"pvutils": "^1.1.3",
|
||||||
|
"tslib": "^2.8.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/assertion-error": {
|
"node_modules/assertion-error": {
|
||||||
"version": "2.0.1",
|
"version": "2.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz",
|
||||||
@@ -6782,6 +7047,15 @@
|
|||||||
],
|
],
|
||||||
"license": "CC-BY-4.0"
|
"license": "CC-BY-4.0"
|
||||||
},
|
},
|
||||||
|
"node_modules/cbor2": {
|
||||||
|
"version": "1.12.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/cbor2/-/cbor2-1.12.0.tgz",
|
||||||
|
"integrity": "sha512-3Cco8XQhi27DogSp9Ri6LYNZLi/TBY/JVnDe+mj06NkBjW/ZYOtekaEU4wZ4xcRMNrFkDv8KNtOAqHyDfz3lYg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18.7"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/ccount": {
|
"node_modules/ccount": {
|
||||||
"version": "2.0.1",
|
"version": "2.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/ccount/-/ccount-2.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/ccount/-/ccount-2.0.1.tgz",
|
||||||
@@ -9200,9 +9474,9 @@
|
|||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/hono": {
|
"node_modules/hono": {
|
||||||
"version": "4.11.1",
|
"version": "4.11.4",
|
||||||
"resolved": "https://registry.npmjs.org/hono/-/hono-4.11.1.tgz",
|
"resolved": "https://registry.npmjs.org/hono/-/hono-4.11.4.tgz",
|
||||||
"integrity": "sha512-KsFcH0xxHes0J4zaQgWbYwmz3UPOOskdqZmItstUG93+Wk1ePBLkLGwbP9zlmh1BFUiL8Qp+Xfu9P7feJWpGNg==",
|
"integrity": "sha512-U7tt8JsyrxSRKspfhtLET79pU8K+tInj5QZXs1jSugO1Vq5dFj3kmZsRldo29mTBfcjDRVRXrEZ6LS63Cog9ZA==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
@@ -12530,6 +12804,24 @@
|
|||||||
"node": ">=6"
|
"node": ">=6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/pvtsutils": {
|
||||||
|
"version": "1.3.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/pvtsutils/-/pvtsutils-1.3.6.tgz",
|
||||||
|
"integrity": "sha512-PLgQXQ6H2FWCaeRak8vvk1GW462lMxB5s3Jm673N82zI4vqtVUPuZdffdZbPDFRoU8kAhItWFtPCWiPpp4/EDg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"tslib": "^2.8.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/pvutils": {
|
||||||
|
"version": "1.1.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/pvutils/-/pvutils-1.1.5.tgz",
|
||||||
|
"integrity": "sha512-KTqnxsgGiQ6ZAzZCVlJH5eOjSnvlyEgx1m8bkRJfOhmGRqfo5KLvmAlACQkrjEtOQ4B7wF9TdSLIs9O90MX9xA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=16.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/qrcode": {
|
"node_modules/qrcode": {
|
||||||
"version": "1.5.4",
|
"version": "1.5.4",
|
||||||
"resolved": "https://registry.npmjs.org/qrcode/-/qrcode-1.5.4.tgz",
|
"resolved": "https://registry.npmjs.org/qrcode/-/qrcode-1.5.4.tgz",
|
||||||
@@ -12548,9 +12840,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/qs": {
|
"node_modules/qs": {
|
||||||
"version": "6.14.0",
|
"version": "6.14.1",
|
||||||
"resolved": "https://registry.npmjs.org/qs/-/qs-6.14.0.tgz",
|
"resolved": "https://registry.npmjs.org/qs/-/qs-6.14.1.tgz",
|
||||||
"integrity": "sha512-YWWTjgABSKcvs/nWBi9PycY/JiPJqOD4JA6o9Sej2AtvSGarXxKC3OQSk4pAarbdQlKAh5D4FCQkJNkW+GAn3w==",
|
"integrity": "sha512-4EK3+xJl8Ts67nLYNwqw/dsFVnCf+qR7RgXSK9jEEm9unao3njwMDdmsdvoKBKHzxd7tCYz5e5M+SnMjdtXGQQ==",
|
||||||
"license": "BSD-3-Clause",
|
"license": "BSD-3-Clause",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"side-channel": "^1.1.0"
|
"side-channel": "^1.1.0"
|
||||||
@@ -12816,12 +13108,12 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/react-router": {
|
"node_modules/react-router": {
|
||||||
"version": "6.30.0",
|
"version": "6.30.3",
|
||||||
"resolved": "https://registry.npmjs.org/react-router/-/react-router-6.30.0.tgz",
|
"resolved": "https://registry.npmjs.org/react-router/-/react-router-6.30.3.tgz",
|
||||||
"integrity": "sha512-D3X8FyH9nBcTSHGdEKurK7r8OYE1kKFn3d/CF+CoxbSHkxU7o37+Uh7eAHRXr6k2tSExXYO++07PeXJtA/dEhQ==",
|
"integrity": "sha512-XRnlbKMTmktBkjCLE8/XcZFlnHvr2Ltdr1eJX4idL55/9BbORzyZEaIkBFDhFGCEWBBItsVrDxwx3gnisMitdw==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@remix-run/router": "1.23.0"
|
"@remix-run/router": "1.23.2"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=14.0.0"
|
"node": ">=14.0.0"
|
||||||
@@ -12831,13 +13123,13 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/react-router-dom": {
|
"node_modules/react-router-dom": {
|
||||||
"version": "6.30.0",
|
"version": "6.30.3",
|
||||||
"resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.30.0.tgz",
|
"resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.30.3.tgz",
|
||||||
"integrity": "sha512-x30B78HV5tFk8ex0ITwzC9TTZMua4jGyA9IUlH1JLQYQTFyxr/ZxwOJq7evg1JX1qGVUcvhsmQSKdPncQrjTgA==",
|
"integrity": "sha512-pxPcv1AczD4vso7G4Z3TKcvlxK7g7TNt3/FNGMhfqyntocvYKj+GCatfigGDjbLozC4baguJ0ReCigoDJXb0ag==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@remix-run/router": "1.23.0",
|
"@remix-run/router": "1.23.2",
|
||||||
"react-router": "6.30.0"
|
"react-router": "6.30.3"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=14.0.0"
|
"node": ">=14.0.0"
|
||||||
@@ -12981,6 +13273,12 @@
|
|||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/reflect-metadata": {
|
||||||
|
"version": "0.2.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.2.2.tgz",
|
||||||
|
"integrity": "sha512-urBwgfrvVP/eAyXx4hluJivBKzuEbSQs9rKWCrCkbSxNv8mxPcUZKeuoF3Uy4mJl3Lwprp6yy5/39VWigZ4K6Q==",
|
||||||
|
"license": "Apache-2.0"
|
||||||
|
},
|
||||||
"node_modules/reflect.getprototypeof": {
|
"node_modules/reflect.getprototypeof": {
|
||||||
"version": "1.0.10",
|
"version": "1.0.10",
|
||||||
"resolved": "https://registry.npmjs.org/reflect.getprototypeof/-/reflect.getprototypeof-1.0.10.tgz",
|
"resolved": "https://registry.npmjs.org/reflect.getprototypeof/-/reflect.getprototypeof-1.0.10.tgz",
|
||||||
@@ -14698,6 +14996,24 @@
|
|||||||
"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
|
"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
|
||||||
"license": "0BSD"
|
"license": "0BSD"
|
||||||
},
|
},
|
||||||
|
"node_modules/tsyringe": {
|
||||||
|
"version": "4.10.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/tsyringe/-/tsyringe-4.10.0.tgz",
|
||||||
|
"integrity": "sha512-axr3IdNuVIxnaK5XGEUFTu3YmAQ6lllgrvqfEoR16g/HGnYY/6We4oWENtAnzK6/LpJ2ur9PAb80RBt7/U4ugw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"tslib": "^1.9.3"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 6.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/tsyringe/node_modules/tslib": {
|
||||||
|
"version": "1.14.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",
|
||||||
|
"integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==",
|
||||||
|
"license": "0BSD"
|
||||||
|
},
|
||||||
"node_modules/turndown": {
|
"node_modules/turndown": {
|
||||||
"version": "7.2.1",
|
"version": "7.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/turndown/-/turndown-7.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/turndown/-/turndown-7.2.1.tgz",
|
||||||
@@ -14707,6 +15023,12 @@
|
|||||||
"@mixmark-io/domino": "^2.2.0"
|
"@mixmark-io/domino": "^2.2.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/tweetnacl": {
|
||||||
|
"version": "1.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz",
|
||||||
|
"integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==",
|
||||||
|
"license": "Unlicense"
|
||||||
|
},
|
||||||
"node_modules/type-check": {
|
"node_modules/type-check": {
|
||||||
"version": "0.4.0",
|
"version": "0.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz",
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
"@mozilla/readability": "^0.6.0",
|
"@mozilla/readability": "^0.6.0",
|
||||||
"@nostrify/nostrify": "^0.48.2",
|
"@nostrify/nostrify": "^0.48.2",
|
||||||
"@nostrify/react": "^0.2.20",
|
"@nostrify/react": "^0.2.20",
|
||||||
|
"@opensecret/react": "^1.5.4",
|
||||||
"@radix-ui/react-accordion": "^1.2.0",
|
"@radix-ui/react-accordion": "^1.2.0",
|
||||||
"@radix-ui/react-alert-dialog": "^1.1.1",
|
"@radix-ui/react-alert-dialog": "^1.1.1",
|
||||||
"@radix-ui/react-aspect-ratio": "^1.1.0",
|
"@radix-ui/react-aspect-ratio": "^1.1.0",
|
||||||
|
|||||||
+7
-6
@@ -24,8 +24,13 @@ export default {
|
|||||||
return new Response('Invalid url parameter', { status: 400 });
|
return new Response('Invalid url parameter', { status: 400 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let hostname = url.hostname;
|
||||||
|
|
||||||
|
// Strip `ai.` and `api.` subdomains for a better chance at finding a favicon
|
||||||
|
hostname = hostname.replace(/^(ai\.|api\.)/, '');
|
||||||
|
|
||||||
// GitHub hack: neutral color for light/dark mode
|
// GitHub hack: neutral color for light/dark mode
|
||||||
if (url.hostname === 'github.com') {
|
if (hostname === 'github.com') {
|
||||||
const svg = await (await fetch('https://github.githubassets.com/favicons/favicon.svg')).text();
|
const svg = await (await fetch('https://github.githubassets.com/favicons/favicon.svg')).text();
|
||||||
return new Response(svg.replaceAll('#24292E', '#808080'), {
|
return new Response(svg.replaceAll('#24292E', '#808080'), {
|
||||||
headers: { 'Content-Type': 'image/svg+xml' },
|
headers: { 'Content-Type': 'image/svg+xml' },
|
||||||
@@ -33,20 +38,16 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AI-provider-specific hacks
|
// AI-provider-specific hacks
|
||||||
let hostname = url.hostname;
|
|
||||||
if (url.host === 'localhost:11434' || url.origin === '127.0.0.1:11434') {
|
if (url.host === 'localhost:11434' || url.origin === '127.0.0.1:11434') {
|
||||||
hostname = 'ollama.com';
|
hostname = 'ollama.com';
|
||||||
} else if (url.host === 'localhost:45554' || url.origin === '127.0.0.1:45554') {
|
} else if (url.host === 'localhost:45554' || url.origin === '127.0.0.1:45554') {
|
||||||
hostname = 'claude.ai';
|
hostname = 'claude.ai';
|
||||||
} else if (url.host === 'generativelanguage.googleapis.com') {
|
} else if (url.host === 'generativelanguage.googleapis.com') {
|
||||||
hostname = 'gemini.google.com';
|
hostname = 'gemini.google.com';
|
||||||
} else if (url.host === 'api.z.ai') {
|
} else if (url.host === 'z.ai') {
|
||||||
hostname = 'docs.z.ai';
|
hostname = 'docs.z.ai';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Strip `ai.` and `api.` subdomains for a better chance at finding a favicon
|
|
||||||
hostname = hostname.replace(/^(ai\.|api\.)/, '');
|
|
||||||
|
|
||||||
// Fetch the favicon from DuckDuckGo's service
|
// Fetch the favicon from DuckDuckGo's service
|
||||||
return fetch(`https://external-content.duckduckgo.com/ip3/${hostname}.ico`);
|
return fetch(`https://external-content.duckduckgo.com/ip3/${hostname}.ico`);
|
||||||
},
|
},
|
||||||
|
|||||||
+9
-8
@@ -12,16 +12,17 @@ export default {
|
|||||||
return new Response(null, {
|
return new Response(null, {
|
||||||
status: 200,
|
status: 200,
|
||||||
headers: {
|
headers: {
|
||||||
"Access-Control-Allow-Origin": "*",
|
"access-control-allow-origin": "*",
|
||||||
"Access-Control-Allow-Methods": "GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS",
|
"access-control-allow-methods": "GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS",
|
||||||
"Access-Control-Allow-Headers": "*", // Or specify specific headers
|
"access-control-allow-headers": "*", // Or specify specific headers
|
||||||
"Access-Control-Max-Age": "86400", // Cache preflight for 24 hours
|
"access-control-max-age": "86400", // Cache preflight for 24 hours
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const headers = new Headers(request.headers);
|
const headers = new Headers(request.headers);
|
||||||
headers.set('User-Agent', 'Shakespeare Proxy <https://proxy.shakespeare.diy/>');
|
headers.set('user-agent', 'Shakespeare Proxy <https://proxy.shakespeare.diy/>');
|
||||||
|
headers.delete('origin');
|
||||||
|
|
||||||
const targetResponse = await fetch(target, {
|
const targetResponse = await fetch(target, {
|
||||||
method: request.method,
|
method: request.method,
|
||||||
@@ -31,9 +32,9 @@ export default {
|
|||||||
|
|
||||||
const response = new Response(targetResponse.body, targetResponse);
|
const response = new Response(targetResponse.body, targetResponse);
|
||||||
|
|
||||||
response.headers.set("Access-Control-Allow-Origin", "*");
|
response.headers.set("access-control-allow-origin", "*");
|
||||||
response.headers.set("Access-Control-Allow-Methods", "GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS");
|
response.headers.set("access-control-allow-methods", "GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS");
|
||||||
response.headers.set("Access-Control-Allow-Headers", "*");
|
response.headers.set("access-control-allow-headers", "*");
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import AboutSettings from "./pages/AboutSettings";
|
|||||||
import GitHubOAuth from "./pages/GitHubOAuth";
|
import GitHubOAuth from "./pages/GitHubOAuth";
|
||||||
import NetlifyOAuth from "./pages/NetlifyOAuth";
|
import NetlifyOAuth from "./pages/NetlifyOAuth";
|
||||||
import VercelOAuth from "./pages/VercelOAuth";
|
import VercelOAuth from "./pages/VercelOAuth";
|
||||||
|
import OpenRouterOAuth from "./pages/OpenRouterOAuth";
|
||||||
import { NIP19Page } from "./pages/NIP19Page";
|
import { NIP19Page } from "./pages/NIP19Page";
|
||||||
import NotFound from "./pages/NotFound";
|
import NotFound from "./pages/NotFound";
|
||||||
import { ProjectView } from "./pages/ProjectView";
|
import { ProjectView } from "./pages/ProjectView";
|
||||||
@@ -39,6 +40,7 @@ export function AppRouter() {
|
|||||||
<Route path="/oauth/github" element={<GitHubOAuth />} />
|
<Route path="/oauth/github" element={<GitHubOAuth />} />
|
||||||
<Route path="/oauth/netlify" element={<NetlifyOAuth />} />
|
<Route path="/oauth/netlify" element={<NetlifyOAuth />} />
|
||||||
<Route path="/oauth/vercel" element={<VercelOAuth />} />
|
<Route path="/oauth/vercel" element={<VercelOAuth />} />
|
||||||
|
<Route path="/oauth/openrouter" element={<OpenRouterOAuth />} />
|
||||||
<Route path="/settings" element={<SettingsLayout />}>
|
<Route path="/settings" element={<SettingsLayout />}>
|
||||||
<Route index element={<Settings />} />
|
<Route index element={<Settings />} />
|
||||||
<Route path="preferences" element={<Preferences />} />
|
<Route path="preferences" element={<Preferences />} />
|
||||||
|
|||||||
@@ -1041,12 +1041,31 @@ export function AIProviderConfigDialog({
|
|||||||
<div className="grid gap-2">
|
<div className="grid gap-2">
|
||||||
<Label htmlFor="provider-auth">{t('authentication')}</Label>
|
<Label htmlFor="provider-auth">{t('authentication')}</Label>
|
||||||
<Select
|
<Select
|
||||||
value={localProvider.nostr ? 'nostr' : 'api-key'}
|
value={localProvider.nostr ? 'nostr' : localProvider.openSecret ? 'opensecret' : 'api-key'}
|
||||||
onValueChange={(value: 'api-key' | 'nostr') => setLocalProvider({
|
onValueChange={(value: 'api-key' | 'nostr' | 'opensecret') => {
|
||||||
...localProvider,
|
if (value === 'nostr') {
|
||||||
nostr: value === 'nostr' || undefined,
|
setLocalProvider({
|
||||||
apiKey: value === 'nostr' ? undefined : localProvider.apiKey
|
...localProvider,
|
||||||
})}
|
nostr: true,
|
||||||
|
openSecret: undefined,
|
||||||
|
apiKey: undefined
|
||||||
|
});
|
||||||
|
} else if (value === 'opensecret') {
|
||||||
|
setLocalProvider({
|
||||||
|
...localProvider,
|
||||||
|
nostr: undefined,
|
||||||
|
openSecret: localProvider.openSecret,
|
||||||
|
apiKey: localProvider.apiKey
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
setLocalProvider({
|
||||||
|
...localProvider,
|
||||||
|
nostr: undefined,
|
||||||
|
openSecret: undefined,
|
||||||
|
apiKey: localProvider.apiKey
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
<SelectValue />
|
<SelectValue />
|
||||||
@@ -1054,10 +1073,25 @@ export function AIProviderConfigDialog({
|
|||||||
<SelectContent>
|
<SelectContent>
|
||||||
<SelectItem value="api-key">{t('apiKey')}</SelectItem>
|
<SelectItem value="api-key">{t('apiKey')}</SelectItem>
|
||||||
<SelectItem value="nostr">Nostr</SelectItem>
|
<SelectItem value="nostr">Nostr</SelectItem>
|
||||||
|
<SelectItem value="opensecret">OpenSecret</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{localProvider.openSecret && (
|
||||||
|
<div className="grid gap-2">
|
||||||
|
<Label htmlFor="provider-opensecret-url">
|
||||||
|
OpenSecret API URL <span className="text-destructive">*</span>
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="provider-opensecret-url"
|
||||||
|
placeholder="https://enclave.trymaple.ai"
|
||||||
|
value={localProvider.openSecret || ''}
|
||||||
|
onChange={(e) => setLocalProvider({ ...localProvider, openSecret: e.target.value })}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{!localProvider.nostr && (
|
{!localProvider.nostr && (
|
||||||
<div className="grid gap-2">
|
<div className="grid gap-2">
|
||||||
<Label htmlFor="provider-apiKey">{t('apiKey')}</Label>
|
<Label htmlFor="provider-apiKey">{t('apiKey')}</Label>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { Bot } from 'lucide-react';
|
import { Bot, ChevronDown } from 'lucide-react';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Checkbox } from '@/components/ui/checkbox';
|
import { Checkbox } from '@/components/ui/checkbox';
|
||||||
import { ExternalInput } from '@/components/ui/external-input';
|
import { ExternalInput } from '@/components/ui/external-input';
|
||||||
@@ -12,15 +12,31 @@ import {
|
|||||||
DialogTitle,
|
DialogTitle,
|
||||||
DialogFooter,
|
DialogFooter,
|
||||||
} from '@/components/ui/dialog';
|
} from '@/components/ui/dialog';
|
||||||
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuItem,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
} from '@/components/ui/dropdown-menu';
|
||||||
import { ExternalFavicon } from '@/components/ExternalFavicon';
|
import { ExternalFavicon } from '@/components/ExternalFavicon';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import type { PresetProvider } from '@/lib/aiProviderPresets';
|
import type { PresetProvider } from '@/lib/aiProviderPresets';
|
||||||
|
|
||||||
|
interface OAuthHook {
|
||||||
|
isOAuthConfigured: boolean;
|
||||||
|
isLoading: boolean;
|
||||||
|
error: string | null;
|
||||||
|
initiateOAuth: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
interface AddAIProviderDialogProps {
|
interface AddAIProviderDialogProps {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
onOpenChange: (open: boolean) => void;
|
onOpenChange: (open: boolean) => void;
|
||||||
preset: PresetProvider;
|
preset: PresetProvider;
|
||||||
isLoggedIntoNostr: boolean;
|
isLoggedIntoNostr: boolean;
|
||||||
|
oauthHook?: OAuthHook | null;
|
||||||
|
forceManualEntry?: boolean;
|
||||||
|
onSetForceManualEntry?: (force: boolean) => void;
|
||||||
onAdd: (apiKey: string) => void;
|
onAdd: (apiKey: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,6 +45,9 @@ export function AddAIProviderDialog({
|
|||||||
onOpenChange,
|
onOpenChange,
|
||||||
preset,
|
preset,
|
||||||
isLoggedIntoNostr,
|
isLoggedIntoNostr,
|
||||||
|
oauthHook,
|
||||||
|
forceManualEntry = false,
|
||||||
|
onSetForceManualEntry,
|
||||||
onAdd,
|
onAdd,
|
||||||
}: AddAIProviderDialogProps) {
|
}: AddAIProviderDialogProps) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -36,16 +55,27 @@ export function AddAIProviderDialog({
|
|||||||
const [termsAgreed, setTermsAgreed] = useState(false);
|
const [termsAgreed, setTermsAgreed] = useState(false);
|
||||||
|
|
||||||
const showNostrLoginRequired = preset.nostr && !isLoggedIntoNostr;
|
const showNostrLoginRequired = preset.nostr && !isLoggedIntoNostr;
|
||||||
|
const isOAuthConfigured = oauthHook?.isOAuthConfigured ?? false;
|
||||||
|
const isOAuthLoading = oauthHook?.isLoading ?? false;
|
||||||
|
const oauthError = oauthHook?.error ?? null;
|
||||||
|
|
||||||
const handleAdd = () => {
|
const handleAdd = () => {
|
||||||
onAdd(apiKey);
|
onAdd(apiKey);
|
||||||
setApiKey('');
|
setApiKey('');
|
||||||
setTermsAgreed(false);
|
|
||||||
onOpenChange(false);
|
onOpenChange(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Reset state when dialog closes
|
||||||
|
const handleOpenChange = (open: boolean) => {
|
||||||
|
if (!open) {
|
||||||
|
setApiKey('');
|
||||||
|
setTermsAgreed(false);
|
||||||
|
}
|
||||||
|
onOpenChange(open);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
<Dialog open={open} onOpenChange={handleOpenChange}>
|
||||||
<DialogContent className="max-w-md">
|
<DialogContent className="max-w-md">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
@@ -73,6 +103,50 @@ export function AddAIProviderDialog({
|
|||||||
</Link>
|
</Link>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
) : isOAuthConfigured && !forceManualEntry ? (
|
||||||
|
// Show OAuth button if OAuth is configured and not forced to manual
|
||||||
|
<div className="space-y-3">
|
||||||
|
<div className="flex gap-0">
|
||||||
|
<Button
|
||||||
|
onClick={() => oauthHook?.initiateOAuth()}
|
||||||
|
disabled={isOAuthLoading}
|
||||||
|
className="flex-1 rounded-r-none gap-2"
|
||||||
|
variant="default"
|
||||||
|
>
|
||||||
|
{isOAuthLoading ? (
|
||||||
|
<>
|
||||||
|
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-white"></div>
|
||||||
|
Connecting...
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<span className="truncate text-ellipsis overflow-hidden">
|
||||||
|
Connect to {preset.name}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant="default"
|
||||||
|
className="rounded-l-none border-l border-primary-foreground/20 px-2"
|
||||||
|
disabled={isOAuthLoading}
|
||||||
|
>
|
||||||
|
<ChevronDown className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end">
|
||||||
|
<DropdownMenuItem onClick={() => onSetForceManualEntry?.(true)}>
|
||||||
|
Enter API key
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
</div>
|
||||||
|
{oauthError && (
|
||||||
|
<p className="text-sm text-destructive">
|
||||||
|
{oauthError}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
{!preset.nostr && preset.apiKeysURL && (
|
{!preset.nostr && preset.apiKeysURL && (
|
||||||
@@ -123,7 +197,7 @@ export function AddAIProviderDialog({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{!showNostrLoginRequired && (
|
{!showNostrLoginRequired && !(isOAuthConfigured && !forceManualEntry) && (
|
||||||
<DialogFooter>
|
<DialogFooter>
|
||||||
<Button variant="outline" onClick={() => onOpenChange(false)}>
|
<Button variant="outline" onClick={() => onOpenChange(false)}>
|
||||||
{t('cancel')}
|
{t('cancel')}
|
||||||
|
|||||||
@@ -50,7 +50,8 @@ export function AddCustomAIProviderDialog({
|
|||||||
const [customIdManuallyEdited, setCustomIdManuallyEdited] = useState(false);
|
const [customIdManuallyEdited, setCustomIdManuallyEdited] = useState(false);
|
||||||
const [customBaseURL, setCustomBaseURL] = useState('');
|
const [customBaseURL, setCustomBaseURL] = useState('');
|
||||||
const [customApiKey, setCustomApiKey] = useState('');
|
const [customApiKey, setCustomApiKey] = useState('');
|
||||||
const [customAuthMethod, setCustomAuthMethod] = useState<'api-key' | 'nostr'>('api-key');
|
const [customAuthMethod, setCustomAuthMethod] = useState<'api-key' | 'nostr' | 'opensecret'>('api-key');
|
||||||
|
const [customOpenSecretUrl, setCustomOpenSecretUrl] = useState('');
|
||||||
const [customProxy, setCustomProxy] = useState(false);
|
const [customProxy, setCustomProxy] = useState(false);
|
||||||
|
|
||||||
const handleAdd = () => {
|
const handleAdd = () => {
|
||||||
@@ -66,6 +67,11 @@ export function AddCustomAIProviderDialog({
|
|||||||
provider.apiKey = customApiKey.trim();
|
provider.apiKey = customApiKey.trim();
|
||||||
} else if (customAuthMethod === 'nostr') {
|
} else if (customAuthMethod === 'nostr') {
|
||||||
provider.nostr = true;
|
provider.nostr = true;
|
||||||
|
} else if (customAuthMethod === 'opensecret') {
|
||||||
|
provider.openSecret = customOpenSecretUrl.trim();
|
||||||
|
if (customApiKey.trim()) {
|
||||||
|
provider.apiKey = customApiKey.trim();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (customProxy) {
|
if (customProxy) {
|
||||||
@@ -81,6 +87,7 @@ export function AddCustomAIProviderDialog({
|
|||||||
setCustomBaseURL('');
|
setCustomBaseURL('');
|
||||||
setCustomApiKey('');
|
setCustomApiKey('');
|
||||||
setCustomAuthMethod('api-key');
|
setCustomAuthMethod('api-key');
|
||||||
|
setCustomOpenSecretUrl('');
|
||||||
setCustomProxy(false);
|
setCustomProxy(false);
|
||||||
|
|
||||||
onOpenChange(false);
|
onOpenChange(false);
|
||||||
@@ -89,6 +96,7 @@ export function AddCustomAIProviderDialog({
|
|||||||
const isValid = customProviderName.trim() &&
|
const isValid = customProviderName.trim() &&
|
||||||
customProviderId.trim() &&
|
customProviderId.trim() &&
|
||||||
customBaseURL.trim() &&
|
customBaseURL.trim() &&
|
||||||
|
(customAuthMethod !== 'opensecret' || customOpenSecretUrl.trim()) &&
|
||||||
!existingIds.includes(customProviderId.trim());
|
!existingIds.includes(customProviderId.trim());
|
||||||
|
|
||||||
const idExists = existingIds.includes(customProviderId.trim());
|
const idExists = existingIds.includes(customProviderId.trim());
|
||||||
@@ -156,7 +164,7 @@ export function AddCustomAIProviderDialog({
|
|||||||
<Label htmlFor="custom-auth">{t('authentication')}</Label>
|
<Label htmlFor="custom-auth">{t('authentication')}</Label>
|
||||||
<Select
|
<Select
|
||||||
value={customAuthMethod}
|
value={customAuthMethod}
|
||||||
onValueChange={(value: 'api-key' | 'nostr') => {
|
onValueChange={(value: 'api-key' | 'nostr' | 'opensecret') => {
|
||||||
setCustomAuthMethod(value);
|
setCustomAuthMethod(value);
|
||||||
if (value === 'nostr') {
|
if (value === 'nostr') {
|
||||||
setCustomApiKey(''); // Clear API key when switching to Nostr auth
|
setCustomApiKey(''); // Clear API key when switching to Nostr auth
|
||||||
@@ -169,11 +177,26 @@ export function AddCustomAIProviderDialog({
|
|||||||
<SelectContent>
|
<SelectContent>
|
||||||
<SelectItem value="api-key">{t('apiKey')}</SelectItem>
|
<SelectItem value="api-key">{t('apiKey')}</SelectItem>
|
||||||
<SelectItem value="nostr">Nostr</SelectItem>
|
<SelectItem value="nostr">Nostr</SelectItem>
|
||||||
|
<SelectItem value="opensecret">OpenSecret</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{customAuthMethod === 'api-key' && (
|
{customAuthMethod === 'opensecret' && (
|
||||||
|
<div className="grid gap-2">
|
||||||
|
<Label htmlFor="custom-opensecret-url">
|
||||||
|
OpenSecret API URL <span className="text-destructive">*</span>
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="custom-opensecret-url"
|
||||||
|
placeholder="https://enclave.trymaple.ai"
|
||||||
|
value={customOpenSecretUrl}
|
||||||
|
onChange={(e) => setCustomOpenSecretUrl(e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{(customAuthMethod === 'api-key' || customAuthMethod === 'opensecret') && (
|
||||||
<div className="grid gap-2">
|
<div className="grid gap-2">
|
||||||
<Label htmlFor="custom-apikey">{t('apiKey')}</Label>
|
<Label htmlFor="custom-apikey">{t('apiKey')}</Label>
|
||||||
<PasswordInput
|
<PasswordInput
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ interface OAuthHook {
|
|||||||
initiateOAuth: () => void;
|
initiateOAuth: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AddProviderDialogProps {
|
interface AddDeployProviderDialogProps {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
onOpenChange: (open: boolean) => void;
|
onOpenChange: (open: boolean) => void;
|
||||||
preset: PresetDeployProvider;
|
preset: PresetDeployProvider;
|
||||||
@@ -39,7 +39,7 @@ interface AddProviderDialogProps {
|
|||||||
onAdd: (apiKey: string, accountId?: string, organizationId?: string) => void;
|
onAdd: (apiKey: string, accountId?: string, organizationId?: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function AddProviderDialog({
|
export function AddDeployProviderDialog({
|
||||||
open,
|
open,
|
||||||
onOpenChange,
|
onOpenChange,
|
||||||
preset,
|
preset,
|
||||||
@@ -48,7 +48,7 @@ export function AddProviderDialog({
|
|||||||
forceManualEntry,
|
forceManualEntry,
|
||||||
onSetForceManualEntry,
|
onSetForceManualEntry,
|
||||||
onAdd,
|
onAdd,
|
||||||
}: AddProviderDialogProps) {
|
}: AddDeployProviderDialogProps) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [apiKey, setApiKey] = useState('');
|
const [apiKey, setApiKey] = useState('');
|
||||||
const [accountId, setAccountId] = useState('');
|
const [accountId, setAccountId] = useState('');
|
||||||
@@ -112,16 +112,9 @@ export function AddProviderDialog({
|
|||||||
Connecting...
|
Connecting...
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<span className="truncate text-ellipsis overflow-hidden">
|
||||||
<ExternalFavicon
|
Connect to {preset.name}
|
||||||
url={preset.baseURL}
|
</span>
|
||||||
size={16}
|
|
||||||
fallback={<Rocket size={16} />}
|
|
||||||
/>
|
|
||||||
<span className="truncate text-ellipsis overflow-hidden">
|
|
||||||
Connect to {preset.name}
|
|
||||||
</span>
|
|
||||||
</>
|
|
||||||
)}
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
@@ -84,8 +84,8 @@ export function AddGitCredentialDialog({
|
|||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
||||||
<div className="space-y-4 py-4">
|
<div className="space-y-4 py-4">
|
||||||
{preset.id === 'github' && isOAuthConfigured && !forceManualEntry ? (
|
{isOAuthConfigured && !forceManualEntry ? (
|
||||||
// Special rendering for GitHub OAuth
|
// Show OAuth button if OAuth is configured and not forced to manual
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
<div className="flex gap-0">
|
<div className="flex gap-0">
|
||||||
<Button
|
<Button
|
||||||
@@ -100,16 +100,9 @@ export function AddGitCredentialDialog({
|
|||||||
Connecting...
|
Connecting...
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<span className="truncate text-ellipsis overflow-hidden">
|
||||||
<ExternalFavicon
|
Connect to {preset.name}
|
||||||
url="https://github.com"
|
</span>
|
||||||
size={16}
|
|
||||||
fallback={<GitBranch size={16} />}
|
|
||||||
/>
|
|
||||||
<span className="truncate text-ellipsis overflow-hidden">
|
|
||||||
Connect to GitHub
|
|
||||||
</span>
|
|
||||||
</>
|
|
||||||
)}
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
@@ -124,7 +117,7 @@ export function AddGitCredentialDialog({
|
|||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent align="end">
|
<DropdownMenuContent align="end">
|
||||||
<DropdownMenuItem onClick={() => onSetForceManualEntry(true)}>
|
<DropdownMenuItem onClick={() => onSetForceManualEntry(true)}>
|
||||||
Enter API key
|
Enter token manually
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
</DropdownMenuContent>
|
</DropdownMenuContent>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
@@ -136,7 +129,7 @@ export function AddGitCredentialDialog({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
// Standard token input
|
// Show manual token input
|
||||||
<ExternalInput
|
<ExternalInput
|
||||||
type="password"
|
type="password"
|
||||||
placeholder={t('enterToken')}
|
placeholder={t('enterToken')}
|
||||||
@@ -153,7 +146,7 @@ export function AddGitCredentialDialog({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{!(preset.id === 'github' && isOAuthConfigured && !forceManualEntry) && (
|
{!(isOAuthConfigured && !forceManualEntry) && (
|
||||||
<DialogFooter>
|
<DialogFooter>
|
||||||
<Button variant="outline" onClick={() => onOpenChange(false)}>
|
<Button variant="outline" onClick={() => onOpenChange(false)}>
|
||||||
{t('cancel')}
|
{t('cancel')}
|
||||||
|
|||||||
@@ -33,10 +33,10 @@ export function ExternalFavicon({
|
|||||||
const parsedUrl = new URL(url);
|
const parsedUrl = new URL(url);
|
||||||
|
|
||||||
// Strip `ai.` and `api.` subdomains for a better chance at finding a favicon
|
// Strip `ai.` and `api.` subdomains for a better chance at finding a favicon
|
||||||
parsedUrl.hostname = parsedUrl.hostname.replace(/^(ai\.|api\.)/, '');
|
parsedUrl.hostname = parsedUrl.hostname.replace(/^(ai\.|api\.|enclave\.)/, '');
|
||||||
|
|
||||||
// Normalize the URL to ensure it has a protocol
|
// Normalize the URL to ensure it has a protocol
|
||||||
return faviconUrl(config.faviconUrl, parsedUrl);
|
return faviconUrl({ template: config.faviconUrl, url: parsedUrl });
|
||||||
} catch {
|
} catch {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useState, useEffect, useRef } from 'react';
|
import { useState, useEffect, useRef } from 'react';
|
||||||
import { generateSecretKey } from 'nostr-tools';
|
import { generateSecretKey } from 'nostr-tools';
|
||||||
import { nip19 } from 'nostr-tools';
|
import { nip19 } from 'nostr-tools';
|
||||||
import { Bot, Check, Sparkles, ArrowRight, ArrowLeft, ExternalLink, Search, Coins } from 'lucide-react';
|
import { Bot, Check, Sparkles, ArrowRight, ArrowLeft, Search, Coins } from 'lucide-react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
@@ -9,7 +9,7 @@ import { Card, CardHeader, CardTitle } from '@/components/ui/card';
|
|||||||
import { Skeleton } from '@/components/ui/skeleton';
|
import { Skeleton } from '@/components/ui/skeleton';
|
||||||
import { Checkbox } from '@/components/ui/checkbox';
|
import { Checkbox } from '@/components/ui/checkbox';
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
import { PasswordInput } from '@/components/ui/password-input';
|
import { ExternalInput } from '@/components/ui/external-input';
|
||||||
import { useAISettings } from '@/hooks/useAISettings';
|
import { useAISettings } from '@/hooks/useAISettings';
|
||||||
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
||||||
import { useLoginActions } from '@/hooks/useLoginActions';
|
import { useLoginActions } from '@/hooks/useLoginActions';
|
||||||
@@ -465,37 +465,28 @@ export function OnboardingDialog({ open, onOpenChange }: OnboardingDialogProps)
|
|||||||
{/* API Key Input Section */}
|
{/* API Key Input Section */}
|
||||||
{selectedProvider && selectedProvider.apiKeysURL && !selectedProvider.nostr && (
|
{selectedProvider && selectedProvider.apiKeysURL && !selectedProvider.nostr && (
|
||||||
<div className="space-y-3 max-w-md mx-auto">
|
<div className="space-y-3 max-w-md mx-auto">
|
||||||
<div className="text-center">
|
<h3 className="flex justify-center text-lg font-semibold gap-2">
|
||||||
<h3 className="text-lg font-semibold">
|
<ExternalFavicon
|
||||||
|
url={selectedProvider.baseURL}
|
||||||
|
size={16}
|
||||||
|
fallback={<Bot size={16} />}
|
||||||
|
/>
|
||||||
|
<span>
|
||||||
{selectedProvider.id === 'routstr' ? t('enterCashuToken') : t('enterApiKey')}
|
{selectedProvider.id === 'routstr' ? t('enterCashuToken') : t('enterApiKey')}
|
||||||
</h3>
|
</span>
|
||||||
<p className="text-sm text-muted-foreground">
|
</h3>
|
||||||
{selectedProvider.id === 'routstr' ? (
|
<ExternalInput
|
||||||
t('requiresCashuToken', { providerName: selectedProvider.name })
|
type="password"
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
{selectedProvider.name} {t('requiresAnApiKey')}{' '}
|
|
||||||
{selectedProvider.apiKeysURL ? (
|
|
||||||
<a className="text-foreground underline" href={selectedProvider.apiKeysURL} target="_blank">
|
|
||||||
{t('apiKey')}
|
|
||||||
<ExternalLink className="inline-block h-4 w-4 ml-1" />
|
|
||||||
</a>
|
|
||||||
) : (
|
|
||||||
t('apiKey')
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<PasswordInput
|
|
||||||
placeholder={selectedProvider.id === 'routstr' ? t('enterCashuToken') : t('enterApiKey')}
|
placeholder={selectedProvider.id === 'routstr' ? t('enterCashuToken') : t('enterApiKey')}
|
||||||
value={providerApiKey}
|
value={providerApiKey}
|
||||||
onChange={(e) => setProviderApiKey(e.target.value)}
|
onChange={(e) => setProviderApiKey(e.target.value)}
|
||||||
onKeyDown={(e) => {
|
onKeyDown={(e) => {
|
||||||
if (e.key === 'Enter' && providerApiKey.trim()) {
|
if (e.key === 'Enter' && providerApiKey.trim() && agreedToProviderTerms) {
|
||||||
handleContinueFromProviderSelection();
|
handleContinueFromProviderSelection();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
url={selectedProvider.apiKeysURL}
|
||||||
|
urlTitle="Get Key"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -0,0 +1,246 @@
|
|||||||
|
import { useEffect, useRef, useState, useCallback } from 'react';
|
||||||
|
import { MessageSquare, Minus, X } from 'lucide-react';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { ChatPane, type ChatPaneRef } from '@/components/Shakespeare/ChatPane';
|
||||||
|
import { ShakespeareLogo } from '@/components/ShakespeareLogo';
|
||||||
|
import { ProjectPreviewConsoleError } from '@/lib/consoleMessages';
|
||||||
|
import { useLocalStorage } from '@/hooks/useLocalStorage';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
interface FloatingChatWidgetProps {
|
||||||
|
projectId: string;
|
||||||
|
isMinimized: boolean;
|
||||||
|
onToggleMinimize: () => void;
|
||||||
|
onClose: () => void;
|
||||||
|
onNewChat: () => void;
|
||||||
|
onFirstInteraction?: () => void;
|
||||||
|
onLoadingChange?: (isLoading: boolean) => void;
|
||||||
|
isLoading?: boolean;
|
||||||
|
isBuildLoading?: boolean;
|
||||||
|
consoleError?: ProjectPreviewConsoleError | null;
|
||||||
|
onDismissConsoleError?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ChatSize {
|
||||||
|
width: number;
|
||||||
|
height: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const MIN_WIDTH = 320;
|
||||||
|
const MIN_HEIGHT = 380;
|
||||||
|
const MAX_WIDTH = 720;
|
||||||
|
const MAX_HEIGHT = 900;
|
||||||
|
const DEFAULT_WIDTH = 420;
|
||||||
|
const DEFAULT_HEIGHT = 520;
|
||||||
|
|
||||||
|
export function FloatingChatWidget({
|
||||||
|
projectId,
|
||||||
|
isMinimized,
|
||||||
|
onToggleMinimize,
|
||||||
|
onClose,
|
||||||
|
onNewChat,
|
||||||
|
onFirstInteraction,
|
||||||
|
onLoadingChange,
|
||||||
|
isLoading,
|
||||||
|
isBuildLoading,
|
||||||
|
consoleError,
|
||||||
|
onDismissConsoleError,
|
||||||
|
}: FloatingChatWidgetProps) {
|
||||||
|
const chatPaneRef = useRef<ChatPaneRef>(null);
|
||||||
|
const [size, setSize] = useLocalStorage<ChatSize>('shk:floatingChatSize', {
|
||||||
|
width: DEFAULT_WIDTH,
|
||||||
|
height: DEFAULT_HEIGHT,
|
||||||
|
});
|
||||||
|
const [isResizing, setIsResizing] = useState(false);
|
||||||
|
const resizeStartRef = useRef<{ x: number; y: number; width: number; height: number } | null>(null);
|
||||||
|
|
||||||
|
// Handle keyboard escape to minimize
|
||||||
|
useEffect(() => {
|
||||||
|
const handleKeyDown = (e: KeyboardEvent) => {
|
||||||
|
if (e.key === 'Escape' && !isMinimized) {
|
||||||
|
onToggleMinimize();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!isMinimized) {
|
||||||
|
window.addEventListener('keydown', handleKeyDown);
|
||||||
|
return () => window.removeEventListener('keydown', handleKeyDown);
|
||||||
|
}
|
||||||
|
}, [isMinimized, onToggleMinimize]);
|
||||||
|
|
||||||
|
// Resize handlers
|
||||||
|
const startResize = useCallback((e: React.PointerEvent, direction: 'right' | 'bottom' | 'top' | 'bottomLeft' | 'topRight') => {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
|
||||||
|
const target = e.currentTarget as HTMLElement;
|
||||||
|
target.setPointerCapture(e.pointerId);
|
||||||
|
|
||||||
|
setIsResizing(true);
|
||||||
|
document.body.style.userSelect = 'none';
|
||||||
|
|
||||||
|
resizeStartRef.current = {
|
||||||
|
x: e.clientX,
|
||||||
|
y: e.clientY,
|
||||||
|
width: size.width,
|
||||||
|
height: size.height,
|
||||||
|
};
|
||||||
|
|
||||||
|
const handlePointerMove = (moveEvent: PointerEvent) => {
|
||||||
|
if (!resizeStartRef.current) return;
|
||||||
|
|
||||||
|
const maxW = Math.min(MAX_WIDTH, window.innerWidth - 16);
|
||||||
|
const maxH = Math.min(MAX_HEIGHT, window.innerHeight - 16);
|
||||||
|
|
||||||
|
let newWidth = resizeStartRef.current.width;
|
||||||
|
let newHeight = resizeStartRef.current.height;
|
||||||
|
|
||||||
|
// Handle horizontal resizing (left edge for bottom-right anchored widget)
|
||||||
|
if (direction === 'right' || direction === 'bottomLeft' || direction === 'topRight') {
|
||||||
|
const deltaX = resizeStartRef.current.x - moveEvent.clientX;
|
||||||
|
newWidth = Math.max(MIN_WIDTH, Math.min(maxW, resizeStartRef.current.width + deltaX));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle vertical resizing from bottom (grows downward)
|
||||||
|
if (direction === 'bottom' || direction === 'bottomLeft') {
|
||||||
|
const deltaY = resizeStartRef.current.y - moveEvent.clientY;
|
||||||
|
newHeight = Math.max(MIN_HEIGHT, Math.min(maxH, resizeStartRef.current.height + deltaY));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle vertical resizing from top (grows upward, widget anchored at bottom)
|
||||||
|
if (direction === 'top' || direction === 'topRight') {
|
||||||
|
const deltaY = moveEvent.clientY - resizeStartRef.current.y;
|
||||||
|
newHeight = Math.max(MIN_HEIGHT, Math.min(maxH, resizeStartRef.current.height - deltaY));
|
||||||
|
}
|
||||||
|
|
||||||
|
setSize({ width: newWidth, height: newHeight });
|
||||||
|
};
|
||||||
|
|
||||||
|
const handlePointerUp = () => {
|
||||||
|
setIsResizing(false);
|
||||||
|
document.body.style.userSelect = '';
|
||||||
|
resizeStartRef.current = null;
|
||||||
|
|
||||||
|
window.removeEventListener('pointermove', handlePointerMove);
|
||||||
|
window.removeEventListener('pointerup', handlePointerUp);
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener('pointermove', handlePointerMove);
|
||||||
|
window.addEventListener('pointerup', handlePointerUp);
|
||||||
|
}, [size, setSize]);
|
||||||
|
|
||||||
|
if (isMinimized) {
|
||||||
|
return (
|
||||||
|
<div className="fixed right-4 bottom-4 z-50">
|
||||||
|
<Button
|
||||||
|
onClick={onToggleMinimize}
|
||||||
|
size="icon"
|
||||||
|
className="h-14 w-14 rounded-full shadow-lg hover:shadow-xl transition-all duration-200"
|
||||||
|
aria-label="Open chat"
|
||||||
|
>
|
||||||
|
<MessageSquare className="h-6 w-6" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
"fixed right-4 bottom-4 z-50",
|
||||||
|
"rounded-lg border shadow-2xl bg-background",
|
||||||
|
"flex flex-col overflow-hidden",
|
||||||
|
isResizing && "select-none"
|
||||||
|
)}
|
||||||
|
style={{
|
||||||
|
width: `${size.width}px`,
|
||||||
|
height: `${size.height}px`,
|
||||||
|
maxWidth: '92vw',
|
||||||
|
maxHeight: '70vh',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{/* Header - Styled like ProjectSidebar */}
|
||||||
|
<div className="h-12 px-4 border-b flex-shrink-0 flex items-center justify-between bg-gradient-to-r from-primary/10 via-accent/5 to-primary/10 backdrop-blur">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<ShakespeareLogo className="w-5 h-5" />
|
||||||
|
<h2 className="text-base font-semibold bg-gradient-to-r from-primary to-accent bg-clip-text text-transparent">
|
||||||
|
Shakespeare
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
<Button
|
||||||
|
onClick={onToggleMinimize}
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="h-8 w-8"
|
||||||
|
aria-label="Minimize chat"
|
||||||
|
>
|
||||||
|
<Minus className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={onClose}
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="h-8 w-8"
|
||||||
|
aria-label="Close floating chat"
|
||||||
|
>
|
||||||
|
<X className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Chat Body */}
|
||||||
|
<div className="flex-1 min-h-0 overflow-hidden">
|
||||||
|
<div className="h-full">
|
||||||
|
<ChatPane
|
||||||
|
ref={chatPaneRef}
|
||||||
|
projectId={projectId}
|
||||||
|
onNewChat={onNewChat}
|
||||||
|
onFirstInteraction={onFirstInteraction}
|
||||||
|
onLoadingChange={onLoadingChange}
|
||||||
|
isLoading={isLoading}
|
||||||
|
isBuildLoading={isBuildLoading}
|
||||||
|
consoleError={consoleError}
|
||||||
|
onDismissConsoleError={onDismissConsoleError}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Resize Handles */}
|
||||||
|
{/* Left edge (appears as "right" from widget perspective, but it's on the left side) */}
|
||||||
|
<div
|
||||||
|
className="absolute top-0 left-0 h-full w-2 cursor-ew-resize hover:bg-primary/10 active:bg-primary/20 transition-colors"
|
||||||
|
onPointerDown={(e) => startResize(e, 'right')}
|
||||||
|
style={{ touchAction: 'none' }}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Top edge */}
|
||||||
|
<div
|
||||||
|
className="absolute top-0 left-0 w-full h-2 cursor-ns-resize hover:bg-primary/10 active:bg-primary/20 transition-colors"
|
||||||
|
onPointerDown={(e) => startResize(e, 'top')}
|
||||||
|
style={{ touchAction: 'none' }}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Bottom edge */}
|
||||||
|
<div
|
||||||
|
className="absolute bottom-0 left-0 w-full h-2 cursor-ns-resize hover:bg-primary/10 active:bg-primary/20 transition-colors"
|
||||||
|
onPointerDown={(e) => startResize(e, 'bottom')}
|
||||||
|
style={{ touchAction: 'none' }}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Bottom-left corner */}
|
||||||
|
<div
|
||||||
|
className="absolute bottom-0 left-0 w-4 h-4 cursor-nesw-resize hover:bg-primary/20 active:bg-primary/30 transition-colors"
|
||||||
|
onPointerDown={(e) => startResize(e, 'bottomLeft')}
|
||||||
|
style={{ touchAction: 'none' }}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Top-right corner */}
|
||||||
|
<div
|
||||||
|
className="absolute top-0 right-0 w-4 h-4 cursor-nesw-resize hover:bg-primary/20 active:bg-primary/30 transition-colors"
|
||||||
|
onPointerDown={(e) => startResize(e, 'topRight')}
|
||||||
|
style={{ touchAction: 'none' }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -63,10 +63,10 @@ export function CloudflareDeployForm({
|
|||||||
const workersUrl = `${baseURL}/accounts/${accountId}/workers/scripts`;
|
const workersUrl = `${baseURL}/accounts/${accountId}/workers/scripts`;
|
||||||
|
|
||||||
const [subdomainResponse, workersResponse] = await Promise.all([
|
const [subdomainResponse, workersResponse] = await Promise.all([
|
||||||
fetch(corsProxy ? proxyUrl(corsProxy, subdomainUrl) : subdomainUrl, {
|
fetch(corsProxy ? proxyUrl({ template: corsProxy, url: subdomainUrl }) : subdomainUrl, {
|
||||||
headers: { 'Authorization': `Bearer ${apiKey}` },
|
headers: { 'Authorization': `Bearer ${apiKey}` },
|
||||||
}),
|
}),
|
||||||
fetch(corsProxy ? proxyUrl(corsProxy, workersUrl) : workersUrl, {
|
fetch(corsProxy ? proxyUrl({ template: corsProxy, url: workersUrl }) : workersUrl, {
|
||||||
headers: { 'Authorization': `Bearer ${apiKey}` },
|
headers: { 'Authorization': `Bearer ${apiKey}` },
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ export function DenoDeployForm({
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const url = `${baseURL}/organizations/${organizationId}/projects?limit=100`;
|
const url = `${baseURL}/organizations/${organizationId}/projects?limit=100`;
|
||||||
const targetUrl = corsProxy ? proxyUrl(corsProxy, url) : url;
|
const targetUrl = corsProxy ? proxyUrl({ template: corsProxy, url }) : url;
|
||||||
|
|
||||||
const response = await fetch(targetUrl, {
|
const response = await fetch(targetUrl, {
|
||||||
headers: { 'Authorization': `Bearer ${apiKey}` },
|
headers: { 'Authorization': `Bearer ${apiKey}` },
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ export function NetlifyDeployForm({
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const url = `${baseURL}/sites`;
|
const url = `${baseURL}/sites`;
|
||||||
const targetUrl = corsProxy ? proxyUrl(corsProxy, url) : url;
|
const targetUrl = corsProxy ? proxyUrl({ template: corsProxy, url }) : url;
|
||||||
|
|
||||||
const response = await fetch(targetUrl, {
|
const response = await fetch(targetUrl, {
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useState, useEffect, useRef } from 'react';
|
import { useState, useEffect, useRef } from 'react';
|
||||||
import { CloudUpload, Loader2, Check } from 'lucide-react';
|
import { CloudUpload, Loader2, Check, AlertTriangle } from 'lucide-react';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
|
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
|
||||||
import { useGitStatus } from '@/hooks/useGitStatus';
|
import { useGitStatus } from '@/hooks/useGitStatus';
|
||||||
@@ -16,6 +16,8 @@ interface GitSyncButtonProps {
|
|||||||
export function GitSyncButton({ projectId, className }: GitSyncButtonProps) {
|
export function GitSyncButton({ projectId, className }: GitSyncButtonProps) {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [syncSuccess, setSyncSuccess] = useState(false);
|
const [syncSuccess, setSyncSuccess] = useState(false);
|
||||||
|
const [showWarningPopover, setShowWarningPopover] = useState(false);
|
||||||
|
const warningDismissed = useRef(false);
|
||||||
|
|
||||||
const { data: gitStatus, isLoading: isGitStatusLoading } = useGitStatus(projectId);
|
const { data: gitStatus, isLoading: isGitStatusLoading } = useGitStatus(projectId);
|
||||||
const { getError, getState } = useGitSyncState();
|
const { getError, getState } = useGitSyncState();
|
||||||
@@ -26,6 +28,18 @@ export function GitSyncButton({ projectId, className }: GitSyncButtonProps) {
|
|||||||
const gitSyncState = getState(dir);
|
const gitSyncState = getState(dir);
|
||||||
const isGitActionOccurring = gitSyncState?.isActive ?? false;
|
const isGitActionOccurring = gitSyncState?.isActive ?? false;
|
||||||
const prevIsGitActionOccurring = useRef(isGitActionOccurring);
|
const prevIsGitActionOccurring = useRef(isGitActionOccurring);
|
||||||
|
const prevProjectId = useRef(projectId);
|
||||||
|
|
||||||
|
// Reset state when projectId changes
|
||||||
|
useEffect(() => {
|
||||||
|
if (prevProjectId.current !== projectId) {
|
||||||
|
setSyncSuccess(false);
|
||||||
|
setShowWarningPopover(false);
|
||||||
|
warningDismissed.current = false;
|
||||||
|
prevIsGitActionOccurring.current = isGitActionOccurring;
|
||||||
|
prevProjectId.current = projectId;
|
||||||
|
}
|
||||||
|
}, [projectId, isGitActionOccurring]);
|
||||||
|
|
||||||
// Detect when a git action completes successfully
|
// Detect when a git action completes successfully
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -38,6 +52,29 @@ export function GitSyncButton({ projectId, className }: GitSyncButtonProps) {
|
|||||||
prevIsGitActionOccurring.current = isGitActionOccurring;
|
prevIsGitActionOccurring.current = isGitActionOccurring;
|
||||||
}, [isGitActionOccurring, hasError]);
|
}, [isGitActionOccurring, hasError]);
|
||||||
|
|
||||||
|
// Check if we need to show the warning popover
|
||||||
|
const needsRemote = !isGitStatusLoading && gitStatus &&
|
||||||
|
!gitStatus.remotes.find(r => r.name === 'origin') &&
|
||||||
|
gitStatus.totalCommits > 1;
|
||||||
|
|
||||||
|
// Show warning popover when purple indicator is visible (only if not dismissed)
|
||||||
|
useEffect(() => {
|
||||||
|
if (needsRemote && !warningDismissed.current && gitStatus.totalCommits > 1) {
|
||||||
|
setShowWarningPopover(true);
|
||||||
|
} else {
|
||||||
|
setShowWarningPopover(false);
|
||||||
|
}
|
||||||
|
}, [gitStatus?.totalCommits, needsRemote]);
|
||||||
|
|
||||||
|
// Handle button click - dismiss warning popover permanently
|
||||||
|
const handleButtonClick = () => {
|
||||||
|
if (showWarningPopover) {
|
||||||
|
warningDismissed.current = true;
|
||||||
|
setShowWarningPopover(false);
|
||||||
|
}
|
||||||
|
setOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
// Determine which indicator to show (only one at a time, in priority order)
|
// Determine which indicator to show (only one at a time, in priority order)
|
||||||
const renderIndicator = () => {
|
const renderIndicator = () => {
|
||||||
// Checkmark: sync just completed successfully - highest priority
|
// Checkmark: sync just completed successfully - highest priority
|
||||||
@@ -78,26 +115,61 @@ export function GitSyncButton({ projectId, className }: GitSyncButtonProps) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Popover open={open} onOpenChange={setOpen}>
|
<>
|
||||||
<PopoverTrigger asChild>
|
{/* Warning popover - shown when purple indicator is visible */}
|
||||||
<Button
|
<Popover open={showWarningPopover} modal={false}>
|
||||||
variant="ghost"
|
<PopoverTrigger asChild>
|
||||||
size="sm"
|
<div className="relative">
|
||||||
className={cn("size-8 p-0 group relative", className)}
|
{/* Main Git Sync popover */}
|
||||||
aria-label="Sync with Git"
|
<Popover open={open} onOpenChange={setOpen}>
|
||||||
|
<PopoverTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
className={cn("size-8 p-0 group relative", className)}
|
||||||
|
aria-label="Sync with Git"
|
||||||
|
onClick={handleButtonClick}
|
||||||
|
>
|
||||||
|
<CloudUpload className={cn("size-5 group-hover:text-foreground", open ? "text-foreground" : "text-muted-foreground")} />
|
||||||
|
{renderIndicator()}
|
||||||
|
</Button>
|
||||||
|
</PopoverTrigger>
|
||||||
|
<PopoverContent
|
||||||
|
align="start"
|
||||||
|
className="w-96"
|
||||||
|
onOpenAutoFocus={(e) => e.preventDefault()}
|
||||||
|
>
|
||||||
|
<GitSyncSteps projectId={projectId} onClose={() => setOpen(false)} />
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
|
</div>
|
||||||
|
</PopoverTrigger>
|
||||||
|
<PopoverContent
|
||||||
|
side="bottom"
|
||||||
|
align="center"
|
||||||
|
className="w-80 pointer-events-none z-40"
|
||||||
|
onOpenAutoFocus={(e) => e.preventDefault()}
|
||||||
|
onInteractOutside={(e) => e.preventDefault()}
|
||||||
>
|
>
|
||||||
<CloudUpload className={cn("size-5 group-hover:text-foreground", open ? "text-foreground" : "text-muted-foreground")} />
|
<div className="space-y-3 pointer-events-auto">
|
||||||
{renderIndicator()}
|
<div className="flex items-center gap-2">
|
||||||
</Button>
|
<AlertTriangle className="size-5 text-primary shrink-0" />
|
||||||
</PopoverTrigger>
|
<h4 className="font-semibold text-sm">Your project files are not safe</h4>
|
||||||
<PopoverContent
|
</div>
|
||||||
align="start"
|
<p className="text-sm text-muted-foreground">
|
||||||
className="w-96"
|
Your project files are stored in your browser session and could be deleted. Sync with git to back up your project.
|
||||||
onOpenAutoFocus={(e) => e.preventDefault()}
|
</p>
|
||||||
>
|
<Button
|
||||||
<GitSyncSteps projectId={projectId} onClose={() => setOpen(false)} />
|
onClick={handleButtonClick}
|
||||||
</PopoverContent>
|
className="w-full"
|
||||||
</Popover>
|
size="sm"
|
||||||
|
>
|
||||||
|
Continue
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ export function SyncStep({ projectId, remoteUrl }: SyncStepProps) {
|
|||||||
|
|
||||||
if (url.protocol === 'nostr:') {
|
if (url.protocol === 'nostr:') {
|
||||||
const nostrUri = await NostrURI.parse(url.href);
|
const nostrUri = await NostrURI.parse(url.href);
|
||||||
return ngitWebUrl(config.ngitWebUrl, nostrUri);
|
return ngitWebUrl({ template: config.ngitWebUrl, nostrURI: nostrUri });
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ export interface AIProvider {
|
|||||||
apiKey?: string;
|
apiKey?: string;
|
||||||
nostr?: boolean;
|
nostr?: boolean;
|
||||||
proxy?: boolean;
|
proxy?: boolean;
|
||||||
|
openSecret?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MCPServer {
|
export interface MCPServer {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ export function useGitHubOAuth() {
|
|||||||
redirectUri: window.location.origin + '/oauth/github',
|
redirectUri: window.location.origin + '/oauth/github',
|
||||||
usePKCE: true, // GitHub supports PKCE
|
usePKCE: true, // GitHub supports PKCE
|
||||||
getUserInfo: async (accessToken: string, corsProxy: string) => {
|
getUserInfo: async (accessToken: string, corsProxy: string) => {
|
||||||
const userUrl = proxyUrl(corsProxy, 'https://api.github.com/user');
|
const userUrl = proxyUrl({ template: corsProxy, url: 'https://api.github.com/user' });
|
||||||
const userResponse = await fetch(userUrl, {
|
const userResponse = await fetch(userUrl, {
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Bearer ${accessToken}`,
|
'Authorization': `Bearer ${accessToken}`,
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ export function useNetlifyOAuth() {
|
|||||||
redirectUri: window.location.origin + '/oauth/netlify',
|
redirectUri: window.location.origin + '/oauth/netlify',
|
||||||
usePKCE: false, // Netlify doesn't support PKCE
|
usePKCE: false, // Netlify doesn't support PKCE
|
||||||
getUserInfo: async (accessToken: string, corsProxy: string) => {
|
getUserInfo: async (accessToken: string, corsProxy: string) => {
|
||||||
const userUrl = proxyUrl(corsProxy, 'https://api.netlify.com/api/v1/user');
|
const userUrl = proxyUrl({ template: corsProxy, url: 'https://api.netlify.com/api/v1/user' });
|
||||||
const userResponse = await fetch(userUrl, {
|
const userResponse = await fetch(userUrl, {
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Bearer ${accessToken}`,
|
'Authorization': `Bearer ${accessToken}`,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { useAppContext } from './useAppContext';
|
|||||||
import { proxyUrl } from '@/lib/proxyUrl';
|
import { proxyUrl } from '@/lib/proxyUrl';
|
||||||
|
|
||||||
export interface OAuthConfig {
|
export interface OAuthConfig {
|
||||||
provider: 'github' | 'netlify' | 'vercel';
|
provider: 'github' | 'netlify' | 'vercel' | 'openrouter';
|
||||||
clientId: string;
|
clientId: string;
|
||||||
clientSecret: string;
|
clientSecret: string;
|
||||||
authorizeUrl: string;
|
authorizeUrl: string;
|
||||||
@@ -169,7 +169,7 @@ export function useOAuth(config: OAuthConfig) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Exchange code for access token
|
// Exchange code for access token
|
||||||
const tokenUrl = proxyUrl(corsProxy, config.tokenUrl);
|
const tokenUrl = proxyUrl({ template: corsProxy, url: config.tokenUrl });
|
||||||
const tokenResponse = await fetch(tokenUrl, {
|
const tokenResponse = await fetch(tokenUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
@@ -0,0 +1,164 @@
|
|||||||
|
import { useState, useCallback } from 'react';
|
||||||
|
import { useAISettings } from './useAISettings';
|
||||||
|
import type { AIProvider } from '@/contexts/AISettingsContext';
|
||||||
|
|
||||||
|
interface OpenRouterTokenResponse {
|
||||||
|
key: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook for OpenRouter OAuth authentication with PKCE.
|
||||||
|
* OpenRouter uses a custom OAuth flow that differs from standard OAuth 2.0.
|
||||||
|
* It uses PKCE without requiring client credentials.
|
||||||
|
*/
|
||||||
|
export function useOpenRouterOAuth() {
|
||||||
|
const { setProvider, isLoading: isSettingsLoading } = useAISettings();
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
|
// OpenRouter doesn't require client credentials - it uses PKCE only
|
||||||
|
const isOAuthConfigured = true;
|
||||||
|
|
||||||
|
// Generate a cryptographically secure random string for PKCE code verifier
|
||||||
|
const generateCodeVerifier = (): string => {
|
||||||
|
const array = new Uint8Array(32);
|
||||||
|
crypto.getRandomValues(array);
|
||||||
|
return btoa(String.fromCharCode(...array))
|
||||||
|
.replace(/\+/g, '-')
|
||||||
|
.replace(/\//g, '_')
|
||||||
|
.replace(/=/g, '');
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create SHA-256 hash of the code verifier for PKCE code challenge
|
||||||
|
const generateCodeChallenge = async (codeVerifier: string): Promise<string> => {
|
||||||
|
const encoder = new TextEncoder();
|
||||||
|
const data = encoder.encode(codeVerifier);
|
||||||
|
const digest = await crypto.subtle.digest('SHA-256', data);
|
||||||
|
return btoa(String.fromCharCode(...new Uint8Array(digest)))
|
||||||
|
.replace(/\+/g, '-')
|
||||||
|
.replace(/\//g, '_')
|
||||||
|
.replace(/=/g, '');
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initiates the OAuth flow by redirecting to OpenRouter's authorization page.
|
||||||
|
*/
|
||||||
|
const initiateOAuth = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
// Generate a random state parameter for security
|
||||||
|
const state = crypto.randomUUID();
|
||||||
|
const storagePrefix = 'openrouter_oauth';
|
||||||
|
|
||||||
|
// Store state for later verification
|
||||||
|
localStorage.setItem(`${storagePrefix}_state`, state);
|
||||||
|
|
||||||
|
// Generate PKCE parameters
|
||||||
|
const codeVerifier = generateCodeVerifier();
|
||||||
|
const codeChallenge = await generateCodeChallenge(codeVerifier);
|
||||||
|
|
||||||
|
localStorage.setItem(`${storagePrefix}_code_verifier`, codeVerifier);
|
||||||
|
|
||||||
|
// Build authorization URL
|
||||||
|
const redirectUri = window.location.origin + '/oauth/openrouter';
|
||||||
|
const params = new URLSearchParams({
|
||||||
|
callback_url: redirectUri,
|
||||||
|
code_challenge: codeChallenge,
|
||||||
|
code_challenge_method: 'S256',
|
||||||
|
});
|
||||||
|
|
||||||
|
// Redirect to OpenRouter's authorization page
|
||||||
|
window.location.href = `https://openrouter.ai/auth?${params.toString()}`;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to initiate OpenRouter OAuth:', error);
|
||||||
|
setError('Failed to generate PKCE parameters. Please try again.');
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the OAuth callback after the user authorizes the application.
|
||||||
|
* Exchanges the authorization code for an API key.
|
||||||
|
*/
|
||||||
|
const handleCallback = useCallback(async (
|
||||||
|
code: string,
|
||||||
|
_state: string
|
||||||
|
): Promise<boolean> => {
|
||||||
|
setIsLoading(true);
|
||||||
|
setError(null);
|
||||||
|
|
||||||
|
const storagePrefix = 'openrouter_oauth';
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Get PKCE code verifier
|
||||||
|
const codeVerifier = localStorage.getItem(`${storagePrefix}_code_verifier`);
|
||||||
|
if (!codeVerifier) {
|
||||||
|
throw new Error('PKCE code verifier not found. Please restart the OAuth flow.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean up stored values
|
||||||
|
localStorage.removeItem(`${storagePrefix}_state`);
|
||||||
|
localStorage.removeItem(`${storagePrefix}_code_verifier`);
|
||||||
|
|
||||||
|
// Exchange code for API key using OpenRouter's custom endpoint
|
||||||
|
const tokenResponse = await fetch('https://openrouter.ai/api/v1/auth/keys', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
code: code,
|
||||||
|
code_verifier: codeVerifier,
|
||||||
|
code_challenge_method: 'S256',
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!tokenResponse.ok) {
|
||||||
|
const errorText = await tokenResponse.text();
|
||||||
|
throw new Error(`OpenRouter token exchange failed: ${tokenResponse.statusText} - ${errorText}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const tokenData: OpenRouterTokenResponse = await tokenResponse.json();
|
||||||
|
|
||||||
|
if (!tokenData.key) {
|
||||||
|
throw new Error('No API key received from OpenRouter');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for settings to be initialized before storing
|
||||||
|
if (isSettingsLoading) {
|
||||||
|
throw new Error('Settings not initialized. Please try again.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a new OpenRouter provider with the OAuth token
|
||||||
|
const newProvider: AIProvider = {
|
||||||
|
id: 'openrouter',
|
||||||
|
name: 'OpenRouter',
|
||||||
|
baseURL: 'https://openrouter.ai/api/v1',
|
||||||
|
apiKey: tokenData.key,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add or update the OpenRouter provider in settings
|
||||||
|
setProvider(newProvider);
|
||||||
|
|
||||||
|
setIsLoading(false);
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('OpenRouter OAuth error:', error);
|
||||||
|
|
||||||
|
// Clean up any remaining OAuth data on error
|
||||||
|
localStorage.removeItem(`${storagePrefix}_state`);
|
||||||
|
localStorage.removeItem(`${storagePrefix}_code_verifier`);
|
||||||
|
|
||||||
|
setError(error instanceof Error ? error.message : 'OAuth authentication failed');
|
||||||
|
setIsLoading(false);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}, [setProvider, isSettingsLoading]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
isLoading,
|
||||||
|
error,
|
||||||
|
isOAuthConfigured,
|
||||||
|
initiateOAuth,
|
||||||
|
handleCallback,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ export function useVercelOAuth() {
|
|||||||
redirectUri: window.location.origin + '/oauth/vercel',
|
redirectUri: window.location.origin + '/oauth/vercel',
|
||||||
usePKCE: false, // Vercel doesn't require PKCE
|
usePKCE: false, // Vercel doesn't require PKCE
|
||||||
getUserInfo: async (accessToken: string, corsProxy: string) => {
|
getUserInfo: async (accessToken: string, corsProxy: string) => {
|
||||||
const userUrl = proxyUrl(corsProxy, 'https://api.vercel.com/v2/user');
|
const userUrl = proxyUrl({ template: corsProxy, url: 'https://api.vercel.com/v2/user' });
|
||||||
const userResponse = await fetch(userUrl, {
|
const userResponse = await fetch(userUrl, {
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Bearer ${accessToken}`,
|
'Authorization': `Bearer ${accessToken}`,
|
||||||
|
|||||||
+60
-14
@@ -450,7 +450,7 @@ export class SessionManager {
|
|||||||
|
|
||||||
let accumulatedContent = '';
|
let accumulatedContent = '';
|
||||||
let accumulatedReasoningContent = '';
|
let accumulatedReasoningContent = '';
|
||||||
const accumulatedToolCalls: OpenAI.Chat.Completions.ChatCompletionMessageToolCall[] = [];
|
const accumulatedToolCalls: Map<number, OpenAI.Chat.Completions.ChatCompletionMessageFunctionToolCall> = new Map();
|
||||||
let finishReason: string | null = null;
|
let finishReason: string | null = null;
|
||||||
|
|
||||||
// Process the stream
|
// Process the stream
|
||||||
@@ -491,20 +491,29 @@ export class SessionManager {
|
|||||||
const toolCallDelta = delta.tool_calls[i];
|
const toolCallDelta = delta.tool_calls[i];
|
||||||
const index = toolCallDelta.index ?? i; // Fix for Gemini models
|
const index = toolCallDelta.index ?? i; // Fix for Gemini models
|
||||||
|
|
||||||
accumulatedToolCalls[index] ??= {
|
let toolCall = accumulatedToolCalls.get(index);
|
||||||
id: '',
|
|
||||||
type: 'function',
|
if (!toolCall) {
|
||||||
function: { name: '', arguments: '' }
|
toolCall = {
|
||||||
};
|
id: '',
|
||||||
|
type: 'function',
|
||||||
|
function: { name: '', arguments: '' },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const toolCall = accumulatedToolCalls[index] as OpenAI.Chat.Completions.ChatCompletionMessageFunctionToolCall;
|
|
||||||
if (toolCallDelta.id) toolCall.id = toolCallDelta.id;
|
if (toolCallDelta.id) toolCall.id = toolCallDelta.id;
|
||||||
if (toolCallDelta.function?.name) toolCall.function.name = toolCallDelta.function.name;
|
if (toolCallDelta.function?.name) toolCall.function.name = toolCallDelta.function.name;
|
||||||
if (toolCallDelta.function?.arguments) toolCall.function.arguments += toolCallDelta.function.arguments;
|
if (toolCallDelta.function?.arguments) toolCall.function.arguments += toolCallDelta.function.arguments;
|
||||||
|
|
||||||
|
accumulatedToolCalls.set(index, toolCall);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (session.streamingMessage) {
|
if (session.streamingMessage && accumulatedToolCalls.size > 0) {
|
||||||
session.streamingMessage.tool_calls = accumulatedToolCalls.length > 0 ? accumulatedToolCalls : undefined;
|
const sortedToolCalls = [...accumulatedToolCalls.entries()]
|
||||||
|
.sort((a, b) => a[0] - b[0])
|
||||||
|
.map(entry => entry[1]);
|
||||||
|
|
||||||
|
session.streamingMessage.tool_calls = sortedToolCalls;
|
||||||
this.emit('streamingUpdate', projectId, session.streamingMessage.content, session.streamingMessage.reasoning_content, session.streamingMessage.tool_calls);
|
this.emit('streamingUpdate', projectId, session.streamingMessage.content, session.streamingMessage.reasoning_content, session.streamingMessage.tool_calls);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -528,7 +537,7 @@ export class SessionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fix tool calls with empty arguments or names
|
// Fix tool calls with empty arguments or names
|
||||||
for (const toolCall of accumulatedToolCalls) {
|
for (const toolCall of accumulatedToolCalls.values()) {
|
||||||
if (toolCall.type === 'function') {
|
if (toolCall.type === 'function') {
|
||||||
toolCall.function.arguments = toolCall.function.arguments || '{}';
|
toolCall.function.arguments = toolCall.function.arguments || '{}';
|
||||||
|
|
||||||
@@ -549,7 +558,7 @@ export class SessionManager {
|
|||||||
role: 'assistant',
|
role: 'assistant',
|
||||||
content: accumulatedContent,
|
content: accumulatedContent,
|
||||||
...(accumulatedReasoningContent && { reasoning_content: accumulatedReasoningContent }),
|
...(accumulatedReasoningContent && { reasoning_content: accumulatedReasoningContent }),
|
||||||
...(accumulatedToolCalls.length > 0 && { tool_calls: accumulatedToolCalls })
|
...(accumulatedToolCalls.size > 0 && { tool_calls: [...accumulatedToolCalls.values()] })
|
||||||
};
|
};
|
||||||
|
|
||||||
// Check if the assistant message is empty (no content, reasoning, or tool calls)
|
// Check if the assistant message is empty (no content, reasoning, or tool calls)
|
||||||
@@ -575,8 +584,8 @@ export class SessionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle tool calls
|
// Handle tool calls
|
||||||
if (accumulatedToolCalls?.length) {
|
if (accumulatedToolCalls?.size) {
|
||||||
for (const toolCall of accumulatedToolCalls) {
|
for (const toolCall of accumulatedToolCalls.values()) {
|
||||||
if (toolCall.type !== 'function') continue;
|
if (toolCall.type !== 'function') continue;
|
||||||
|
|
||||||
const functionToolCall = toolCall as OpenAI.Chat.Completions.ChatCompletionMessageFunctionToolCall;
|
const functionToolCall = toolCall as OpenAI.Chat.Completions.ChatCompletionMessageFunctionToolCall;
|
||||||
@@ -711,13 +720,50 @@ export class SessionManager {
|
|||||||
this.emit('finishReasonChanged', projectId, null);
|
this.emit('finishReasonChanged', projectId, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if content exceeds size/line limits
|
||||||
|
*/
|
||||||
|
private exceedsLimits(content: string): boolean {
|
||||||
|
const MAX_SIZE_BYTES = 50 * 1024; // 50 KiB
|
||||||
|
const MAX_LINES = 2000;
|
||||||
|
|
||||||
|
const sizeBytes = new Blob([content]).size;
|
||||||
|
const lineCount = content.split('\n').length;
|
||||||
|
|
||||||
|
return sizeBytes > MAX_SIZE_BYTES || lineCount > MAX_LINES;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save content to tmpDir and return the file path
|
||||||
|
*/
|
||||||
|
private async saveToTmpFile(projectId: string, content: string, toolCallId: string): Promise<string> {
|
||||||
|
const config = this.getConfig();
|
||||||
|
const timestamp = Date.now();
|
||||||
|
const filename = `tool-output-${toolCallId}-${timestamp}.txt`;
|
||||||
|
const filepath = `${config.fsPathTmp}/${filename}`;
|
||||||
|
|
||||||
|
await this.fs.writeFile(filepath, content, 'utf8');
|
||||||
|
return filepath;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper to add tool messages and update conversation
|
* Helper to add tool messages and update conversation
|
||||||
*/
|
*/
|
||||||
private async addToolMessage(projectId: string, toolCallId: string, content: string): Promise<void> {
|
private async addToolMessage(projectId: string, toolCallId: string, content: string): Promise<void> {
|
||||||
|
let finalContent = content;
|
||||||
|
|
||||||
|
// Check if content exceeds limits
|
||||||
|
if (this.exceedsLimits(content)) {
|
||||||
|
// Save full content to tmp file
|
||||||
|
const filepath = await this.saveToTmpFile(projectId, content, toolCallId);
|
||||||
|
|
||||||
|
// Create placeholder message
|
||||||
|
finalContent = `The tool call succeeded but the output was truncated. Full output saved to: ${filepath}\nUse grep to search it for specific content, or text_editor_view with start_line/end_line to view specific sections.`;
|
||||||
|
}
|
||||||
|
|
||||||
const toolMessage: AIMessage = {
|
const toolMessage: AIMessage = {
|
||||||
role: 'tool',
|
role: 'tool',
|
||||||
content,
|
content: finalContent,
|
||||||
tool_call_id: toolCallId
|
tool_call_id: toolCallId
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+50
-9
@@ -12,17 +12,21 @@ import { proxyUrl } from './proxyUrl';
|
|||||||
* If the provider has proxy enabled, requests will be proxied through the corsProxy.
|
* If the provider has proxy enabled, requests will be proxied through the corsProxy.
|
||||||
*/
|
*/
|
||||||
export function createAIClient(provider: AIProvider, user?: NUser, corsProxy?: string): OpenAI {
|
export function createAIClient(provider: AIProvider, user?: NUser, corsProxy?: string): OpenAI {
|
||||||
const baseConfig: ConstructorParameters<typeof OpenAI>[0] = {
|
const openai = new OpenAI({
|
||||||
baseURL: provider.baseURL,
|
baseURL: provider.baseURL,
|
||||||
apiKey: provider.apiKey ?? '',
|
apiKey: provider.apiKey ?? '',
|
||||||
dangerouslyAllowBrowser: true,
|
dangerouslyAllowBrowser: true,
|
||||||
};
|
|
||||||
|
|
||||||
const openai = new OpenAI({
|
|
||||||
...baseConfig,
|
|
||||||
fetch: async (input, init) => {
|
fetch: async (input, init) => {
|
||||||
let request = new Request(input, init);
|
let request = new Request(input, init);
|
||||||
|
|
||||||
|
// OpenSecret auth
|
||||||
|
// https://docs.opensecret.cloud/docs/maple-ai/
|
||||||
|
if (provider.openSecret) {
|
||||||
|
const { createCustomFetch } = await import('@opensecret/react');
|
||||||
|
return createCustomFetch({ apiKey: provider.apiKey, apiUrl: provider.openSecret })(input, init);
|
||||||
|
}
|
||||||
|
|
||||||
// Add OpenRouter headers
|
// Add OpenRouter headers
|
||||||
// https://openrouter.ai/docs/app-attribution
|
// https://openrouter.ai/docs/app-attribution
|
||||||
if (provider.id === 'openrouter') {
|
if (provider.id === 'openrouter') {
|
||||||
@@ -47,7 +51,7 @@ export function createAIClient(provider: AIProvider, user?: NUser, corsProxy?: s
|
|||||||
|
|
||||||
// If proxy is enabled and we have a CORS proxy URL, modify the request URL
|
// If proxy is enabled and we have a CORS proxy URL, modify the request URL
|
||||||
if (provider.proxy && corsProxy) {
|
if (provider.proxy && corsProxy) {
|
||||||
request = new Request(proxyUrl(corsProxy, request.url), request);
|
request = new Request(proxyUrl({ template: corsProxy, url: request.url }), request);
|
||||||
}
|
}
|
||||||
|
|
||||||
return fetch(request);
|
return fetch(request);
|
||||||
@@ -58,14 +62,51 @@ 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);
|
||||||
}) as typeof createCompletion;
|
}) as typeof createCompletion;
|
||||||
|
|
||||||
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" };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -6,6 +6,7 @@ export interface PresetProvider {
|
|||||||
nostr?: boolean;
|
nostr?: boolean;
|
||||||
tosURL?: string;
|
tosURL?: string;
|
||||||
proxy?: boolean;
|
proxy?: boolean;
|
||||||
|
openSecret?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AI_PROVIDER_PRESETS: PresetProvider[] = [
|
export const AI_PROVIDER_PRESETS: PresetProvider[] = [
|
||||||
@@ -16,6 +17,22 @@ export const AI_PROVIDER_PRESETS: PresetProvider[] = [
|
|||||||
tosURL: "https://ai.shakespeare.diy/terms",
|
tosURL: "https://ai.shakespeare.diy/terms",
|
||||||
nostr: true,
|
nostr: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
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: "maple",
|
||||||
|
name: "Maple AI",
|
||||||
|
baseURL: "https://enclave.trymaple.ai/v1",
|
||||||
|
apiKeysURL: "https://trymaple.ai/",
|
||||||
|
tosURL: "https://opensecret.cloud/terms",
|
||||||
|
openSecret: "https://enclave.trymaple.ai",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
id: "openrouter",
|
id: "openrouter",
|
||||||
name: "OpenRouter",
|
name: "OpenRouter",
|
||||||
|
|||||||
@@ -260,6 +260,19 @@ export function esmPlugin(options: EsmPluginOptions): Plugin {
|
|||||||
// not a URL; continue
|
// not a URL; continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if this is a file: dependency
|
||||||
|
const allDeps = {
|
||||||
|
...packageJson.dependencies,
|
||||||
|
...packageJson.devDependencies,
|
||||||
|
...packageJson.peerDependencies,
|
||||||
|
};
|
||||||
|
const depVersion = allDeps[packageName];
|
||||||
|
|
||||||
|
if (depVersion && depVersion.startsWith("file:")) {
|
||||||
|
// Let fsPlugin handle file: dependencies
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Determine importer lock path (breadcrumb)
|
// Determine importer lock path (breadcrumb)
|
||||||
const importerLockPath = getImporterLockPath(args.importer);
|
const importerLockPath = getImporterLockPath(args.importer);
|
||||||
|
|
||||||
@@ -430,6 +443,8 @@ export function esmPlugin(options: EsmPluginOptions): Plugin {
|
|||||||
if (contentType) {
|
if (contentType) {
|
||||||
if (contentType === "application/javascript") {
|
if (contentType === "application/javascript") {
|
||||||
loader = "js";
|
loader = "js";
|
||||||
|
} else if (contentType === "application/json") {
|
||||||
|
loader = "json";
|
||||||
} else if (contentType === "text/css") {
|
} else if (contentType === "text/css") {
|
||||||
loader = "css";
|
loader = "css";
|
||||||
} else if (contentType === "application/wasm") {
|
} else if (contentType === "application/wasm") {
|
||||||
|
|||||||
@@ -10,14 +10,21 @@ interface TsConfig {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface PackageJson {
|
||||||
|
dependencies?: { [key: string]: string };
|
||||||
|
devDependencies?: { [key: string]: string };
|
||||||
|
peerDependencies?: { [key: string]: string };
|
||||||
|
}
|
||||||
|
|
||||||
interface FsPluginOptions {
|
interface FsPluginOptions {
|
||||||
fs: JSRuntimeFS;
|
fs: JSRuntimeFS;
|
||||||
cwd: string;
|
cwd: string;
|
||||||
tsconfig?: TsConfig;
|
tsconfig?: TsConfig;
|
||||||
|
packageJson?: PackageJson;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fsPlugin(options: FsPluginOptions): Plugin {
|
export function fsPlugin(options: FsPluginOptions): Plugin {
|
||||||
const { fs, cwd, tsconfig } = options;
|
const { fs, cwd, tsconfig, packageJson } = options;
|
||||||
return {
|
return {
|
||||||
name: "fs",
|
name: "fs",
|
||||||
|
|
||||||
@@ -30,21 +37,65 @@ export function fsPlugin(options: FsPluginOptions): Plugin {
|
|||||||
});
|
});
|
||||||
|
|
||||||
build.onResolve({ filter: /.*/ }, async (args) => {
|
build.onResolve({ filter: /.*/ }, async (args) => {
|
||||||
// Skip resolving paths from external URLs
|
// Skip resolving paths from external URLs (but not fs: namespace)
|
||||||
if (/^https?:\/\//.test(args.importer)) {
|
if (/^https?:\/\//.test(args.importer)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let resolved: string;
|
let resolved: string | undefined;
|
||||||
|
|
||||||
|
// Handle absolute paths
|
||||||
if (args.path.startsWith("/")) {
|
if (args.path.startsWith("/")) {
|
||||||
resolved = args.path;
|
resolved = args.path;
|
||||||
} else if (args.path.startsWith("@/")) {
|
}
|
||||||
|
// Handle @/ alias
|
||||||
|
else if (args.path.startsWith("@/")) {
|
||||||
resolved = join(cwd, "src", args.path.slice(2));
|
resolved = join(cwd, "src", args.path.slice(2));
|
||||||
} else if (args.importer && (args.path.startsWith("./") || args.path.startsWith("../"))) {
|
}
|
||||||
resolved = join(dirname(args.importer), args.path);
|
// Handle relative paths
|
||||||
} else if (args.importer && tsconfig?.compilerOptions?.baseUrl) {
|
else if (args.importer && (args.path.startsWith("./") || args.path.startsWith("../"))) {
|
||||||
|
// Remove fs: prefix from importer if present
|
||||||
|
const importerPath = args.importer.replace(/^fs:/, '');
|
||||||
|
resolved = join(dirname(importerPath), args.path);
|
||||||
|
}
|
||||||
|
// Handle bare imports (e.g., "react", "@scope/package")
|
||||||
|
else if (args.path.match(/^[^./]/)) {
|
||||||
|
// Check if this is a file: dependency
|
||||||
|
const packageName = args.path.startsWith("@")
|
||||||
|
? args.path.split("/").slice(0, 2).join("/")
|
||||||
|
: args.path.split("/")[0];
|
||||||
|
|
||||||
|
const allDeps = {
|
||||||
|
...packageJson?.dependencies,
|
||||||
|
...packageJson?.devDependencies,
|
||||||
|
...packageJson?.peerDependencies,
|
||||||
|
};
|
||||||
|
|
||||||
|
const depVersion = allDeps[packageName];
|
||||||
|
|
||||||
|
if (depVersion && depVersion.startsWith("file:")) {
|
||||||
|
// Extract the file path (e.g., "file:./path" -> "./path")
|
||||||
|
const filePath = depVersion.slice(5); // Remove "file:" prefix
|
||||||
|
const packagePath = join(cwd, filePath);
|
||||||
|
|
||||||
|
// Get the subpath within the package (e.g., "package/subdir/file" -> "/subdir/file")
|
||||||
|
const subpath = args.path.slice(packageName.length);
|
||||||
|
|
||||||
|
resolved = join(packagePath, subpath);
|
||||||
|
} else {
|
||||||
|
return; // Let esmPlugin handle this
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Handle tsconfig baseUrl
|
||||||
|
else if (args.importer && tsconfig?.compilerOptions?.baseUrl) {
|
||||||
resolved = join(cwd, tsconfig.compilerOptions.baseUrl, args.path);
|
resolved = join(cwd, tsconfig.compilerOptions.baseUrl, args.path);
|
||||||
} else {
|
}
|
||||||
|
// Nothing matched, let other plugins handle it
|
||||||
|
else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!resolved) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,8 +165,43 @@ async function tryFileVariants(
|
|||||||
return basePath;
|
return basePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it's a directory, try index files
|
// If it's a directory, try package.json first, then index files
|
||||||
if (stat.isDirectory()) {
|
if (stat.isDirectory()) {
|
||||||
|
// Try to read package.json for entry point
|
||||||
|
try {
|
||||||
|
const packageJsonPath = join(basePath, "package.json");
|
||||||
|
const packageJsonText = await fs.readFile(packageJsonPath, "utf8");
|
||||||
|
const packageJson = JSON.parse(packageJsonText);
|
||||||
|
|
||||||
|
// Check for various entry point fields
|
||||||
|
const entryPoint = packageJson.exports?.['.']
|
||||||
|
|| packageJson.module
|
||||||
|
|| packageJson.main
|
||||||
|
|| 'index.js';
|
||||||
|
|
||||||
|
// Resolve the entry point
|
||||||
|
const entryPath = typeof entryPoint === 'string'
|
||||||
|
? join(basePath, entryPoint)
|
||||||
|
: join(basePath, 'index.js');
|
||||||
|
|
||||||
|
const entryStat = await statSafe(fs, entryPath);
|
||||||
|
if (entryStat.isFile()) {
|
||||||
|
return entryPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try with different extensions if the entry point doesn't exist
|
||||||
|
for (const ext of extensions) {
|
||||||
|
const entryWithExt = entryPath.replace(/\.[^.]+$/, '') + ext;
|
||||||
|
const entryExtStat = await statSafe(fs, entryWithExt);
|
||||||
|
if (entryExtStat.isFile()) {
|
||||||
|
return entryWithExt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// package.json doesn't exist or is invalid, fall through to index files
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fall back to trying index files
|
||||||
for (const ext of extensions) {
|
for (const ext of extensions) {
|
||||||
const indexFile = join(basePath, "index" + ext);
|
const indexFile = join(basePath, "index" + ext);
|
||||||
const indexStat = await statSafe(fs, indexFile);
|
const indexStat = await statSafe(fs, indexFile);
|
||||||
|
|||||||
@@ -535,4 +535,63 @@ react@^18.0.0:
|
|||||||
// Verify tsconfig.json was attempted to be read
|
// Verify tsconfig.json was attempted to be read
|
||||||
expect(mockFS.readFile).toHaveBeenCalledWith('/test/project/tsconfig.json', 'utf8');
|
expect(mockFS.readFile).toHaveBeenCalledWith('/test/project/tsconfig.json', 'utf8');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should support file: dependencies in package.json', async () => {
|
||||||
|
const packageJsonWithFileDeps = JSON.stringify({
|
||||||
|
name: "test-project",
|
||||||
|
dependencies: {
|
||||||
|
"@bitchat/capacitor-ble-mesh": "file:./capacitor-bitchat-mesh",
|
||||||
|
"react": "^18.2.0"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Mock required files
|
||||||
|
vi.mocked(mockFS.readFile)
|
||||||
|
.mockImplementation(async (path: string) => {
|
||||||
|
if (path.endsWith('package.json')) {
|
||||||
|
return packageJsonWithFileDeps;
|
||||||
|
}
|
||||||
|
if (path.endsWith('index.html')) {
|
||||||
|
return '<html><head></head><body><script src="/src/main.tsx"></script></body></html>';
|
||||||
|
}
|
||||||
|
if (path.endsWith('package-lock.json')) {
|
||||||
|
return '{"dependencies": {}}';
|
||||||
|
}
|
||||||
|
throw new Error(`File not found: ${path}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Mock stat to indicate no public directory
|
||||||
|
vi.mocked(mockFS.stat)
|
||||||
|
.mockImplementation(async (path: string) => {
|
||||||
|
if (path === '/test/project/public') {
|
||||||
|
throw new Error('Directory not found');
|
||||||
|
}
|
||||||
|
return { isDirectory: () => false, isFile: () => true };
|
||||||
|
});
|
||||||
|
|
||||||
|
// Mock additional filesystem operations for buildProject
|
||||||
|
vi.mocked(mockFS.readdir).mockImplementation(async (path: string) => {
|
||||||
|
if (path === '/test/project/dist') {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
});
|
||||||
|
|
||||||
|
vi.mocked(mockFS.mkdir).mockResolvedValue(undefined);
|
||||||
|
vi.mocked(mockFS.writeFile).mockResolvedValue(undefined);
|
||||||
|
|
||||||
|
const result = await buildProject({
|
||||||
|
fs: mockFS,
|
||||||
|
projectPath: '/test/project',
|
||||||
|
domParser: mockDOMParser,
|
||||||
|
esmUrl: 'https://esm.shakespeare.diy',
|
||||||
|
});
|
||||||
|
|
||||||
|
// Should successfully build with file: dependencies
|
||||||
|
expect(result.files['stdin-abc123.js']).toEqual(new Uint8Array([1, 2, 3]));
|
||||||
|
expect(result.files['index.html']).toBeDefined();
|
||||||
|
|
||||||
|
// Verify package.json was read
|
||||||
|
expect(mockFS.readFile).toHaveBeenCalledWith('/test/project/package.json', 'utf8');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -130,7 +130,7 @@ async function bundle(
|
|||||||
assetNames: "[name]-[hash]",
|
assetNames: "[name]-[hash]",
|
||||||
plugins: [
|
plugins: [
|
||||||
shakespearePlugin({ esmUrl }),
|
shakespearePlugin({ esmUrl }),
|
||||||
fsPlugin({ fs, cwd: projectPath, tsconfig }),
|
fsPlugin({ fs, cwd: projectPath, tsconfig, packageJson }),
|
||||||
esmPlugin({ packageJson, packageLock, target, esmUrl }),
|
esmPlugin({ packageJson, packageLock, target, esmUrl }),
|
||||||
],
|
],
|
||||||
define: {
|
define: {
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ export class CurlCommand implements ShellCommand {
|
|||||||
|
|
||||||
// Proxy the URL through configured CorsProxy
|
// Proxy the URL through configured CorsProxy
|
||||||
const originalUrl = url.toString();
|
const originalUrl = url.toString();
|
||||||
const proxiedUrl = proxyUrl(this.corsProxy, originalUrl);
|
const proxiedUrl = proxyUrl({ template: this.corsProxy, url: originalUrl });
|
||||||
|
|
||||||
// Prepare request
|
// Prepare request
|
||||||
const requestInit: RequestInit = {
|
const requestInit: RequestInit = {
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ const aiProviderSchema = z.object({
|
|||||||
apiKey: z.string().optional(),
|
apiKey: z.string().optional(),
|
||||||
nostr: z.boolean().optional(),
|
nostr: z.boolean().optional(),
|
||||||
proxy: z.boolean().optional(),
|
proxy: z.boolean().optional(),
|
||||||
|
openSecret: z.string().url().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const providerModelSchema = z.string().regex(
|
const providerModelSchema = z.string().regex(
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ export class CloudflareAdapter implements DeployAdapter {
|
|||||||
|
|
||||||
private async getWorkersSubdomain(): Promise<string> {
|
private async getWorkersSubdomain(): Promise<string> {
|
||||||
const url = `${this.baseURL}/accounts/${this.accountId}/workers/subdomain`;
|
const url = `${this.baseURL}/accounts/${this.accountId}/workers/subdomain`;
|
||||||
const targetUrl = this.corsProxy ? proxyUrl(this.corsProxy, url) : url;
|
const targetUrl = this.corsProxy ? proxyUrl({ template: this.corsProxy, url }) : url;
|
||||||
|
|
||||||
const response = await fetch(targetUrl, {
|
const response = await fetch(targetUrl, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
@@ -160,7 +160,7 @@ export class CloudflareAdapter implements DeployAdapter {
|
|||||||
|
|
||||||
private async enableWorkersDevSubdomain(scriptName: string): Promise<void> {
|
private async enableWorkersDevSubdomain(scriptName: string): Promise<void> {
|
||||||
const url = `${this.baseURL}/accounts/${this.accountId}/workers/scripts/${scriptName}/subdomain`;
|
const url = `${this.baseURL}/accounts/${this.accountId}/workers/scripts/${scriptName}/subdomain`;
|
||||||
const targetUrl = this.corsProxy ? proxyUrl(this.corsProxy, url) : url;
|
const targetUrl = this.corsProxy ? proxyUrl({ template: this.corsProxy, url }) : url;
|
||||||
|
|
||||||
const response = await fetch(targetUrl, {
|
const response = await fetch(targetUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -185,7 +185,7 @@ export class CloudflareAdapter implements DeployAdapter {
|
|||||||
manifest: AssetManifest
|
manifest: AssetManifest
|
||||||
): Promise<InitializeAssetsResponse> {
|
): Promise<InitializeAssetsResponse> {
|
||||||
const url = `${this.baseURL}/accounts/${this.accountId}/workers/scripts/${scriptName}/assets-upload-session`;
|
const url = `${this.baseURL}/accounts/${this.accountId}/workers/scripts/${scriptName}/assets-upload-session`;
|
||||||
const targetUrl = this.corsProxy ? proxyUrl(this.corsProxy, url) : url;
|
const targetUrl = this.corsProxy ? proxyUrl({ template: this.corsProxy, url }) : url;
|
||||||
|
|
||||||
const response = await fetch(targetUrl, {
|
const response = await fetch(targetUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -211,7 +211,7 @@ export class CloudflareAdapter implements DeployAdapter {
|
|||||||
hashToFile: Map<string, { path: string; info: FileInfo }>
|
hashToFile: Map<string, { path: string; info: FileInfo }>
|
||||||
): Promise<UploadResponse> {
|
): Promise<UploadResponse> {
|
||||||
const url = `${this.baseURL}/accounts/${this.accountId}/workers/assets/upload?base64=true`;
|
const url = `${this.baseURL}/accounts/${this.accountId}/workers/assets/upload?base64=true`;
|
||||||
const targetUrl = this.corsProxy ? proxyUrl(this.corsProxy, url) : url;
|
const targetUrl = this.corsProxy ? proxyUrl({ template: this.corsProxy, url }) : url;
|
||||||
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
|
||||||
@@ -251,7 +251,7 @@ export class CloudflareAdapter implements DeployAdapter {
|
|||||||
|
|
||||||
private async deployWorker(scriptName: string, assetsJwt: string): Promise<WorkerScript> {
|
private async deployWorker(scriptName: string, assetsJwt: string): Promise<WorkerScript> {
|
||||||
const url = `${this.baseURL}/accounts/${this.accountId}/workers/scripts/${scriptName}`;
|
const url = `${this.baseURL}/accounts/${this.accountId}/workers/scripts/${scriptName}`;
|
||||||
const targetUrl = this.corsProxy ? proxyUrl(this.corsProxy, url) : url;
|
const targetUrl = this.corsProxy ? proxyUrl({ template: this.corsProxy, url }) : url;
|
||||||
|
|
||||||
// Create a minimal worker script that serves static assets
|
// Create a minimal worker script that serves static assets
|
||||||
// This is an assets-only worker - Cloudflare will automatically serve the uploaded assets
|
// This is an assets-only worker - Cloudflare will automatically serve the uploaded assets
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ export class DenoDeployAdapter implements DeployAdapter {
|
|||||||
|
|
||||||
private async findProject(projectName: string): Promise<Project | null> {
|
private async findProject(projectName: string): Promise<Project | null> {
|
||||||
const url = `${this.baseURL}/organizations/${this.organizationId}/projects?q=${encodeURIComponent(projectName)}`;
|
const url = `${this.baseURL}/organizations/${this.organizationId}/projects?q=${encodeURIComponent(projectName)}`;
|
||||||
const targetUrl = this.corsProxy ? proxyUrl(this.corsProxy, url) : url;
|
const targetUrl = this.corsProxy ? proxyUrl({ template: this.corsProxy, url }) : url;
|
||||||
|
|
||||||
const response = await fetch(targetUrl, {
|
const response = await fetch(targetUrl, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
@@ -116,7 +116,7 @@ export class DenoDeployAdapter implements DeployAdapter {
|
|||||||
|
|
||||||
private async createProject(projectName: string): Promise<Project> {
|
private async createProject(projectName: string): Promise<Project> {
|
||||||
const url = `${this.baseURL}/organizations/${this.organizationId}/projects`;
|
const url = `${this.baseURL}/organizations/${this.organizationId}/projects`;
|
||||||
const targetUrl = this.corsProxy ? proxyUrl(this.corsProxy, url) : url;
|
const targetUrl = this.corsProxy ? proxyUrl({ template: this.corsProxy, url }) : url;
|
||||||
|
|
||||||
const response = await fetch(targetUrl, {
|
const response = await fetch(targetUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -143,7 +143,7 @@ export class DenoDeployAdapter implements DeployAdapter {
|
|||||||
domain: string
|
domain: string
|
||||||
): Promise<Deployment> {
|
): Promise<Deployment> {
|
||||||
const url = `${this.baseURL}/projects/${projectId}/deployments`;
|
const url = `${this.baseURL}/projects/${projectId}/deployments`;
|
||||||
const targetUrl = this.corsProxy ? proxyUrl(this.corsProxy, url) : url;
|
const targetUrl = this.corsProxy ? proxyUrl({ template: this.corsProxy, url }) : url;
|
||||||
|
|
||||||
// Create a minimal server script that serves static files
|
// Create a minimal server script that serves static files
|
||||||
// For static sites, we use a simple file server entry point
|
// For static sites, we use a simple file server entry point
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ export class NetlifyAdapter implements DeployAdapter {
|
|||||||
|
|
||||||
private async createSite(name: string): Promise<NetlifySite> {
|
private async createSite(name: string): Promise<NetlifySite> {
|
||||||
const url = `${this.baseURL}/sites`;
|
const url = `${this.baseURL}/sites`;
|
||||||
const targetUrl = this.corsProxy ? proxyUrl(this.corsProxy, url) : url;
|
const targetUrl = this.corsProxy ? proxyUrl({ template: this.corsProxy, url }) : url;
|
||||||
|
|
||||||
const response = await fetch(targetUrl, {
|
const response = await fetch(targetUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -113,7 +113,7 @@ export class NetlifyAdapter implements DeployAdapter {
|
|||||||
|
|
||||||
private async getSite(siteId: string): Promise<NetlifySite> {
|
private async getSite(siteId: string): Promise<NetlifySite> {
|
||||||
const url = `${this.baseURL}/sites/${siteId}`;
|
const url = `${this.baseURL}/sites/${siteId}`;
|
||||||
const targetUrl = this.corsProxy ? proxyUrl(this.corsProxy, url) : url;
|
const targetUrl = this.corsProxy ? proxyUrl({ template: this.corsProxy, url }) : url;
|
||||||
|
|
||||||
const response = await fetch(targetUrl, {
|
const response = await fetch(targetUrl, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
@@ -132,7 +132,7 @@ export class NetlifyAdapter implements DeployAdapter {
|
|||||||
|
|
||||||
private async triggerDeploy(siteId: string, zipBlob: Blob): Promise<NetlifyBuildResponse> {
|
private async triggerDeploy(siteId: string, zipBlob: Blob): Promise<NetlifyBuildResponse> {
|
||||||
const url = `${this.baseURL}/sites/${siteId}/deploys`;
|
const url = `${this.baseURL}/sites/${siteId}/deploys`;
|
||||||
const targetUrl = this.corsProxy ? proxyUrl(this.corsProxy, url) : url;
|
const targetUrl = this.corsProxy ? proxyUrl({ template: this.corsProxy, url }) : url;
|
||||||
|
|
||||||
const response = await fetch(targetUrl, {
|
const response = await fetch(targetUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ export class ShakespeareAdapter implements DeployAdapter {
|
|||||||
|
|
||||||
// Apply proxy if configured
|
// Apply proxy if configured
|
||||||
if (this.corsProxy) {
|
if (this.corsProxy) {
|
||||||
request = new Request(proxyUrl(this.corsProxy, request.url), request);
|
request = new Request(proxyUrl({ template: this.corsProxy, url: request.url }), request);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deploy
|
// Deploy
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ export class VercelAdapter implements DeployAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Apply proxy if configured
|
// Apply proxy if configured
|
||||||
const targetUrl = this.corsProxy ? proxyUrl(this.corsProxy, apiUrl) : apiUrl;
|
const targetUrl = this.corsProxy ? proxyUrl({ template: this.corsProxy, url: apiUrl }) : apiUrl;
|
||||||
|
|
||||||
// Deploy to Vercel
|
// Deploy to Vercel
|
||||||
const response = await fetch(targetUrl, {
|
const response = await fetch(targetUrl, {
|
||||||
|
|||||||
+11
-5
@@ -1,15 +1,21 @@
|
|||||||
import UriTemplate from 'uri-templates';
|
import UriTemplate from 'uri-templates';
|
||||||
|
|
||||||
|
export interface FaviconUrlOpts {
|
||||||
|
template: string;
|
||||||
|
url: string | URL;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a favicon URL from a template and input URL
|
* Generate a favicon URL from a template and input URL
|
||||||
* @param template - URL template with placeholders like {hostname}, {origin}, etc.
|
* @param opts - Options object
|
||||||
* @param url - The URL to extract parts from
|
* @param opts.template - URL template with placeholders like {hostname}, {origin}, etc.
|
||||||
|
* @param opts.url - The URL to extract parts from
|
||||||
* @returns The hydrated favicon URL
|
* @returns The hydrated favicon URL
|
||||||
*/
|
*/
|
||||||
export function faviconUrl(template: string, url: string | URL): string {
|
export function faviconUrl(opts: FaviconUrlOpts): string {
|
||||||
const u = new URL(url);
|
const u = new URL(opts.url);
|
||||||
|
|
||||||
return UriTemplate(template).fill({
|
return UriTemplate(opts.template).fill({
|
||||||
href: u.href,
|
href: u.href,
|
||||||
origin: u.origin,
|
origin: u.origin,
|
||||||
protocol: u.protocol,
|
protocol: u.protocol,
|
||||||
|
|||||||
+1
-1
@@ -1115,7 +1115,7 @@ class GitHttp implements HttpClient {
|
|||||||
const url = new URL(request.url);
|
const url = new URL(request.url);
|
||||||
|
|
||||||
const target = this.proxy
|
const target = this.proxy
|
||||||
? proxyUrl(this.proxy, url)
|
? proxyUrl({ template: this.proxy, url })
|
||||||
: url.href;
|
: url.href;
|
||||||
|
|
||||||
const init: RequestInit = {
|
const init: RequestInit = {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ describe('ngitWebUrl', () => {
|
|||||||
const identifier = 'my-repo';
|
const identifier = 'my-repo';
|
||||||
const nostrURI = new NostrURI({ pubkey, identifier });
|
const nostrURI = new NostrURI({ pubkey, identifier });
|
||||||
|
|
||||||
const result = ngitWebUrl(template, nostrURI);
|
const result = ngitWebUrl({ template, nostrURI });
|
||||||
|
|
||||||
expect(result).toMatch(/^https:\/\/nostrhub\.io\/naddr1/);
|
expect(result).toMatch(/^https:\/\/nostrhub\.io\/naddr1/);
|
||||||
});
|
});
|
||||||
@@ -20,7 +20,7 @@ describe('ngitWebUrl', () => {
|
|||||||
const identifier = 'my-repo';
|
const identifier = 'my-repo';
|
||||||
const nostrURI = new NostrURI({ pubkey, identifier });
|
const nostrURI = new NostrURI({ pubkey, identifier });
|
||||||
|
|
||||||
const result = ngitWebUrl(template, nostrURI);
|
const result = ngitWebUrl({ template, nostrURI });
|
||||||
|
|
||||||
expect(result).toMatch(/^https:\/\/example\.com\/npub1/);
|
expect(result).toMatch(/^https:\/\/example\.com\/npub1/);
|
||||||
});
|
});
|
||||||
@@ -31,7 +31,7 @@ describe('ngitWebUrl', () => {
|
|||||||
const identifier = 'my-repo';
|
const identifier = 'my-repo';
|
||||||
const nostrURI = new NostrURI({ pubkey, identifier });
|
const nostrURI = new NostrURI({ pubkey, identifier });
|
||||||
|
|
||||||
const result = ngitWebUrl(template, nostrURI);
|
const result = ngitWebUrl({ template, nostrURI });
|
||||||
|
|
||||||
expect(result).toBe(`https://example.com/${pubkey}`);
|
expect(result).toBe(`https://example.com/${pubkey}`);
|
||||||
});
|
});
|
||||||
@@ -42,7 +42,7 @@ describe('ngitWebUrl', () => {
|
|||||||
const identifier = 'my-repo';
|
const identifier = 'my-repo';
|
||||||
const nostrURI = new NostrURI({ pubkey, identifier });
|
const nostrURI = new NostrURI({ pubkey, identifier });
|
||||||
|
|
||||||
const result = ngitWebUrl(template, nostrURI);
|
const result = ngitWebUrl({ template, nostrURI });
|
||||||
|
|
||||||
expect(result).toBe('https://example.com/my-repo');
|
expect(result).toBe('https://example.com/my-repo');
|
||||||
});
|
});
|
||||||
@@ -53,7 +53,7 @@ describe('ngitWebUrl', () => {
|
|||||||
const identifier = 'my-repo';
|
const identifier = 'my-repo';
|
||||||
const nostrURI = new NostrURI({ pubkey, identifier });
|
const nostrURI = new NostrURI({ pubkey, identifier });
|
||||||
|
|
||||||
const result = ngitWebUrl(template, nostrURI);
|
const result = ngitWebUrl({ template, nostrURI });
|
||||||
|
|
||||||
expect(result).toMatch(/^https:\/\/example\.com\/npub1[^/]+\/my-repo$/);
|
expect(result).toMatch(/^https:\/\/example\.com\/npub1[^/]+\/my-repo$/);
|
||||||
});
|
});
|
||||||
@@ -65,7 +65,7 @@ describe('ngitWebUrl', () => {
|
|||||||
const relay = 'wss://relay.example.com/';
|
const relay = 'wss://relay.example.com/';
|
||||||
const nostrURI = new NostrURI({ pubkey, identifier, relay });
|
const nostrURI = new NostrURI({ pubkey, identifier, relay });
|
||||||
|
|
||||||
const result = ngitWebUrl(template, nostrURI);
|
const result = ngitWebUrl({ template, nostrURI });
|
||||||
|
|
||||||
// The naddr should be longer when it includes relay information
|
// The naddr should be longer when it includes relay information
|
||||||
expect(result).toMatch(/^https:\/\/nostrhub\.io\/naddr1/);
|
expect(result).toMatch(/^https:\/\/nostrhub\.io\/naddr1/);
|
||||||
|
|||||||
+14
-8
@@ -2,20 +2,26 @@ import UriTemplate from 'uri-templates';
|
|||||||
import { nip19 } from 'nostr-tools';
|
import { nip19 } from 'nostr-tools';
|
||||||
import { NostrURI } from './NostrURI';
|
import { NostrURI } from './NostrURI';
|
||||||
|
|
||||||
|
export interface NgitWebUrlOpts {
|
||||||
|
template: string;
|
||||||
|
nostrURI: NostrURI;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a Nostr Git web URL from a template and Nostr URI
|
* Generate a Nostr Git web URL from a template and Nostr URI
|
||||||
* @param template - URL template with placeholders like {naddr}, {npub}, {pubkey}, {identifier}
|
* @param opts - Options object
|
||||||
* @param nostrURI - The Nostr URI containing pubkey, identifier, and optional relay
|
* @param opts.template - URL template with placeholders like {naddr}, {npub}, {pubkey}, {identifier}
|
||||||
|
* @param opts.nostrURI - The Nostr URI containing pubkey, identifier, and optional relay
|
||||||
* @returns The hydrated web URL
|
* @returns The hydrated web URL
|
||||||
*/
|
*/
|
||||||
export function ngitWebUrl(template: string, nostrURI: NostrURI): string {
|
export function ngitWebUrl(opts: NgitWebUrlOpts): string {
|
||||||
const naddr = nostrURI.toNaddr();
|
const naddr = opts.nostrURI.toNaddr();
|
||||||
const npub = nip19.npubEncode(nostrURI.pubkey);
|
const npub = nip19.npubEncode(opts.nostrURI.pubkey);
|
||||||
|
|
||||||
return UriTemplate(template).fill({
|
return UriTemplate(opts.template).fill({
|
||||||
naddr,
|
naddr,
|
||||||
npub,
|
npub,
|
||||||
pubkey: nostrURI.pubkey,
|
pubkey: opts.nostrURI.pubkey,
|
||||||
identifier: nostrURI.identifier,
|
identifier: opts.nostrURI.identifier,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
+8
-3
@@ -1,8 +1,13 @@
|
|||||||
import UriTemplate from 'uri-templates';
|
import UriTemplate from 'uri-templates';
|
||||||
|
|
||||||
export function proxyUrl(template: string, url: string | URL): string {
|
export interface ProxyUrlOpts {
|
||||||
const u = new URL(url);
|
template: string;
|
||||||
return UriTemplate(template).fill({
|
url: string | URL;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function proxyUrl(opts: ProxyUrlOpts): string {
|
||||||
|
const u = new URL(opts.url);
|
||||||
|
return UriTemplate(opts.template).fill({
|
||||||
href: u.href,
|
href: u.href,
|
||||||
origin: u.origin,
|
origin: u.origin,
|
||||||
protocol: u.protocol,
|
protocol: u.protocol,
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ export class GenerateImageTool implements Tool<GenerateImageParams> {
|
|||||||
}
|
}
|
||||||
} else if (firstImage.url) {
|
} else if (firstImage.url) {
|
||||||
// Fetch the image from the URL
|
// Fetch the image from the URL
|
||||||
const imageUrl = this.corsProxy ? proxyUrl(this.corsProxy, firstImage.url) : firstImage.url;
|
const imageUrl = this.corsProxy ? proxyUrl({ template: this.corsProxy, url: firstImage.url }) : firstImage.url;
|
||||||
const imageResponse = await fetch(imageUrl);
|
const imageResponse = await fetch(imageUrl);
|
||||||
|
|
||||||
if (!imageResponse.ok) {
|
if (!imageResponse.ok) {
|
||||||
|
|||||||
+5
-18
@@ -54,12 +54,9 @@
|
|||||||
"showcaseModerator": "Showcase Moderator",
|
"showcaseModerator": "Showcase Moderator",
|
||||||
"showcaseModeratorDescription": "Nostr public key (npub) of the user who can moderate showcase submissions",
|
"showcaseModeratorDescription": "Nostr public key (npub) of the user who can moderate showcase submissions",
|
||||||
"filesystemPaths": "Filesystem Paths",
|
"filesystemPaths": "Filesystem Paths",
|
||||||
"projectsDirectory": "Projects Directory",
|
"projectsDirectory": "Projects",
|
||||||
"projectsDirectoryDescription": "Filesystem path where projects are stored",
|
"configDirectory": "Config",
|
||||||
"configDirectory": "Config Directory",
|
"temporaryDirectory": "Temporary",
|
||||||
"configDirectoryDescription": "Filesystem path where configuration files are stored",
|
|
||||||
"temporaryDirectory": "Temporary Directory",
|
|
||||||
"temporaryDirectoryDescription": "Filesystem path for temporary files",
|
|
||||||
"sentryDsn": "Sentry DSN",
|
"sentryDsn": "Sentry DSN",
|
||||||
"sentryDsnDescription": "Sentry Data Source Name (DSN) for error reporting. Leave empty to disable Sentry.",
|
"sentryDsnDescription": "Sentry Data Source Name (DSN) for error reporting. Leave empty to disable Sentry.",
|
||||||
"shareErrorReports": "Share error reports",
|
"shareErrorReports": "Share error reports",
|
||||||
@@ -484,8 +481,7 @@
|
|||||||
"skills": "Skills",
|
"skills": "Skills",
|
||||||
"noSkillsFound": "No skills found in this plugin.",
|
"noSkillsFound": "No skills found in this plugin.",
|
||||||
"noPluginsConfigured": "No plugins configured. Add a plugin to get started.",
|
"noPluginsConfigured": "No plugins configured. Add a plugin to get started.",
|
||||||
"pluginsDirectory": "Plugins Directory",
|
"pluginsDirectory": "Plugins",
|
||||||
"pluginsDirectoryDescription": "Directory where plugins are stored in the virtual filesystem.",
|
|
||||||
"discoverPlugins": "Discover Plugins",
|
"discoverPlugins": "Discover Plugins",
|
||||||
"discoverPluginsDescription": "Browse and install Shakespeare plugins shared on the Nostr network.",
|
"discoverPluginsDescription": "Browse and install Shakespeare plugins shared on the Nostr network.",
|
||||||
"searchPlugins": "Search plugins...",
|
"searchPlugins": "Search plugins...",
|
||||||
@@ -526,21 +522,12 @@
|
|||||||
"discoveringTools": "Discovering tools...",
|
"discoveringTools": "Discovering tools...",
|
||||||
"toolsDiscovered": "{{count}} tool(s) discovered",
|
"toolsDiscovered": "{{count}} tool(s) discovered",
|
||||||
"toolDiscoveryFailed": "Failed to discover tools from this server",
|
"toolDiscoveryFailed": "Failed to discover tools from this server",
|
||||||
"filesystemPaths": "Filesystem Paths",
|
|
||||||
"projectsDirectory": "Projects Directory",
|
|
||||||
"projectsDirectoryDescription": "Directory where projects are stored in the virtual filesystem.",
|
|
||||||
"configDirectory": "Config Directory",
|
|
||||||
"configDirectoryDescription": "Directory where configuration files are stored in the virtual filesystem.",
|
|
||||||
"temporaryDirectory": "Temporary Directory",
|
|
||||||
"temporaryDirectoryDescription": "Directory for temporary files in the virtual filesystem.",
|
|
||||||
"deleting": "Deleting...",
|
"deleting": "Deleting...",
|
||||||
"modified": "Modified",
|
|
||||||
"restoreToDefault": "Restore to default",
|
"restoreToDefault": "Restore to default",
|
||||||
"restoredToDefault": "Restored to Default",
|
"restoredToDefault": "Restored to Default",
|
||||||
"templateUpdateFailed": "Template Update Failed",
|
"templateUpdateFailed": "Template Update Failed",
|
||||||
"templateUpdateFailedDescription": "Failed to update the project template from the remote repository. Using the cached version instead.",
|
"templateUpdateFailedDescription": "Failed to update the project template from the remote repository. Using the cached version instead.",
|
||||||
"templatesDirectory": "Templates Directory",
|
"templatesDirectory": "Templates",
|
||||||
"templatesDirectoryDescription": "Directory where project templates are cached in the virtual filesystem.",
|
|
||||||
"terminal": "Terminal",
|
"terminal": "Terminal",
|
||||||
"templateName": "Template Name",
|
"templateName": "Template Name",
|
||||||
"templateDescription": "Description",
|
"templateDescription": "Description",
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import { CreditsBadge } from '@/components/CreditsBadge';
|
|||||||
import { useAISettings } from '@/hooks/useAISettings';
|
import { useAISettings } from '@/hooks/useAISettings';
|
||||||
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
||||||
import { useAppContext } from '@/hooks/useAppContext';
|
import { useAppContext } from '@/hooks/useAppContext';
|
||||||
|
import { useOpenRouterOAuth } from '@/hooks/useOpenRouterOAuth';
|
||||||
import { SettingsPageLayout } from '@/components/SettingsPageLayout';
|
import { SettingsPageLayout } from '@/components/SettingsPageLayout';
|
||||||
import type { AIProvider } from '@/contexts/AISettingsContext';
|
import type { AIProvider } from '@/contexts/AISettingsContext';
|
||||||
import { AI_PROVIDER_PRESETS, type PresetProvider } from '@/lib/aiProviderPresets';
|
import { AI_PROVIDER_PRESETS, type PresetProvider } from '@/lib/aiProviderPresets';
|
||||||
@@ -45,6 +46,7 @@ export function AISettings() {
|
|||||||
const { settings, updateSettings, setProvider, removeProvider, setProviders, isLoading } = useAISettings();
|
const { settings, updateSettings, setProvider, removeProvider, setProviders, isLoading } = useAISettings();
|
||||||
const { user } = useCurrentUser();
|
const { user } = useCurrentUser();
|
||||||
const { config, defaultConfig, updateConfig } = useAppContext();
|
const { config, defaultConfig, updateConfig } = useAppContext();
|
||||||
|
const openRouterOAuth = useOpenRouterOAuth();
|
||||||
const [showAdvanced, setShowAdvanced] = useState(false);
|
const [showAdvanced, setShowAdvanced] = useState(false);
|
||||||
const [systemPromptInput, setSystemPromptInput] = useState(config.systemPrompt || defaultSystemPrompt);
|
const [systemPromptInput, setSystemPromptInput] = useState(config.systemPrompt || defaultSystemPrompt);
|
||||||
|
|
||||||
@@ -54,6 +56,7 @@ export function AISettings() {
|
|||||||
const [selectedPreset, setSelectedPreset] = useState<PresetProvider | null>(null);
|
const [selectedPreset, setSelectedPreset] = useState<PresetProvider | null>(null);
|
||||||
const [addDialogOpen, setAddDialogOpen] = useState(false);
|
const [addDialogOpen, setAddDialogOpen] = useState(false);
|
||||||
const [customProviderDialogOpen, setCustomProviderDialogOpen] = useState(false);
|
const [customProviderDialogOpen, setCustomProviderDialogOpen] = useState(false);
|
||||||
|
const [forceManualEntry, setForceManualEntry] = useState(false);
|
||||||
|
|
||||||
// Drag and drop sensors
|
// Drag and drop sensors
|
||||||
const sensors = useSensors(
|
const sensors = useSensors(
|
||||||
@@ -115,6 +118,9 @@ export function AISettings() {
|
|||||||
if (typeof preset.proxy === 'boolean') {
|
if (typeof preset.proxy === 'boolean') {
|
||||||
newProvider.proxy = preset.proxy;
|
newProvider.proxy = preset.proxy;
|
||||||
}
|
}
|
||||||
|
if (preset.openSecret) {
|
||||||
|
newProvider.openSecret = preset.openSecret;
|
||||||
|
}
|
||||||
|
|
||||||
setProvider(newProvider);
|
setProvider(newProvider);
|
||||||
};
|
};
|
||||||
@@ -256,9 +262,18 @@ export function AISettings() {
|
|||||||
{selectedPreset && (
|
{selectedPreset && (
|
||||||
<AddAIProviderDialog
|
<AddAIProviderDialog
|
||||||
open={addDialogOpen}
|
open={addDialogOpen}
|
||||||
onOpenChange={setAddDialogOpen}
|
onOpenChange={(open) => {
|
||||||
|
setAddDialogOpen(open);
|
||||||
|
if (!open) {
|
||||||
|
// Reset force manual entry when dialog closes
|
||||||
|
setForceManualEntry(false);
|
||||||
|
}
|
||||||
|
}}
|
||||||
preset={selectedPreset}
|
preset={selectedPreset}
|
||||||
isLoggedIntoNostr={!!user}
|
isLoggedIntoNostr={!!user}
|
||||||
|
oauthHook={selectedPreset.id === 'openrouter' ? openRouterOAuth : null}
|
||||||
|
forceManualEntry={forceManualEntry}
|
||||||
|
onSetForceManualEntry={setForceManualEntry}
|
||||||
onAdd={(apiKey) => handleAddPresetProvider(selectedPreset, apiKey)}
|
onAdd={(apiKey) => handleAddPresetProvider(selectedPreset, apiKey)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import type { PresetDeployProvider } from '@/lib/deploy/types';
|
|||||||
import { PRESET_DEPLOY_PROVIDERS } from '@/lib/deployProviderPresets';
|
import { PRESET_DEPLOY_PROVIDERS } from '@/lib/deployProviderPresets';
|
||||||
import { ExternalFavicon } from '@/components/ExternalFavicon';
|
import { ExternalFavicon } from '@/components/ExternalFavicon';
|
||||||
import { ProviderConfigDialog } from '@/components/ProviderConfigDialog';
|
import { ProviderConfigDialog } from '@/components/ProviderConfigDialog';
|
||||||
import { AddProviderDialog } from '@/components/AddProviderDialog';
|
import { AddDeployProviderDialog } from '@/components/AddDeployProviderDialog';
|
||||||
import { AddCustomProviderDialog } from '@/components/AddCustomProviderDialog';
|
import { AddCustomProviderDialog } from '@/components/AddCustomProviderDialog';
|
||||||
import {
|
import {
|
||||||
DndContext,
|
DndContext,
|
||||||
@@ -384,7 +384,7 @@ export function DeploySettings() {
|
|||||||
|
|
||||||
{/* Add Preset Provider Dialog */}
|
{/* Add Preset Provider Dialog */}
|
||||||
{selectedPreset && (
|
{selectedPreset && (
|
||||||
<AddProviderDialog
|
<AddDeployProviderDialog
|
||||||
open={addDialogOpen}
|
open={addDialogOpen}
|
||||||
onOpenChange={setAddDialogOpen}
|
onOpenChange={setAddDialogOpen}
|
||||||
preset={selectedPreset}
|
preset={selectedPreset}
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
import { useEffect } from 'react';
|
||||||
|
import { useSearchParams, useNavigate } from 'react-router-dom';
|
||||||
|
import { useOpenRouterOAuth } from '@/hooks/useOpenRouterOAuth';
|
||||||
|
import { useAISettings } from '@/hooks/useAISettings';
|
||||||
|
import { useToast } from '@/hooks/useToast';
|
||||||
|
import { Card, CardContent } from '@/components/ui/card';
|
||||||
|
import { Bot } from 'lucide-react';
|
||||||
|
|
||||||
|
export default function OpenRouterOAuth() {
|
||||||
|
const [searchParams] = useSearchParams();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const { handleCallback } = useOpenRouterOAuth();
|
||||||
|
const { isLoading: isSettingsLoading } = useAISettings();
|
||||||
|
const { toast } = useToast();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// Wait for AI settings to be initialized
|
||||||
|
if (isSettingsLoading) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const code = searchParams.get('code');
|
||||||
|
const state = searchParams.get('state');
|
||||||
|
const error = searchParams.get('error');
|
||||||
|
const errorDescription = searchParams.get('error_description');
|
||||||
|
const storedCodeVerifier = localStorage.getItem('openrouter_oauth_code_verifier');
|
||||||
|
|
||||||
|
// Handle OAuth errors
|
||||||
|
if (error) {
|
||||||
|
toast({
|
||||||
|
title: "OpenRouter OAuth Error",
|
||||||
|
description: errorDescription || error,
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
|
navigate('/settings/ai');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle successful OAuth callback
|
||||||
|
if (code && storedCodeVerifier) {
|
||||||
|
handleCallback(code, state || '').then((success) => {
|
||||||
|
if (success) {
|
||||||
|
toast({
|
||||||
|
title: "OpenRouter Connected",
|
||||||
|
description: "Successfully connected to OpenRouter. You can now use OpenRouter models.",
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
toast({
|
||||||
|
title: "Connection Failed",
|
||||||
|
description: "Failed to connect to OpenRouter. Please try again.",
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// Always redirect to AI settings after handling the callback
|
||||||
|
navigate('/settings/ai');
|
||||||
|
});
|
||||||
|
} else if (code && !storedCodeVerifier) {
|
||||||
|
// Missing code verifier - likely an incomplete PKCE flow
|
||||||
|
toast({
|
||||||
|
title: "Authentication Error",
|
||||||
|
description: "OAuth flow is incomplete. Please try connecting to OpenRouter again.",
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
|
// Clean up any remaining OAuth data
|
||||||
|
localStorage.removeItem('openrouter_oauth_state');
|
||||||
|
localStorage.removeItem('openrouter_oauth_code_verifier');
|
||||||
|
navigate('/settings/ai');
|
||||||
|
} else {
|
||||||
|
// No code parameter - redirect to AI settings
|
||||||
|
navigate('/settings/ai');
|
||||||
|
}
|
||||||
|
}, [searchParams, handleCallback, toast, navigate, isSettingsLoading]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="min-h-screen flex items-center justify-center p-4">
|
||||||
|
<Card className="w-full max-w-md">
|
||||||
|
<CardContent className="py-12 px-8 text-center">
|
||||||
|
<div className="space-y-6">
|
||||||
|
<div className="flex justify-center">
|
||||||
|
<Bot className="h-12 w-12 text-primary" />
|
||||||
|
</div>
|
||||||
|
<div className="space-y-2">
|
||||||
|
<h1 className="text-xl font-semibold">Connecting to OpenRouter</h1>
|
||||||
|
<p className="text-muted-foreground">
|
||||||
|
Processing your OpenRouter authentication...
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="flex justify-center">
|
||||||
|
<div className="animate-spin rounded-full h-6 w-6 border-b-2 border-primary"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
+197
-97
@@ -31,6 +31,9 @@ import { useGitAutosync } from '@/hooks/useGitAutosync';
|
|||||||
import { useQueryClient } from '@tanstack/react-query';
|
import { useQueryClient } from '@tanstack/react-query';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
import { useProjectSessionStatus } from '@/hooks/useProjectSessionStatus';
|
import { useProjectSessionStatus } from '@/hooks/useProjectSessionStatus';
|
||||||
|
import { useLocalStorage } from '@/hooks/useLocalStorage';
|
||||||
|
import { FloatingChatWidget } from '@/components/Shakespeare/FloatingChatWidget';
|
||||||
|
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
|
||||||
|
|
||||||
export function ProjectView() {
|
export function ProjectView() {
|
||||||
const { projectId } = useParams<{ projectId: string }>();
|
const { projectId } = useParams<{ projectId: string }>();
|
||||||
@@ -59,6 +62,16 @@ export function ProjectView() {
|
|||||||
|
|
||||||
const [isSidebarVisible, setIsSidebarVisible] = useState(!isMobile);
|
const [isSidebarVisible, setIsSidebarVisible] = useState(!isMobile);
|
||||||
|
|
||||||
|
// Floating chat state
|
||||||
|
const [isFloatingChatEnabled, setIsFloatingChatEnabled] = useLocalStorage(
|
||||||
|
'shk:floatingChatEnabled',
|
||||||
|
false
|
||||||
|
);
|
||||||
|
const [isFloatingChatMinimized, setIsFloatingChatMinimized] = useLocalStorage(
|
||||||
|
'shk:floatingChatMinimized',
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
const build = useBuildProject(projectId!);
|
const build = useBuildProject(projectId!);
|
||||||
const { data: isPreviewable = false } = useIsProjectPreviewable(projectId!);
|
const { data: isPreviewable = false } = useIsProjectPreviewable(projectId!);
|
||||||
const { hasRunningSessions } = useProjectSessionStatus(projectId || '');
|
const { hasRunningSessions } = useProjectSessionStatus(projectId || '');
|
||||||
@@ -227,7 +240,7 @@ export function ProjectView() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center gap-4 px-3">
|
<div className="flex items-center gap-2 px-3">
|
||||||
{project ? (
|
{project ? (
|
||||||
<>
|
<>
|
||||||
<GitSyncButton
|
<GitSyncButton
|
||||||
@@ -239,6 +252,24 @@ export function ProjectView() {
|
|||||||
projectName={project.name}
|
projectName={project.name}
|
||||||
disabled={isAnyLoading}
|
disabled={isAnyLoading}
|
||||||
/>
|
/>
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="h-8 w-8"
|
||||||
|
onClick={() => {
|
||||||
|
setIsFloatingChatEnabled(true);
|
||||||
|
setIsFloatingChatMinimized(false);
|
||||||
|
}}
|
||||||
|
aria-label="Floating chat"
|
||||||
|
aria-pressed={isFloatingChatEnabled}
|
||||||
|
>
|
||||||
|
<MessageSquare className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent>Floating chat</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
@@ -389,6 +420,23 @@ export function ProjectView() {
|
|||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* Floating Chat Widget - Mobile */}
|
||||||
|
{isFloatingChatEnabled && project && (
|
||||||
|
<FloatingChatWidget
|
||||||
|
projectId={project.id}
|
||||||
|
isMinimized={isFloatingChatMinimized}
|
||||||
|
onToggleMinimize={() => setIsFloatingChatMinimized(!isFloatingChatMinimized)}
|
||||||
|
onClose={() => setIsFloatingChatEnabled(false)}
|
||||||
|
onNewChat={handleNewChat}
|
||||||
|
onFirstInteraction={handleFirstInteraction}
|
||||||
|
onLoadingChange={handleAILoadingChange}
|
||||||
|
isLoading={isAILoading}
|
||||||
|
isBuildLoading={build.isPending}
|
||||||
|
consoleError={consoleError}
|
||||||
|
onDismissConsoleError={handleDismissConsoleError}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -415,123 +463,175 @@ export function ProjectView() {
|
|||||||
{/* Main Content Area */}
|
{/* Main Content Area */}
|
||||||
<div className="flex-1 flex flex-col overflow-hidden bg-background">
|
<div className="flex-1 flex flex-col overflow-hidden bg-background">
|
||||||
<div className="flex-1 overflow-hidden">
|
<div className="flex-1 overflow-hidden">
|
||||||
<ResizablePanelGroup direction="horizontal" className="h-full">
|
{isFloatingChatEnabled ? (
|
||||||
{/* Chat Panel */}
|
// Full-width preview/code when floating chat is enabled
|
||||||
<ResizablePanel defaultSize={35} minSize={25}>
|
<div className="h-full">
|
||||||
<div className="h-full flex flex-col">
|
{project ? (
|
||||||
{/* Chat Header */}
|
<PreviewPane
|
||||||
<div className="h-12 px-4 border-b flex-shrink-0">
|
projectId={project.id}
|
||||||
<div className="flex items-center justify-between h-12">
|
activeTab={isPreviewable ? activeTab : 'code'}
|
||||||
{/* Left side - Sidebar toggle (when collapsed) */}
|
onToggleView={isPreviewable ? () => setActiveTab(activeTab === 'preview' ? 'code' : 'preview') : undefined}
|
||||||
<div className="flex items-center gap-3 overflow-hidden">
|
isPreviewable={isPreviewable}
|
||||||
{!isSidebarVisible && (
|
/>
|
||||||
<Button
|
) : (
|
||||||
variant="ghost"
|
<div className="h-full p-4 space-y-4">
|
||||||
size="sm"
|
<Skeleton className="h-8 w-32" />
|
||||||
onClick={() => setIsSidebarVisible(true)}
|
<Skeleton className="h-full w-full" />
|
||||||
className="h-8 w-8 p-0"
|
</div>
|
||||||
aria-label="Open sidebar"
|
)}
|
||||||
>
|
</div>
|
||||||
<Menu className="h-4 w-4" />
|
) : (
|
||||||
</Button>
|
// Original resizable panel layout
|
||||||
)}
|
<ResizablePanelGroup direction="horizontal" className="h-full">
|
||||||
|
{/* Chat Panel */}
|
||||||
|
<ResizablePanel defaultSize={35} minSize={25}>
|
||||||
|
<div className="h-full flex flex-col">
|
||||||
|
{/* Chat Header */}
|
||||||
|
<div className="h-12 px-4 border-b flex-shrink-0">
|
||||||
|
<div className="flex items-center justify-between h-12">
|
||||||
|
{/* Left side - Sidebar toggle (when collapsed) */}
|
||||||
|
<div className="flex items-center gap-3 overflow-hidden">
|
||||||
|
{!isSidebarVisible && (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => setIsSidebarVisible(true)}
|
||||||
|
className="h-8 w-8 p-0"
|
||||||
|
aria-label="Open sidebar"
|
||||||
|
>
|
||||||
|
<Menu className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Project title */}
|
{/* Project title */}
|
||||||
<div className="flex flex-1 min-w-0 truncate">
|
<div className="flex flex-1 min-w-0 truncate">
|
||||||
|
{project ? (
|
||||||
|
<ProjectTitleMenu
|
||||||
|
projectId={project.id}
|
||||||
|
projectName={project.name}
|
||||||
|
onNewChat={handleNewChat}
|
||||||
|
onGitHistory={() => setGitHistoryOpen(true)}
|
||||||
|
onDuplicate={() => setDuplicateDialogOpen(true)}
|
||||||
|
onDelete={() => setDeleteDialogOpen(true)}
|
||||||
|
onProjectDetails={() => setIsProjectDetailsOpen(true)}
|
||||||
|
isAILoading={isAILoading}
|
||||||
|
isAnyLoading={isAnyLoading || isDeleting}
|
||||||
|
className="text-lg"
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<Skeleton className="h-6 w-40" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Right side - Deploy and Sync buttons */}
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
{project ? (
|
{project ? (
|
||||||
<ProjectTitleMenu
|
<>
|
||||||
projectId={project.id}
|
<GitSyncButton
|
||||||
projectName={project.name}
|
projectId={project.id}
|
||||||
onNewChat={handleNewChat}
|
className="h-8 w-8"
|
||||||
onGitHistory={() => setGitHistoryOpen(true)}
|
/>
|
||||||
onDuplicate={() => setDuplicateDialogOpen(true)}
|
<DeployButton
|
||||||
onDelete={() => setDeleteDialogOpen(true)}
|
projectId={project.id}
|
||||||
onProjectDetails={() => setIsProjectDetailsOpen(true)}
|
projectName={project.name}
|
||||||
isAILoading={isAILoading}
|
disabled={isAnyLoading}
|
||||||
isAnyLoading={isAnyLoading || isDeleting}
|
/>
|
||||||
className="text-lg"
|
<Tooltip>
|
||||||
/>
|
<TooltipTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="h-8 w-8"
|
||||||
|
onClick={() => setIsFloatingChatEnabled(true)}
|
||||||
|
aria-label="Floating chat"
|
||||||
|
aria-pressed={isFloatingChatEnabled}
|
||||||
|
>
|
||||||
|
<MessageSquare className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent>Floating chat</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
</>
|
||||||
) : (
|
) : (
|
||||||
<Skeleton className="h-6 w-40" />
|
<>
|
||||||
|
<Skeleton className="h-8 w-8 rounded" />
|
||||||
|
<Skeleton className="h-8 w-8 rounded" />
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* Right side - Deploy and Sync buttons */}
|
{/* Chat Content */}
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex-1 overflow-hidden">
|
||||||
{project ? (
|
{project ? (
|
||||||
<>
|
<ChatPane
|
||||||
<GitSyncButton
|
ref={chatPaneRef}
|
||||||
projectId={project.id}
|
projectId={project.id}
|
||||||
className="h-8 w-8"
|
onNewChat={handleNewChat}
|
||||||
/>
|
onFirstInteraction={handleFirstInteraction}
|
||||||
<DeployButton
|
onLoadingChange={handleAILoadingChange}
|
||||||
projectId={project.id}
|
isLoading={isAILoading}
|
||||||
projectName={project.name}
|
isBuildLoading={build.isPending}
|
||||||
disabled={isAnyLoading}
|
consoleError={consoleError}
|
||||||
/>
|
onDismissConsoleError={handleDismissConsoleError}
|
||||||
</>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<div className="h-full p-4 space-y-4">
|
||||||
<Skeleton className="h-8 w-8 rounded" />
|
<Skeleton className="h-12 w-full" />
|
||||||
<Skeleton className="h-8 w-8 rounded" />
|
<Skeleton className="h-8 w-3/4" />
|
||||||
</>
|
<Skeleton className="h-8 w-1/2" />
|
||||||
)}
|
<Skeleton className="h-32 w-full" />
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</ResizablePanel>
|
||||||
|
|
||||||
{/* Chat Content */}
|
{/* Resizable Handle */}
|
||||||
<div className="flex-1 overflow-hidden">
|
<ResizableHandle withHandle />
|
||||||
|
|
||||||
|
{/* Preview/Code Panel */}
|
||||||
|
<ResizablePanel defaultSize={65} minSize={30}>
|
||||||
|
<div className="h-full">
|
||||||
{project ? (
|
{project ? (
|
||||||
<ChatPane
|
<PreviewPane
|
||||||
ref={chatPaneRef}
|
|
||||||
projectId={project.id}
|
projectId={project.id}
|
||||||
onNewChat={handleNewChat}
|
activeTab={isPreviewable ? activeTab : 'code'}
|
||||||
onFirstInteraction={handleFirstInteraction}
|
onToggleView={isPreviewable ? () => setActiveTab(activeTab === 'preview' ? 'code' : 'preview') : undefined}
|
||||||
onLoadingChange={handleAILoadingChange}
|
isPreviewable={isPreviewable}
|
||||||
isLoading={isAILoading}
|
|
||||||
isBuildLoading={build.isPending}
|
|
||||||
consoleError={consoleError}
|
|
||||||
onDismissConsoleError={handleDismissConsoleError}
|
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<div className="h-full p-4 space-y-4">
|
<div className="h-full p-4 space-y-4">
|
||||||
<Skeleton className="h-12 w-full" />
|
<Skeleton className="h-8 w-32" />
|
||||||
<Skeleton className="h-8 w-3/4" />
|
<Skeleton className="h-full w-full" />
|
||||||
<Skeleton className="h-8 w-1/2" />
|
|
||||||
<Skeleton className="h-32 w-full" />
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</ResizablePanel>
|
||||||
</ResizablePanel>
|
</ResizablePanelGroup>
|
||||||
|
)}
|
||||||
{/* Resizable Handle */}
|
|
||||||
<ResizableHandle withHandle />
|
|
||||||
|
|
||||||
{/* Preview/Code Panel */}
|
|
||||||
<ResizablePanel defaultSize={65} minSize={30}>
|
|
||||||
<div className="h-full">
|
|
||||||
{project ? (
|
|
||||||
<PreviewPane
|
|
||||||
projectId={project.id}
|
|
||||||
activeTab={isPreviewable ? activeTab : 'code'}
|
|
||||||
onToggleView={isPreviewable ? () => setActiveTab(activeTab === 'preview' ? 'code' : 'preview') : undefined}
|
|
||||||
isPreviewable={isPreviewable}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<div className="h-full p-4 space-y-4">
|
|
||||||
<Skeleton className="h-8 w-32" />
|
|
||||||
<Skeleton className="h-full w-full" />
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</ResizablePanel>
|
|
||||||
</ResizablePanelGroup>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Floating Chat Widget - Desktop */}
|
||||||
|
{isFloatingChatEnabled && project && (
|
||||||
|
<FloatingChatWidget
|
||||||
|
projectId={project.id}
|
||||||
|
isMinimized={isFloatingChatMinimized}
|
||||||
|
onToggleMinimize={() => setIsFloatingChatMinimized(!isFloatingChatMinimized)}
|
||||||
|
onClose={() => setIsFloatingChatEnabled(false)}
|
||||||
|
onNewChat={handleNewChat}
|
||||||
|
onFirstInteraction={handleFirstInteraction}
|
||||||
|
onLoadingChange={handleAILoadingChange}
|
||||||
|
isLoading={isAILoading}
|
||||||
|
isBuildLoading={build.isPending}
|
||||||
|
consoleError={consoleError}
|
||||||
|
onDismissConsoleError={handleDismissConsoleError}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Dialogs */}
|
{/* Dialogs */}
|
||||||
{project && (
|
{project && (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -257,6 +257,7 @@ export function SystemSettings() {
|
|||||||
icon={Settings}
|
icon={Settings}
|
||||||
titleKey="systemSettings"
|
titleKey="systemSettings"
|
||||||
descriptionKey="systemSettingsDescription"
|
descriptionKey="systemSettingsDescription"
|
||||||
|
className="space-y-2"
|
||||||
>
|
>
|
||||||
{/* Service Worker Configuration */}
|
{/* Service Worker Configuration */}
|
||||||
<Accordion type="single" collapsible className="w-full">
|
<Accordion type="single" collapsible className="w-full">
|
||||||
@@ -767,7 +768,7 @@ export function SystemSettings() {
|
|||||||
</div>
|
</div>
|
||||||
</AccordionTrigger>
|
</AccordionTrigger>
|
||||||
<AccordionContent className="px-4 pb-4">
|
<AccordionContent className="px-4 pb-4">
|
||||||
<div className="py-1 space-y-4">
|
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4 py-1">
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<Label htmlFor="fs-path-projects" className="text-sm font-medium">
|
<Label htmlFor="fs-path-projects" className="text-sm font-medium">
|
||||||
@@ -804,9 +805,6 @@ export function SystemSettings() {
|
|||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<p className="text-xs text-muted-foreground">
|
|
||||||
{t('projectsDirectoryDescription')}
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
@@ -845,9 +843,6 @@ export function SystemSettings() {
|
|||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<p className="text-xs text-muted-foreground">
|
|
||||||
{t('configDirectoryDescription')}
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
@@ -886,9 +881,6 @@ export function SystemSettings() {
|
|||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<p className="text-xs text-muted-foreground">
|
|
||||||
{t('temporaryDirectoryDescription')}
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
@@ -927,9 +919,6 @@ export function SystemSettings() {
|
|||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<p className="text-xs text-muted-foreground">
|
|
||||||
{t('pluginsDirectoryDescription')}
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
@@ -968,9 +957,6 @@ export function SystemSettings() {
|
|||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<p className="text-xs text-muted-foreground">
|
|
||||||
{t('templatesDirectoryDescription')}
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</AccordionContent>
|
</AccordionContent>
|
||||||
|
|||||||
Reference in new issue
Block a user