mirror of
https://github.com/anomalyco/opencode.git
synced 2026-04-05 13:34:52 +00:00
Compare commits
15 Commits
tool-optim
...
rankings
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a34bcf9880 | ||
|
|
3a0e00dd7f | ||
|
|
66b4e5e020 | ||
|
|
8b8d4fa066 | ||
|
|
6253ef0c27 | ||
|
|
c6ebc7ff7c | ||
|
|
985663620f | ||
|
|
c796b9a19e | ||
|
|
6ea108a03b | ||
|
|
280eb16e77 | ||
|
|
930e94a3ea | ||
|
|
629e866ff0 | ||
|
|
c08fa5675f | ||
|
|
cc50b778eb | ||
|
|
7a881b6950 |
32
bun.lock
32
bun.lock
@@ -26,7 +26,7 @@
|
||||
},
|
||||
"packages/app": {
|
||||
"name": "@opencode-ai/app",
|
||||
"version": "1.3.13",
|
||||
"version": "1.3.15",
|
||||
"dependencies": {
|
||||
"@kobalte/core": "catalog:",
|
||||
"@opencode-ai/sdk": "workspace:*",
|
||||
@@ -80,7 +80,7 @@
|
||||
},
|
||||
"packages/console/app": {
|
||||
"name": "@opencode-ai/console-app",
|
||||
"version": "1.3.13",
|
||||
"version": "1.3.15",
|
||||
"dependencies": {
|
||||
"@cloudflare/vite-plugin": "1.15.2",
|
||||
"@ibm/plex": "6.4.1",
|
||||
@@ -114,7 +114,7 @@
|
||||
},
|
||||
"packages/console/core": {
|
||||
"name": "@opencode-ai/console-core",
|
||||
"version": "1.3.13",
|
||||
"version": "1.3.15",
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-sts": "3.782.0",
|
||||
"@jsx-email/render": "1.1.1",
|
||||
@@ -141,7 +141,7 @@
|
||||
},
|
||||
"packages/console/function": {
|
||||
"name": "@opencode-ai/console-function",
|
||||
"version": "1.3.13",
|
||||
"version": "1.3.15",
|
||||
"dependencies": {
|
||||
"@ai-sdk/anthropic": "3.0.64",
|
||||
"@ai-sdk/openai": "3.0.48",
|
||||
@@ -165,7 +165,7 @@
|
||||
},
|
||||
"packages/console/mail": {
|
||||
"name": "@opencode-ai/console-mail",
|
||||
"version": "1.3.13",
|
||||
"version": "1.3.15",
|
||||
"dependencies": {
|
||||
"@jsx-email/all": "2.2.3",
|
||||
"@jsx-email/cli": "1.4.3",
|
||||
@@ -189,7 +189,7 @@
|
||||
},
|
||||
"packages/desktop": {
|
||||
"name": "@opencode-ai/desktop",
|
||||
"version": "1.3.13",
|
||||
"version": "1.3.15",
|
||||
"dependencies": {
|
||||
"@opencode-ai/app": "workspace:*",
|
||||
"@opencode-ai/ui": "workspace:*",
|
||||
@@ -222,7 +222,7 @@
|
||||
},
|
||||
"packages/desktop-electron": {
|
||||
"name": "@opencode-ai/desktop-electron",
|
||||
"version": "1.3.13",
|
||||
"version": "1.3.15",
|
||||
"dependencies": {
|
||||
"@opencode-ai/app": "workspace:*",
|
||||
"@opencode-ai/ui": "workspace:*",
|
||||
@@ -254,7 +254,7 @@
|
||||
},
|
||||
"packages/enterprise": {
|
||||
"name": "@opencode-ai/enterprise",
|
||||
"version": "1.3.13",
|
||||
"version": "1.3.15",
|
||||
"dependencies": {
|
||||
"@opencode-ai/ui": "workspace:*",
|
||||
"@opencode-ai/util": "workspace:*",
|
||||
@@ -283,7 +283,7 @@
|
||||
},
|
||||
"packages/function": {
|
||||
"name": "@opencode-ai/function",
|
||||
"version": "1.3.13",
|
||||
"version": "1.3.15",
|
||||
"dependencies": {
|
||||
"@octokit/auth-app": "8.0.1",
|
||||
"@octokit/rest": "catalog:",
|
||||
@@ -299,7 +299,7 @@
|
||||
},
|
||||
"packages/opencode": {
|
||||
"name": "opencode",
|
||||
"version": "1.3.13",
|
||||
"version": "1.3.15",
|
||||
"bin": {
|
||||
"opencode": "./bin/opencode",
|
||||
},
|
||||
@@ -428,7 +428,7 @@
|
||||
},
|
||||
"packages/plugin": {
|
||||
"name": "@opencode-ai/plugin",
|
||||
"version": "1.3.13",
|
||||
"version": "1.3.15",
|
||||
"dependencies": {
|
||||
"@opencode-ai/sdk": "workspace:*",
|
||||
"zod": "catalog:",
|
||||
@@ -462,7 +462,7 @@
|
||||
},
|
||||
"packages/sdk/js": {
|
||||
"name": "@opencode-ai/sdk",
|
||||
"version": "1.3.13",
|
||||
"version": "1.3.15",
|
||||
"dependencies": {
|
||||
"cross-spawn": "catalog:",
|
||||
},
|
||||
@@ -477,7 +477,7 @@
|
||||
},
|
||||
"packages/slack": {
|
||||
"name": "@opencode-ai/slack",
|
||||
"version": "1.3.13",
|
||||
"version": "1.3.15",
|
||||
"dependencies": {
|
||||
"@opencode-ai/sdk": "workspace:*",
|
||||
"@slack/bolt": "^3.17.1",
|
||||
@@ -512,7 +512,7 @@
|
||||
},
|
||||
"packages/ui": {
|
||||
"name": "@opencode-ai/ui",
|
||||
"version": "1.3.13",
|
||||
"version": "1.3.15",
|
||||
"dependencies": {
|
||||
"@kobalte/core": "catalog:",
|
||||
"@opencode-ai/sdk": "workspace:*",
|
||||
@@ -560,7 +560,7 @@
|
||||
},
|
||||
"packages/util": {
|
||||
"name": "@opencode-ai/util",
|
||||
"version": "1.3.13",
|
||||
"version": "1.3.15",
|
||||
"dependencies": {
|
||||
"zod": "catalog:",
|
||||
},
|
||||
@@ -571,7 +571,7 @@
|
||||
},
|
||||
"packages/web": {
|
||||
"name": "@opencode-ai/web",
|
||||
"version": "1.3.13",
|
||||
"version": "1.3.15",
|
||||
"dependencies": {
|
||||
"@astrojs/cloudflare": "12.6.3",
|
||||
"@astrojs/markdown-remark": "6.3.1",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@opencode-ai/app",
|
||||
"version": "1.3.13",
|
||||
"version": "1.3.15",
|
||||
"description": "",
|
||||
"type": "module",
|
||||
"exports": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@opencode-ai/console-app",
|
||||
"version": "1.3.13",
|
||||
"version": "1.3.15",
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
|
||||
541
packages/console/app/src/routes/rankings.css
Normal file
541
packages/console/app/src/routes/rankings.css
Normal file
@@ -0,0 +1,541 @@
|
||||
[data-page="zen"][data-route="rankings"] {
|
||||
[data-component="hero"][data-variant="rankings"] {
|
||||
padding-top: var(--vertical-padding);
|
||||
padding-bottom: var(--vertical-padding);
|
||||
|
||||
[data-slot="hero-copy"] {
|
||||
p {
|
||||
margin-bottom: 0;
|
||||
max-width: 44rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[data-component="container"] {
|
||||
border: none;
|
||||
}
|
||||
|
||||
[data-component="footer"] {
|
||||
border-top: none;
|
||||
}
|
||||
|
||||
[data-component="rankings-section"] {
|
||||
padding: var(--vertical-padding) var(--padding);
|
||||
|
||||
h3 {
|
||||
font-size: 16px;
|
||||
font-weight: 700;
|
||||
color: var(--color-text-strong);
|
||||
}
|
||||
}
|
||||
|
||||
[data-slot="chart"] {
|
||||
margin-top: 1.5rem;
|
||||
background: var(--color-background-weak);
|
||||
border: 1px solid var(--color-border-weak);
|
||||
border-radius: 0.5rem;
|
||||
padding: 2rem 1.5rem 1.5rem;
|
||||
overflow: visible;
|
||||
|
||||
@media (max-width: 40rem) {
|
||||
padding: 1.5rem 1rem 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
[data-slot="bars"] {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
gap: 0.75rem;
|
||||
height: 20rem;
|
||||
|
||||
@media (max-width: 40rem) {
|
||||
height: 14rem;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
[data-slot="bar-group"] {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
height: 100%;
|
||||
justify-content: flex-end;
|
||||
min-width: 2.5rem;
|
||||
cursor: default;
|
||||
transition: opacity 0.15s ease;
|
||||
|
||||
&[data-dimmed] {
|
||||
opacity: 0.35;
|
||||
}
|
||||
}
|
||||
|
||||
[data-slot="bar-label"] {
|
||||
color: var(--color-text-weak);
|
||||
font-size: 0.75rem;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
[data-slot="bar-wrap"] {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
[data-slot="bar"] {
|
||||
width: 100%;
|
||||
max-width: 4rem;
|
||||
border-radius: 0.25rem 0.25rem 0 0;
|
||||
min-height: 2px;
|
||||
display: flex;
|
||||
flex-direction: column-reverse;
|
||||
gap: 1px;
|
||||
overflow: hidden;
|
||||
|
||||
span {
|
||||
display: block;
|
||||
min-height: 1px;
|
||||
}
|
||||
|
||||
span:last-child {
|
||||
border-radius: 0.25rem 0.25rem 0 0;
|
||||
}
|
||||
}
|
||||
|
||||
[data-slot="bar-week"] {
|
||||
color: var(--color-text-weak);
|
||||
font-size: 0.75rem;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
[data-slot="tooltip"] {
|
||||
position: fixed;
|
||||
z-index: 100;
|
||||
transform: translateY(-100%);
|
||||
background: var(--color-background);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 0.375rem;
|
||||
padding: 0.75rem;
|
||||
min-width: 14rem;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
|
||||
pointer-events: none;
|
||||
|
||||
strong {
|
||||
display: block;
|
||||
color: var(--color-text-strong);
|
||||
font-size: 0.8125rem;
|
||||
font-weight: 600;
|
||||
margin-bottom: 0.125rem;
|
||||
}
|
||||
}
|
||||
|
||||
[data-slot="tooltip-total"] {
|
||||
display: block;
|
||||
color: var(--color-text-weak);
|
||||
font-size: 0.75rem;
|
||||
margin-bottom: 0.5rem;
|
||||
padding-bottom: 0.5rem;
|
||||
border-bottom: 1px solid var(--color-border-weak);
|
||||
}
|
||||
|
||||
[data-slot="tooltip-row"] {
|
||||
display: grid;
|
||||
grid-template-columns: auto 1fr auto;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: 0.75rem;
|
||||
color: var(--color-text);
|
||||
padding: 0.175rem 0;
|
||||
|
||||
i {
|
||||
width: 0.5rem;
|
||||
height: 0.5rem;
|
||||
border-radius: 2px;
|
||||
flex: none;
|
||||
}
|
||||
|
||||
span:last-child {
|
||||
text-align: right;
|
||||
color: var(--color-text-strong);
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
|
||||
[data-slot="legend"] {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.75rem 1.25rem;
|
||||
margin-top: 1.5rem;
|
||||
padding-top: 1rem;
|
||||
border-top: 1px solid var(--color-border-weak);
|
||||
}
|
||||
|
||||
[data-slot="legend-item"] {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: 0.8125rem;
|
||||
color: var(--color-text);
|
||||
|
||||
i {
|
||||
width: 0.75rem;
|
||||
height: 0.75rem;
|
||||
border-radius: 2px;
|
||||
flex: none;
|
||||
}
|
||||
}
|
||||
|
||||
[data-slot="subtitle"] {
|
||||
color: var(--color-text);
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
[data-slot="lb-podium"] {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 0.75rem;
|
||||
margin-top: 1.5rem;
|
||||
|
||||
@media (max-width: 40rem) {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
[data-slot="lb-podium-item"] {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.375rem;
|
||||
padding: 1.25rem;
|
||||
background: var(--color-background-weak);
|
||||
border: 1px solid var(--color-border-weak);
|
||||
border-radius: 0.5rem;
|
||||
|
||||
strong {
|
||||
color: var(--color-text-strong);
|
||||
font-size: 1.0625rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
|
||||
[data-slot="lb-podium-rank"] {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 1.75rem;
|
||||
height: 1.75rem;
|
||||
border-radius: 999px;
|
||||
font-size: 0.8125rem;
|
||||
font-weight: 700;
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
[data-slot="lb-podium-item"][data-rank="1"] [data-slot="lb-podium-rank"] {
|
||||
background: hsl(45, 93%, 47%);
|
||||
color: hsl(45, 100%, 10%);
|
||||
}
|
||||
|
||||
[data-slot="lb-podium-item"][data-rank="2"] [data-slot="lb-podium-rank"] {
|
||||
background: hsl(0, 0%, 75%);
|
||||
color: hsl(0, 0%, 15%);
|
||||
}
|
||||
|
||||
[data-slot="lb-podium-item"][data-rank="3"] [data-slot="lb-podium-rank"] {
|
||||
background: hsl(30, 60%, 50%);
|
||||
color: hsl(30, 60%, 10%);
|
||||
}
|
||||
|
||||
[data-slot="lb-podium-tokens"] {
|
||||
color: var(--color-text-weak);
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
[data-slot="leaderboard"] {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 0 2rem;
|
||||
margin-top: 1rem;
|
||||
|
||||
@media (max-width: 58rem) {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
[data-slot="lb-col"] {
|
||||
display: grid;
|
||||
align-content: start;
|
||||
}
|
||||
|
||||
[data-slot="lb-col"] [data-slot="lb-row"]:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
[data-slot="lb-row"] {
|
||||
display: grid;
|
||||
grid-template-columns: 2rem minmax(0, 1fr) auto;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
padding: 0.75rem 0;
|
||||
border-bottom: 1px solid var(--color-border-weak);
|
||||
}
|
||||
|
||||
[data-slot="lb-row"]:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
[data-slot="lb-rank"] {
|
||||
color: var(--color-text-weak);
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
[data-slot="lb-info"] {
|
||||
min-width: 0;
|
||||
|
||||
strong {
|
||||
display: block;
|
||||
color: var(--color-text-strong);
|
||||
font-size: 0.9375rem;
|
||||
font-weight: 500;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
}
|
||||
|
||||
[data-slot="lb-tokens"] {
|
||||
white-space: nowrap;
|
||||
color: var(--color-text);
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
[data-slot="lb-toggle"] {
|
||||
display: block;
|
||||
margin: 1rem auto 0;
|
||||
padding: 0;
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--color-text-weak);
|
||||
font: inherit;
|
||||
font-size: 0.875rem;
|
||||
cursor: pointer;
|
||||
text-decoration: underline;
|
||||
text-underline-offset: 0.14em;
|
||||
text-decoration-thickness: 1px;
|
||||
|
||||
&:hover {
|
||||
color: var(--color-text-strong);
|
||||
}
|
||||
}
|
||||
|
||||
[data-slot="share-bars"] {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
height: 20rem;
|
||||
|
||||
@media (max-width: 40rem) {
|
||||
height: 14rem;
|
||||
gap: 0.375rem;
|
||||
}
|
||||
}
|
||||
|
||||
[data-slot="share-col"] {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
min-width: 2.5rem;
|
||||
cursor: default;
|
||||
transition: opacity 0.15s ease;
|
||||
|
||||
&[data-dimmed] {
|
||||
opacity: 0.35;
|
||||
}
|
||||
}
|
||||
|
||||
[data-slot="share-stack"] {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column-reverse;
|
||||
gap: 1px;
|
||||
border-radius: 0.25rem;
|
||||
overflow: hidden;
|
||||
|
||||
span {
|
||||
display: block;
|
||||
min-height: 1px;
|
||||
}
|
||||
}
|
||||
|
||||
[data-slot="share-week"] {
|
||||
color: var(--color-text-weak);
|
||||
font-size: 0.75rem;
|
||||
text-align: center;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
[data-slot="pricing-table"] {
|
||||
margin-top: 1.5rem;
|
||||
border: 1px solid var(--color-border-weak);
|
||||
border-radius: 0.5rem;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
[data-slot="pricing-header"],
|
||||
[data-slot="pricing-row"] {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1.5fr) repeat(4, minmax(0, 1fr));
|
||||
gap: 0.75rem;
|
||||
padding: 0.75rem 1.25rem;
|
||||
|
||||
&[data-cols="4"] {
|
||||
grid-template-columns: minmax(0, 1.5fr) repeat(3, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
&[data-cols="3"] {
|
||||
grid-template-columns: minmax(0, 1.5fr) repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
&[data-cols="2"] {
|
||||
grid-template-columns: minmax(0, 1fr) auto;
|
||||
}
|
||||
|
||||
@media (max-width: 40rem) {
|
||||
padding: 0.625rem 0.75rem;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
[data-slot="pricing-header"] {
|
||||
background: var(--color-background-weak);
|
||||
border-bottom: 1px solid var(--color-border-weak);
|
||||
font-size: 0.8125rem;
|
||||
font-weight: 600;
|
||||
color: var(--color-text-weak);
|
||||
}
|
||||
|
||||
[data-slot="pricing-row"] {
|
||||
border-bottom: 1px solid var(--color-border-weak);
|
||||
font-size: 0.875rem;
|
||||
color: var(--color-text);
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
}
|
||||
|
||||
[data-slot="cost-list"] {
|
||||
margin-top: 1.5rem;
|
||||
}
|
||||
|
||||
[data-slot="cost-group"] {
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
[data-slot="cost-row"] {
|
||||
padding: 0.5rem 0;
|
||||
}
|
||||
|
||||
[data-slot="cost-main"] {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) auto minmax(0, 1.2fr);
|
||||
align-items: center;
|
||||
gap: 0.75rem 2rem;
|
||||
}
|
||||
|
||||
[data-slot="cost-detail"] {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
margin-top: 0.375rem;
|
||||
font-size: 0.75rem;
|
||||
color: var(--color-text-weak);
|
||||
}
|
||||
|
||||
[data-slot="cost-bar-wrap"] {
|
||||
height: 0.375rem;
|
||||
background: var(--color-border-weak);
|
||||
border-radius: 999px;
|
||||
}
|
||||
|
||||
[data-slot="cost-bar"] {
|
||||
display: block;
|
||||
height: 100%;
|
||||
background: var(--color-background-strong);
|
||||
border-radius: 999px;
|
||||
min-width: 2px;
|
||||
}
|
||||
|
||||
[data-slot="pricing-model"] {
|
||||
color: var(--color-text-strong);
|
||||
font-weight: 500;
|
||||
font-size: 0.9375rem;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
[data-slot="pricing-effective"] {
|
||||
color: var(--color-text-strong);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
[data-slot="tps-cell"] {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
height: 0.5rem;
|
||||
background: var(--color-border-weak);
|
||||
border-radius: 999px;
|
||||
cursor: default;
|
||||
|
||||
&:hover::after {
|
||||
content: attr(title);
|
||||
position: absolute;
|
||||
bottom: calc(100% + 0.375rem);
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
padding: 0.25rem 0.5rem;
|
||||
background: var(--color-background);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 0.25rem;
|
||||
font-size: 0.75rem;
|
||||
color: var(--color-text-strong);
|
||||
white-space: nowrap;
|
||||
pointer-events: none;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
|
||||
z-index: 10;
|
||||
}
|
||||
}
|
||||
|
||||
[data-slot="tps-bar"] {
|
||||
height: 100%;
|
||||
background: var(--color-background-strong);
|
||||
border-radius: 999px 0 0 999px;
|
||||
min-width: 2px;
|
||||
}
|
||||
|
||||
[data-slot="map-wrap"] {
|
||||
position: relative;
|
||||
margin-top: 1.5rem;
|
||||
}
|
||||
|
||||
[data-slot="world-map"] {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
|
||||
path {
|
||||
cursor: default;
|
||||
transition: opacity 0.15s ease;
|
||||
|
||||
&:hover {
|
||||
opacity: 0.8;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
920
packages/console/app/src/routes/rankings.tsx
Normal file
920
packages/console/app/src/routes/rankings.tsx
Normal file
@@ -0,0 +1,920 @@
|
||||
import "./zen/index.css"
|
||||
import "./rankings.css"
|
||||
import { Title } from "@solidjs/meta"
|
||||
import { createSignal, For, Show } from "solid-js"
|
||||
import { Footer } from "~/component/footer"
|
||||
import { Header } from "~/component/header"
|
||||
import { Legal } from "~/component/legal"
|
||||
import { LocaleLinks } from "~/component/locale-links"
|
||||
import { paths as worldPaths } from "./world-paths"
|
||||
|
||||
const models = [
|
||||
{ name: "minimax-m2.5-free", color: "#f25bb2" },
|
||||
{ name: "big-pickle", color: "#8b5cf6" },
|
||||
{ name: "mimo-v2-pro-free", color: "#18a57b" },
|
||||
{ name: "kimi-k2.5-free", color: "#3481cf" },
|
||||
{ name: "kimi-k2.5", color: "#e4ad27" },
|
||||
{ name: "minimax-m2.1-free", color: "#ff5a1f" },
|
||||
{ name: "glm-5-free", color: "#46b786" },
|
||||
{ name: "gpt-5-nano", color: "#84cc16" },
|
||||
{ name: "nemotron-3-super-free", color: "#14c2a3" },
|
||||
{ name: "claude-opus-4-6", color: "#ff7b3d" },
|
||||
] as const
|
||||
|
||||
type Week = {
|
||||
week: string
|
||||
segments: { model: string; color: string; tokens: number }[]
|
||||
total: number
|
||||
}
|
||||
|
||||
const raw: Record<string, Record<string, number>> = {
|
||||
"jan-27": {
|
||||
"big-pickle": 368743864804,
|
||||
"kimi-k2.5-free": 915886375887,
|
||||
"kimi-k2.5": 39168495089,
|
||||
"minimax-m2.1-free": 270764664177,
|
||||
"gpt-5-nano": 41276213376,
|
||||
},
|
||||
"feb-3": {
|
||||
"big-pickle": 520618971808,
|
||||
"kimi-k2.5-free": 980317788887,
|
||||
"kimi-k2.5": 92823557285,
|
||||
"minimax-m2.1-free": 721380871693,
|
||||
"gpt-5-nano": 74420810088,
|
||||
"claude-opus-4-6": 49826050233,
|
||||
},
|
||||
"feb-10": {
|
||||
"minimax-m2.5-free": 905276977685,
|
||||
"big-pickle": 775593605696,
|
||||
"kimi-k2.5-free": 546100624556,
|
||||
"kimi-k2.5": 106869700825,
|
||||
"minimax-m2.1-free": 273479063739,
|
||||
"glm-5-free": 21944995438,
|
||||
"gpt-5-nano": 86562724981,
|
||||
"claude-opus-4-6": 71785580030,
|
||||
},
|
||||
"feb-17": {
|
||||
"minimax-m2.5-free": 1313909105944,
|
||||
"big-pickle": 1017431400927,
|
||||
"kimi-k2.5-free": 350112011799,
|
||||
"kimi-k2.5": 100616295719,
|
||||
"minimax-m2.1-free": 11269742719,
|
||||
"glm-5-free": 735726749938,
|
||||
"gpt-5-nano": 79036772388,
|
||||
"claude-opus-4-6": 66789922519,
|
||||
},
|
||||
"feb-24": {
|
||||
"minimax-m2.5-free": 1988229542028,
|
||||
"big-pickle": 1332574843957,
|
||||
"kimi-k2.5-free": 17964822381,
|
||||
"kimi-k2.5": 152009783828,
|
||||
"minimax-m2.1-free": 10376282858,
|
||||
"glm-5-free": 3848233361,
|
||||
"gpt-5-nano": 94195723658,
|
||||
"claude-opus-4-6": 72579249230,
|
||||
},
|
||||
"mar-3": {
|
||||
"minimax-m2.5-free": 1103526073812,
|
||||
"big-pickle": 864075264151,
|
||||
"kimi-k2.5": 236732504356,
|
||||
"gpt-5-nano": 62076480967,
|
||||
"claude-opus-4-6": 75122544903,
|
||||
},
|
||||
"mar-10": {
|
||||
"minimax-m2.5-free": 1765538911999,
|
||||
"big-pickle": 1456821813321,
|
||||
"kimi-k2.5": 270005019814,
|
||||
"gpt-5-nano": 80064940458,
|
||||
"nemotron-3-super-free": 226767628611,
|
||||
"claude-opus-4-6": 121826865344,
|
||||
},
|
||||
"mar-17": {
|
||||
"minimax-m2.5-free": 2258964526070,
|
||||
"big-pickle": 2157757939980,
|
||||
"mimo-v2-pro-free": 1393092895745,
|
||||
"kimi-k2.5": 253277628360,
|
||||
"gpt-5-nano": 91075743861,
|
||||
"nemotron-3-super-free": 257336931857,
|
||||
"claude-opus-4-6": 107180831444,
|
||||
},
|
||||
"mar-24": {
|
||||
"minimax-m2.5-free": 2256417941175,
|
||||
"big-pickle": 2596072141208,
|
||||
"mimo-v2-pro-free": 1612680626347,
|
||||
"kimi-k2.5": 263140655381,
|
||||
"gpt-5-nano": 130043140955,
|
||||
"nemotron-3-super-free": 254171104198,
|
||||
"claude-opus-4-6": 107813898809,
|
||||
},
|
||||
}
|
||||
|
||||
const totals: Record<string, number> = {
|
||||
"jan-27": 1954431878631,
|
||||
"feb-3": 2782873471532,
|
||||
"feb-10": 2982021636344,
|
||||
"feb-17": 3898395901667,
|
||||
"feb-24": 3980255846812,
|
||||
"mar-3": 2789862168396,
|
||||
"mar-10": 4672779512356,
|
||||
"mar-17": 7453410720062,
|
||||
"mar-24": 8434615944207,
|
||||
}
|
||||
|
||||
const weeks = ["jan-27", "feb-3", "feb-10", "feb-17", "feb-24", "mar-3", "mar-10", "mar-17", "mar-24"]
|
||||
const labels: Record<string, string> = {
|
||||
"jan-27": "Jan 27",
|
||||
"feb-3": "Feb 3",
|
||||
"feb-10": "Feb 10",
|
||||
"feb-17": "Feb 17",
|
||||
"feb-24": "Feb 24",
|
||||
"mar-3": "Mar 3",
|
||||
"mar-10": "Mar 10",
|
||||
"mar-17": "Mar 17",
|
||||
"mar-24": "Mar 24",
|
||||
}
|
||||
|
||||
const usage: Week[] = weeks.map((key) => {
|
||||
const data = raw[key]
|
||||
const total = totals[key]
|
||||
const named = models.filter((m) => data[m.name]).map((m) => ({ model: m.name, color: m.color, tokens: data[m.name] }))
|
||||
const rest = total - named.reduce((sum, s) => sum + s.tokens, 0)
|
||||
return {
|
||||
week: labels[key],
|
||||
total,
|
||||
segments: [...named, { model: "Other", color: "rgba(148, 163, 184, 0.35)", tokens: rest }],
|
||||
}
|
||||
})
|
||||
|
||||
const max = Math.max(...usage.map((w) => w.total))
|
||||
|
||||
const fmt = (n: number) => {
|
||||
if (n >= 1e12) return `${(n / 1e12).toFixed(1)}T`
|
||||
return `${(n / 1e9).toFixed(0)}B`
|
||||
}
|
||||
|
||||
const leaderboard = [
|
||||
{ rank: 1, model: "big-pickle", tokens: 2_596_072_141_208 },
|
||||
{ rank: 2, model: "minimax-m2.5-free", tokens: 2_256_417_941_175 },
|
||||
{ rank: 3, model: "mimo-v2-pro-free", tokens: 1_612_680_626_347 },
|
||||
{ rank: 4, model: "mimo-v2-omni-free", tokens: 313_963_070_777 },
|
||||
{ rank: 5, model: "kimi-k2.5", tokens: 263_140_655_381 },
|
||||
{ rank: 6, model: "nemotron-3-super-free", tokens: 254_171_104_198 },
|
||||
{ rank: 7, model: "minimax-m2.7", tokens: 235_471_532_073 },
|
||||
{ rank: 8, model: "qwen3.6-plus-free", tokens: 211_645_852_696 },
|
||||
{ rank: 9, model: "glm-5", tokens: 149_968_059_435 },
|
||||
{ rank: 10, model: "gpt-5-nano", tokens: 130_043_140_955 },
|
||||
{ rank: 11, model: "claude-opus-4-6", tokens: 107_813_898_809 },
|
||||
{ rank: 12, model: "minimax-m2.5", tokens: 91_477_876_330 },
|
||||
{ rank: 13, model: "gpt-5.4", tokens: 64_216_544_736 },
|
||||
{ rank: 14, model: "claude-sonnet-4-6", tokens: 53_638_240_479 },
|
||||
{ rank: 15, model: "gpt-5.3-codex", tokens: 31_928_019_743 },
|
||||
{ rank: 16, model: "gemini-3-flash", tokens: 14_528_488_448 },
|
||||
{ rank: 17, model: "claude-haiku-4-5", tokens: 8_921_076_835 },
|
||||
{ rank: 18, model: "gemini-3.1-pro", tokens: 7_676_935_166 },
|
||||
{ rank: 19, model: "claude-sonnet-4-5", tokens: 5_051_555_617 },
|
||||
{ rank: 20, model: "gpt-5.4-mini", tokens: 4_751_125_737 },
|
||||
]
|
||||
|
||||
const providers = [
|
||||
{ name: "opencode", color: "#8b5cf6" },
|
||||
{ name: "minimax", color: "#f25bb2" },
|
||||
{ name: "xiaomi", color: "#ff5a1f" },
|
||||
{ name: "moonshot", color: "#3481cf" },
|
||||
{ name: "nvidia", color: "#14c2a3" },
|
||||
{ name: "openai", color: "#84cc16" },
|
||||
{ name: "anthropic", color: "#ff7b3d" },
|
||||
{ name: "zhipu", color: "#46b786" },
|
||||
{ name: "google", color: "#e4ad27" },
|
||||
{ name: "alibaba", color: "#ef5db1" },
|
||||
{ name: "arcee", color: "#2085ec" },
|
||||
] as const
|
||||
|
||||
const shareRaw: Record<string, Record<string, number>> = {
|
||||
"jan-27": {
|
||||
moonshot: 957101046076,
|
||||
opencode: 368743864804,
|
||||
minimax: 273789245099,
|
||||
zhipu: 175220173052,
|
||||
openai: 71428726197,
|
||||
anthropic: 63795092028,
|
||||
arcee: 22900709163,
|
||||
google: 21116481943,
|
||||
alibaba: 336540269,
|
||||
},
|
||||
"feb-3": {
|
||||
moonshot: 1075728836899,
|
||||
minimax: 727777460147,
|
||||
opencode: 520618971808,
|
||||
anthropic: 126083048915,
|
||||
openai: 119992167519,
|
||||
zhipu: 106315324243,
|
||||
arcee: 70511760645,
|
||||
google: 35345191581,
|
||||
alibaba: 500567954,
|
||||
},
|
||||
"feb-10": {
|
||||
minimax: 1195064506114,
|
||||
opencode: 775593605696,
|
||||
moonshot: 655693064959,
|
||||
openai: 126021773769,
|
||||
anthropic: 114969689993,
|
||||
zhipu: 66447874989,
|
||||
google: 27728156767,
|
||||
arcee: 20502880487,
|
||||
},
|
||||
"feb-17": {
|
||||
minimax: 1340689075939,
|
||||
opencode: 1017431400927,
|
||||
zhipu: 753486920157,
|
||||
moonshot: 453006079914,
|
||||
anthropic: 136280713749,
|
||||
openai: 117036878336,
|
||||
google: 44709966980,
|
||||
arcee: 35460739820,
|
||||
},
|
||||
"feb-24": {
|
||||
minimax: 2037390464296,
|
||||
opencode: 1332574843957,
|
||||
moonshot: 172345287072,
|
||||
openai: 165404921924,
|
||||
anthropic: 137007019288,
|
||||
arcee: 65348467867,
|
||||
zhipu: 36192647725,
|
||||
google: 32632757942,
|
||||
},
|
||||
"mar-3": {
|
||||
minimax: 1236589693899,
|
||||
opencode: 864075264151,
|
||||
moonshot: 236940261927,
|
||||
openai: 144296631970,
|
||||
anthropic: 143388311109,
|
||||
zhipu: 89420861866,
|
||||
google: 35499950281,
|
||||
xiaomi: 24396507662,
|
||||
arcee: 14674544044,
|
||||
},
|
||||
"mar-10": {
|
||||
minimax: 1919467888084,
|
||||
opencode: 1456821813321,
|
||||
xiaomi: 302031698856,
|
||||
moonshot: 270021430246,
|
||||
nvidia: 226767628611,
|
||||
anthropic: 181566633371,
|
||||
openai: 171713393912,
|
||||
zhipu: 113460952065,
|
||||
google: 30109971757,
|
||||
arcee: 818102133,
|
||||
},
|
||||
"mar-17": {
|
||||
minimax: 2536581988215,
|
||||
opencode: 2157757939980,
|
||||
xiaomi: 1708313298084,
|
||||
nvidia: 257336931857,
|
||||
moonshot: 253304780525,
|
||||
openai: 196305815207,
|
||||
anthropic: 188087354693,
|
||||
zhipu: 127277270842,
|
||||
google: 28180238053,
|
||||
arcee: 265058488,
|
||||
},
|
||||
"mar-24": {
|
||||
opencode: 2596072141208,
|
||||
minimax: 2583441903425,
|
||||
xiaomi: 1930671539776,
|
||||
moonshot: 263142158847,
|
||||
nvidia: 254171104198,
|
||||
openai: 242821016755,
|
||||
alibaba: 211645852696,
|
||||
anthropic: 179934787304,
|
||||
zhipu: 150050493012,
|
||||
google: 22325363704,
|
||||
arcee: 336333746,
|
||||
},
|
||||
}
|
||||
|
||||
const share = weeks.map((key) => {
|
||||
const data = shareRaw[key]
|
||||
const total = totals[key]
|
||||
const segs = providers
|
||||
.filter((p) => data[p.name])
|
||||
.map((p) => ({
|
||||
provider: p.name,
|
||||
color: p.color,
|
||||
tokens: data[p.name],
|
||||
pct: (data[p.name] / total) * 100,
|
||||
}))
|
||||
return { week: labels[key], total, segments: segs }
|
||||
})
|
||||
|
||||
const pricing: Record<string, { input: number; output: number; cached: number }> = {
|
||||
"kimi-k2.5": { input: 0.6, output: 3.0, cached: 0.1 },
|
||||
"minimax-m2.7": { input: 0.3, output: 1.2, cached: 0.06 },
|
||||
"glm-5": { input: 1.0, output: 3.2, cached: 0.2 },
|
||||
"claude-opus-4-6": { input: 5.0, output: 25.0, cached: 0.5 },
|
||||
"minimax-m2.5": { input: 0.3, output: 1.2, cached: 0.03 },
|
||||
"gpt-5.4": { input: 2.5, output: 15.0, cached: 0.25 },
|
||||
"claude-sonnet-4-6": { input: 3.0, output: 15.0, cached: 0.3 },
|
||||
"gpt-5.3-codex": { input: 1.75, output: 14.0, cached: 0.175 },
|
||||
"gemini-3-flash": { input: 0.5, output: 3.0, cached: 0.05 },
|
||||
"claude-haiku-4-5": { input: 1.0, output: 5.0, cached: 0.1 },
|
||||
"gemini-3.1-pro": { input: 2.0, output: 12.0, cached: 0.2 },
|
||||
"claude-sonnet-4-5": { input: 3.0, output: 15.0, cached: 0.3 },
|
||||
"gpt-5.4-mini": { input: 0.75, output: 4.5, cached: 0.075 },
|
||||
}
|
||||
|
||||
const effective = (p: { input: number; output: number; cached: number }) =>
|
||||
p.cached * 0.94 + p.input * 0.06 + p.output * 0.01
|
||||
|
||||
const price = (n: number) => (n === 0 ? "Free" : `$${n.toFixed(2)}`)
|
||||
|
||||
const modelGroup: Record<string, string> = {
|
||||
"kimi-k2.5": "moonshot",
|
||||
"minimax-m2.7": "minimax",
|
||||
"minimax-m2.5": "minimax",
|
||||
"glm-5": "zhipu",
|
||||
"claude-opus-4-6": "anthropic",
|
||||
"claude-sonnet-4-6": "anthropic",
|
||||
"claude-sonnet-4-5": "anthropic",
|
||||
"claude-haiku-4-5": "anthropic",
|
||||
"gpt-5.4": "openai",
|
||||
"gpt-5.3-codex": "openai",
|
||||
"gpt-5.4-mini": "openai",
|
||||
"gemini-3-flash": "google",
|
||||
"gemini-3.1-pro": "google",
|
||||
}
|
||||
|
||||
const pricedModels = leaderboard
|
||||
.filter((r) => !r.model.endsWith("-free") && pricing[r.model])
|
||||
.sort((a, b) => effective(pricing[a.model]) - effective(pricing[b.model]))
|
||||
|
||||
const maxEffective = Math.max(...pricedModels.map((r) => effective(pricing[r.model])))
|
||||
|
||||
const grouped = (() => {
|
||||
const groups: { provider: string; models: typeof pricedModels }[] = []
|
||||
const seen = new Set<string>()
|
||||
for (const row of pricedModels) {
|
||||
const g = modelGroup[row.model] || row.model
|
||||
if (seen.has(g)) continue
|
||||
seen.add(g)
|
||||
const items = pricedModels.filter((r) => (modelGroup[r.model] || r.model) === g)
|
||||
groups.push({ provider: g, models: items })
|
||||
}
|
||||
return groups
|
||||
})()
|
||||
|
||||
const sessions = [
|
||||
{ model: "gpt-5.4-nano", spend: 56.19, sessions: 2469, tokens: 2_058_320_992 },
|
||||
{ model: "gpt-5.1-codex-mini", spend: 46.49, sessions: 649, tokens: 1_114_706_819 },
|
||||
{ model: "minimax-m2.5", spend: 10774.93, sessions: 101862, tokens: 91_512_287_752 },
|
||||
{ model: "claude-haiku-4-5", spend: 2169.56, sessions: 14896, tokens: 8_965_515_678 },
|
||||
{ model: "gpt-5.4-mini", spend: 858.63, sessions: 4726, tokens: 4_759_454_622 },
|
||||
{ model: "minimax-m2.7", spend: 24120.99, sessions: 118523, tokens: 235_267_498_689 },
|
||||
{ model: "gpt-5.4", spend: 31834.9, sessions: 142909, tokens: 64_146_279_556 },
|
||||
{ model: "kimi-k2.5", spend: 39724.09, sessions: 150135, tokens: 263_660_128_320 },
|
||||
{ model: "gemini-3-flash", spend: 2294.28, sessions: 8405, tokens: 14_752_884_651 },
|
||||
{ model: "glm-5", spend: 37814.87, sessions: 105292, tokens: 150_626_981_063 },
|
||||
{ model: "claude-sonnet-4-6", spend: 32133.34, sessions: 42237, tokens: 53_550_067_871 },
|
||||
{ model: "gpt-5.3-codex", spend: 10809.82, sessions: 13888, tokens: 31_907_600_634 },
|
||||
{ model: "claude-sonnet-4-5", spend: 4061.09, sessions: 4057, tokens: 5_157_076_730 },
|
||||
{ model: "gemini-3.1-pro", spend: 6257.1, sessions: 5777, tokens: 7_569_358_077 },
|
||||
{ model: "claude-opus-4-6", spend: 114219.22, sessions: 42550, tokens: 106_575_958_684 },
|
||||
{ model: "claude-opus-4-5", spend: 3582.53, sessions: 1576, tokens: 3_219_688_476 },
|
||||
{ model: "gpt-5.4-pro", spend: 6555.13, sessions: 1264, tokens: 200_314_429 },
|
||||
]
|
||||
|
||||
const avg = (r: (typeof sessions)[number]) => r.spend / r.sessions
|
||||
const avgTokens = (r: (typeof sessions)[number]) => Math.round(r.tokens / r.sessions)
|
||||
|
||||
const fmtTokens = (n: number) => {
|
||||
if (n >= 1e6) return `${(n / 1e6).toFixed(1)}M`
|
||||
if (n >= 1e3) return `${(n / 1e3).toFixed(0)}K`
|
||||
return String(n)
|
||||
}
|
||||
|
||||
const maxTps = Math.max(...sessions.map((r) => avgTokens(r)))
|
||||
|
||||
const countries: Record<string, number> = {
|
||||
CN: 1_954_638_555_964,
|
||||
US: 893_134_696_046,
|
||||
IN: 535_643_693_640,
|
||||
BR: 382_163_396_828,
|
||||
DE: 311_242_520_442,
|
||||
ES: 209_329_692_495,
|
||||
RU: 201_527_328_150,
|
||||
HK: 196_512_051_704,
|
||||
GB: 166_553_586_780,
|
||||
AR: 162_194_105_984,
|
||||
SG: 158_456_781_083,
|
||||
FR: 156_789_513_531,
|
||||
JP: 152_176_549_930,
|
||||
NL: 142_283_579_531,
|
||||
ID: 133_099_866_730,
|
||||
CA: 130_175_404_155,
|
||||
IT: 104_164_651_206,
|
||||
MX: 103_470_313_882,
|
||||
TW: 99_750_103_092,
|
||||
CO: 96_782_169_230,
|
||||
VN: 89_760_456_363,
|
||||
PL: 87_055_503_038,
|
||||
TR: 83_380_620_873,
|
||||
KR: 82_692_257_401,
|
||||
AU: 82_626_936_402,
|
||||
PH: 63_600_637_182,
|
||||
EG: 61_672_925_246,
|
||||
PT: 55_231_430_725,
|
||||
BD: 54_398_663_664,
|
||||
SE: 53_569_291_560,
|
||||
CL: 52_319_761_865,
|
||||
TH: 50_343_490_695,
|
||||
NG: 50_159_406_105,
|
||||
PK: 49_490_412_870,
|
||||
FI: 45_825_535_387,
|
||||
PE: 43_961_712_555,
|
||||
CH: 43_300_038_112,
|
||||
MY: 41_561_444_011,
|
||||
RO: 40_383_208_346,
|
||||
BE: 38_322_022_514,
|
||||
MA: 38_272_211_062,
|
||||
ZA: 38_180_939_069,
|
||||
UA: 36_032_426_930,
|
||||
VE: 34_807_973_969,
|
||||
KE: 34_239_081_597,
|
||||
IL: 32_705_941_531,
|
||||
AT: 31_995_376_039,
|
||||
DZ: 29_533_977_612,
|
||||
CZ: 28_976_529_740,
|
||||
NP: 25_623_967_353,
|
||||
DO: 23_957_780_174,
|
||||
DK: 22_736_971_721,
|
||||
EC: 21_934_976_342,
|
||||
AE: 21_823_728_235,
|
||||
TN: 21_412_135_454,
|
||||
NO: 20_735_253_026,
|
||||
SA: 20_234_711_215,
|
||||
BY: 18_939_368_533,
|
||||
GH: 16_936_621_597,
|
||||
RS: 16_778_051_855,
|
||||
NZ: 16_319_979_678,
|
||||
ET: 15_465_960_765,
|
||||
IE: 14_978_507_068,
|
||||
BO: 14_833_821_684,
|
||||
GR: 14_785_265_286,
|
||||
HU: 14_540_890_452,
|
||||
UY: 13_804_790_917,
|
||||
UZ: 13_008_621_109,
|
||||
LK: 12_735_597_659,
|
||||
BG: 12_045_851_521,
|
||||
CR: 11_261_069_513,
|
||||
PY: 10_614_168_600,
|
||||
KH: 10_555_315_979,
|
||||
KZ: 10_159_168_104,
|
||||
LT: 9_815_793_110,
|
||||
EE: 9_417_177_100,
|
||||
UG: 9_165_111_455,
|
||||
SK: 9_070_826_870,
|
||||
LV: 8_198_013_338,
|
||||
IQ: 8_187_011_695,
|
||||
HR: 7_605_019_662,
|
||||
CM: 7_377_050_916,
|
||||
ZW: 7_314_742_432,
|
||||
YE: 6_747_216_591,
|
||||
JO: 6_211_747_207,
|
||||
PA: 6_092_366_683,
|
||||
QA: 5_955_042_936,
|
||||
MD: 5_773_585_201,
|
||||
TZ: 5_625_754_397,
|
||||
NI: 5_228_293_282,
|
||||
GE: 5_165_628_063,
|
||||
SI: 4_955_336_900,
|
||||
SN: 4_688_066_204,
|
||||
BA: 4_549_605_753,
|
||||
BJ: 4_543_143_957,
|
||||
GT: 4_424_503_835,
|
||||
HN: 4_405_852_608,
|
||||
OM: 4_395_319_849,
|
||||
}
|
||||
|
||||
const maxCountry = Math.max(...Object.values(countries))
|
||||
|
||||
const names: Record<string, string> = {
|
||||
CN: "China",
|
||||
US: "United States",
|
||||
IN: "India",
|
||||
BR: "Brazil",
|
||||
DE: "Germany",
|
||||
ES: "Spain",
|
||||
RU: "Russia",
|
||||
HK: "Hong Kong",
|
||||
GB: "United Kingdom",
|
||||
AR: "Argentina",
|
||||
SG: "Singapore",
|
||||
FR: "France",
|
||||
JP: "Japan",
|
||||
NL: "Netherlands",
|
||||
ID: "Indonesia",
|
||||
CA: "Canada",
|
||||
IT: "Italy",
|
||||
MX: "Mexico",
|
||||
TW: "Taiwan",
|
||||
CO: "Colombia",
|
||||
VN: "Vietnam",
|
||||
PL: "Poland",
|
||||
TR: "Turkey",
|
||||
KR: "South Korea",
|
||||
AU: "Australia",
|
||||
PH: "Philippines",
|
||||
EG: "Egypt",
|
||||
PT: "Portugal",
|
||||
BD: "Bangladesh",
|
||||
SE: "Sweden",
|
||||
CL: "Chile",
|
||||
TH: "Thailand",
|
||||
NG: "Nigeria",
|
||||
PK: "Pakistan",
|
||||
FI: "Finland",
|
||||
PE: "Peru",
|
||||
CH: "Switzerland",
|
||||
MY: "Malaysia",
|
||||
RO: "Romania",
|
||||
BE: "Belgium",
|
||||
MA: "Morocco",
|
||||
ZA: "South Africa",
|
||||
UA: "Ukraine",
|
||||
VE: "Venezuela",
|
||||
KE: "Kenya",
|
||||
IL: "Israel",
|
||||
AT: "Austria",
|
||||
DZ: "Algeria",
|
||||
CZ: "Czechia",
|
||||
NP: "Nepal",
|
||||
DO: "Dominican Republic",
|
||||
DK: "Denmark",
|
||||
EC: "Ecuador",
|
||||
AE: "UAE",
|
||||
TN: "Tunisia",
|
||||
NO: "Norway",
|
||||
SA: "Saudi Arabia",
|
||||
BY: "Belarus",
|
||||
GH: "Ghana",
|
||||
RS: "Serbia",
|
||||
NZ: "New Zealand",
|
||||
ET: "Ethiopia",
|
||||
IE: "Ireland",
|
||||
BO: "Bolivia",
|
||||
GR: "Greece",
|
||||
HU: "Hungary",
|
||||
UY: "Uruguay",
|
||||
UZ: "Uzbekistan",
|
||||
LK: "Sri Lanka",
|
||||
BG: "Bulgaria",
|
||||
CR: "Costa Rica",
|
||||
PY: "Paraguay",
|
||||
KH: "Cambodia",
|
||||
KZ: "Kazakhstan",
|
||||
LT: "Lithuania",
|
||||
EE: "Estonia",
|
||||
UG: "Uganda",
|
||||
SK: "Slovakia",
|
||||
LV: "Latvia",
|
||||
IQ: "Iraq",
|
||||
HR: "Croatia",
|
||||
CM: "Cameroon",
|
||||
ZW: "Zimbabwe",
|
||||
YE: "Yemen",
|
||||
JO: "Jordan",
|
||||
PA: "Panama",
|
||||
QA: "Qatar",
|
||||
MD: "Moldova",
|
||||
TZ: "Tanzania",
|
||||
NI: "Nicaragua",
|
||||
GE: "Georgia",
|
||||
SI: "Slovenia",
|
||||
SN: "Senegal",
|
||||
BA: "Bosnia",
|
||||
BJ: "Benin",
|
||||
GT: "Guatemala",
|
||||
HN: "Honduras",
|
||||
OM: "Oman",
|
||||
}
|
||||
|
||||
const flag = (code: string) => String.fromCodePoint(...[...code].map((c) => 0x1f1e6 + c.charCodeAt(0) - 65))
|
||||
|
||||
const fill = (code: string) => {
|
||||
const val = countries[code]
|
||||
if (!val) return "var(--color-border-weak)"
|
||||
const t = Math.pow(Math.log(val) / Math.log(maxCountry), 1.5)
|
||||
const s = 50 + t * 40
|
||||
const l = 92 - t * 60
|
||||
return `hsl(220, ${s}%, ${l}%)`
|
||||
}
|
||||
|
||||
export default function Rankings() {
|
||||
const [active, setActive] = createSignal<number | null>(null)
|
||||
const [pos, setPos] = createSignal({ x: 0, y: 0 })
|
||||
const [expanded, setExpanded] = createSignal(false)
|
||||
const [shareActive, setShareActive] = createSignal<number | null>(null)
|
||||
const [sharePos, setSharePos] = createSignal({ x: 0, y: 0 })
|
||||
const [mapHover, setMapHover] = createSignal<string | null>(null)
|
||||
const [mapPos, setMapPos] = createSignal({ x: 0, y: 0 })
|
||||
|
||||
return (
|
||||
<main data-page="zen" data-route="rankings">
|
||||
<Title>Model Rankings</Title>
|
||||
<LocaleLinks path="/rankings" />
|
||||
|
||||
<div data-component="container">
|
||||
<Header zen hideGetStarted />
|
||||
|
||||
<div data-component="content">
|
||||
<section data-component="hero" data-variant="rankings">
|
||||
<div data-slot="hero-copy">
|
||||
<h1>Model Rankings</h1>
|
||||
<p>
|
||||
See which models are winning real usage, how the mix shifts over time, and where momentum is moving each
|
||||
week.
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section data-component="rankings-section">
|
||||
<h3>Usage</h3>
|
||||
<div data-slot="chart">
|
||||
<div
|
||||
data-slot="bars"
|
||||
onMouseLeave={() => setActive(null)}
|
||||
onMouseMove={(e) => setPos({ x: e.clientX, y: e.clientY })}
|
||||
>
|
||||
<For each={usage}>
|
||||
{(week, i) => (
|
||||
<div
|
||||
data-slot="bar-group"
|
||||
data-active={active() === i() ? "" : undefined}
|
||||
data-dimmed={active() !== null && active() !== i() ? "" : undefined}
|
||||
onMouseEnter={() => setActive(i())}
|
||||
>
|
||||
<span data-slot="bar-label">{fmt(week.total)}</span>
|
||||
<div data-slot="bar-wrap">
|
||||
<div data-slot="bar" style={{ height: `${(week.total / max) * 100}%` }}>
|
||||
<For each={week.segments}>
|
||||
{(seg) => (
|
||||
<span
|
||||
style={{
|
||||
flex: String(seg.tokens),
|
||||
background: seg.color,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</For>
|
||||
</div>
|
||||
</div>
|
||||
<span data-slot="bar-week">{week.week}</span>
|
||||
</div>
|
||||
)}
|
||||
</For>
|
||||
</div>
|
||||
<Show when={active() !== null}>
|
||||
<div
|
||||
data-slot="tooltip"
|
||||
style={{
|
||||
left: `${pos().x + 16}px`,
|
||||
top: `${pos().y - 16}px`,
|
||||
}}
|
||||
>
|
||||
<strong>{usage[active()!].week}</strong>
|
||||
<span data-slot="tooltip-total">{fmt(usage[active()!].total)} total</span>
|
||||
<For each={usage[active()!].segments.filter((s) => s.tokens > 0)}>
|
||||
{(seg) => (
|
||||
<span data-slot="tooltip-row">
|
||||
<i style={{ background: seg.color }} />
|
||||
<span>{seg.model}</span>
|
||||
<span>{fmt(seg.tokens)}</span>
|
||||
</span>
|
||||
)}
|
||||
</For>
|
||||
</div>
|
||||
</Show>
|
||||
<div data-slot="legend">
|
||||
<For each={models}>
|
||||
{(m) => (
|
||||
<span data-slot="legend-item">
|
||||
<i style={{ background: m.color }} />
|
||||
{m.name}
|
||||
</span>
|
||||
)}
|
||||
</For>
|
||||
<span data-slot="legend-item">
|
||||
<i style={{ background: "rgba(148, 163, 184, 0.35)" }} />
|
||||
Other
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section data-component="rankings-section">
|
||||
<h3>Leaderboard</h3>
|
||||
<p data-slot="subtitle">Week of Mar 24 — top models by token usage.</p>
|
||||
<div data-slot="lb-podium">
|
||||
<For each={leaderboard.slice(0, 3)}>
|
||||
{(row) => (
|
||||
<div data-slot="lb-podium-item" data-rank={row.rank}>
|
||||
<span data-slot="lb-podium-rank">{row.rank}</span>
|
||||
<strong>{row.model}</strong>
|
||||
<span data-slot="lb-podium-tokens">{fmt(row.tokens)}</span>
|
||||
</div>
|
||||
)}
|
||||
</For>
|
||||
</div>
|
||||
<div data-slot="leaderboard">
|
||||
<For
|
||||
each={[
|
||||
leaderboard.slice(3, expanded() ? 13 : 8),
|
||||
leaderboard.slice(expanded() ? 13 : 8, expanded() ? leaderboard.length : 13),
|
||||
]}
|
||||
>
|
||||
{(col) => (
|
||||
<div data-slot="lb-col">
|
||||
<For each={col}>
|
||||
{(row) => (
|
||||
<article data-slot="lb-row">
|
||||
<span data-slot="lb-rank">{row.rank}.</span>
|
||||
<div data-slot="lb-info">
|
||||
<strong>{row.model}</strong>
|
||||
</div>
|
||||
<span data-slot="lb-tokens">{fmt(row.tokens)}</span>
|
||||
</article>
|
||||
)}
|
||||
</For>
|
||||
</div>
|
||||
)}
|
||||
</For>
|
||||
</div>
|
||||
<Show when={leaderboard.length > 13}>
|
||||
<button data-slot="lb-toggle" onClick={() => setExpanded(!expanded())}>
|
||||
{expanded() ? "Show less" : "Show all"}
|
||||
</button>
|
||||
</Show>
|
||||
</section>
|
||||
|
||||
<section data-component="rankings-section">
|
||||
<h3>Market Share</h3>
|
||||
<div data-slot="chart">
|
||||
<div
|
||||
data-slot="share-bars"
|
||||
onMouseLeave={() => setShareActive(null)}
|
||||
onMouseMove={(e) => setSharePos({ x: e.clientX, y: e.clientY })}
|
||||
>
|
||||
<For each={share}>
|
||||
{(week, i) => (
|
||||
<div
|
||||
data-slot="share-col"
|
||||
data-dimmed={shareActive() !== null && shareActive() !== i() ? "" : undefined}
|
||||
onMouseEnter={() => setShareActive(i())}
|
||||
>
|
||||
<div data-slot="share-stack">
|
||||
<For each={week.segments}>
|
||||
{(seg) => <span style={{ flex: String(seg.pct), background: seg.color }} />}
|
||||
</For>
|
||||
</div>
|
||||
<span data-slot="share-week">{week.week}</span>
|
||||
</div>
|
||||
)}
|
||||
</For>
|
||||
</div>
|
||||
<Show when={shareActive() !== null}>
|
||||
<div
|
||||
data-slot="tooltip"
|
||||
style={{
|
||||
left: `${sharePos().x + 16}px`,
|
||||
top: `${sharePos().y - 16}px`,
|
||||
}}
|
||||
>
|
||||
<strong>{share[shareActive()!].week}</strong>
|
||||
<span data-slot="tooltip-total">{fmt(share[shareActive()!].total)} total</span>
|
||||
<For each={share[shareActive()!].segments.filter((s) => s.tokens > 0)}>
|
||||
{(seg) => (
|
||||
<span data-slot="tooltip-row">
|
||||
<i style={{ background: seg.color }} />
|
||||
<span>{seg.provider}</span>
|
||||
<span>{seg.pct.toFixed(1)}%</span>
|
||||
</span>
|
||||
)}
|
||||
</For>
|
||||
</div>
|
||||
</Show>
|
||||
<div data-slot="legend">
|
||||
<For each={providers}>
|
||||
{(p) => (
|
||||
<span data-slot="legend-item">
|
||||
<i style={{ background: p.color }} />
|
||||
{p.name}
|
||||
</span>
|
||||
)}
|
||||
</For>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section data-component="rankings-section">
|
||||
<h3>Token Cost</h3>
|
||||
<p data-slot="subtitle">Price per 1M tokens on OpenCode Zen.</p>
|
||||
<div data-slot="cost-list">
|
||||
<For each={grouped}>
|
||||
{(group) => (
|
||||
<div data-slot="cost-group">
|
||||
<For each={group.models}>
|
||||
{(row) => {
|
||||
const p = pricing[row.model]
|
||||
const eff = effective(p)
|
||||
return (
|
||||
<div data-slot="cost-row">
|
||||
<div data-slot="cost-main">
|
||||
<span data-slot="pricing-model">{row.model}</span>
|
||||
<span data-slot="pricing-effective">{price(eff)}</span>
|
||||
<span data-slot="cost-bar-wrap">
|
||||
<span data-slot="cost-bar" style={{ width: `${(eff / maxEffective) * 100}%` }} />
|
||||
</span>
|
||||
</div>
|
||||
<div data-slot="cost-detail">
|
||||
<span>Input {price(p.input)}</span>
|
||||
<span>Output {price(p.output)}</span>
|
||||
<span>Cached {price(p.cached)}</span>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}}
|
||||
</For>
|
||||
</div>
|
||||
)}
|
||||
</For>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section data-component="rankings-section">
|
||||
<h3>Session Cost</h3>
|
||||
<p data-slot="subtitle">Average cost per session on OpenCode Zen.</p>
|
||||
<div data-slot="pricing-table">
|
||||
<div data-slot="pricing-header" data-cols="3">
|
||||
<span>Model</span>
|
||||
<span>Cost / Session</span>
|
||||
<span>Tokens / Session</span>
|
||||
</div>
|
||||
<For each={sessions}>
|
||||
{(row) => (
|
||||
<div data-slot="pricing-row" data-cols="3">
|
||||
<span data-slot="pricing-model">{row.model}</span>
|
||||
<span data-slot="pricing-effective">${avg(row).toFixed(4)}</span>
|
||||
<span data-slot="tps-cell" title={fmtTokens(avgTokens(row))}>
|
||||
<span data-slot="tps-bar" style={{ width: `${(avgTokens(row) / maxTps) * 100}%` }} />
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</For>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section data-component="rankings-section">
|
||||
<h3>Token by Country</h3>
|
||||
<div data-slot="map-wrap" onMouseLeave={() => setMapHover(null)}>
|
||||
<svg
|
||||
data-slot="world-map"
|
||||
viewBox="30.767 241.591 784.077 458.627"
|
||||
onMouseMove={(e) => setMapPos({ x: e.clientX, y: e.clientY })}
|
||||
>
|
||||
<For each={Object.entries(worldPaths)}>
|
||||
{([code, d]) => (
|
||||
<path
|
||||
d={d}
|
||||
fill={fill(code)}
|
||||
stroke="var(--color-background)"
|
||||
stroke-width="0.5"
|
||||
onMouseEnter={() => setMapHover(code)}
|
||||
onMouseLeave={() => setMapHover(null)}
|
||||
/>
|
||||
)}
|
||||
</For>
|
||||
</svg>
|
||||
<Show when={mapHover() && countries[mapHover()!]}>
|
||||
<div
|
||||
data-slot="tooltip"
|
||||
style={{
|
||||
left: `${mapPos().x + 16}px`,
|
||||
top: `${mapPos().y - 16}px`,
|
||||
}}
|
||||
>
|
||||
<strong>
|
||||
{flag(mapHover()!)} {names[mapHover()!] || mapHover()}
|
||||
</strong>
|
||||
<span data-slot="tooltip-total">{fmt(countries[mapHover()!])}</span>
|
||||
</div>
|
||||
</Show>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<Footer />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Legal />
|
||||
</main>
|
||||
)
|
||||
}
|
||||
181
packages/console/app/src/routes/world-paths.ts
Normal file
181
packages/console/app/src/routes/world-paths.ts
Normal file
File diff suppressed because one or more lines are too long
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/package.json",
|
||||
"name": "@opencode-ai/console-core",
|
||||
"version": "1.3.13",
|
||||
"version": "1.3.15",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@opencode-ai/console-function",
|
||||
"version": "1.3.13",
|
||||
"version": "1.3.15",
|
||||
"$schema": "https://json.schemastore.org/package.json",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@opencode-ai/console-mail",
|
||||
"version": "1.3.13",
|
||||
"version": "1.3.15",
|
||||
"dependencies": {
|
||||
"@jsx-email/all": "2.2.3",
|
||||
"@jsx-email/cli": "1.4.3",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@opencode-ai/desktop-electron",
|
||||
"private": true,
|
||||
"version": "1.3.13",
|
||||
"version": "1.3.15",
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
"homepage": "https://opencode.ai",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@opencode-ai/desktop",
|
||||
"private": true,
|
||||
"version": "1.3.13",
|
||||
"version": "1.3.15",
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@opencode-ai/enterprise",
|
||||
"version": "1.3.13",
|
||||
"version": "1.3.15",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
id = "opencode"
|
||||
name = "OpenCode"
|
||||
description = "The open source coding agent."
|
||||
version = "1.3.13"
|
||||
version = "1.3.15"
|
||||
schema_version = 1
|
||||
authors = ["Anomaly"]
|
||||
repository = "https://github.com/anomalyco/opencode"
|
||||
@@ -11,26 +11,26 @@ name = "OpenCode"
|
||||
icon = "./icons/opencode.svg"
|
||||
|
||||
[agent_servers.opencode.targets.darwin-aarch64]
|
||||
archive = "https://github.com/anomalyco/opencode/releases/download/v1.3.13/opencode-darwin-arm64.zip"
|
||||
archive = "https://github.com/anomalyco/opencode/releases/download/v1.3.15/opencode-darwin-arm64.zip"
|
||||
cmd = "./opencode"
|
||||
args = ["acp"]
|
||||
|
||||
[agent_servers.opencode.targets.darwin-x86_64]
|
||||
archive = "https://github.com/anomalyco/opencode/releases/download/v1.3.13/opencode-darwin-x64.zip"
|
||||
archive = "https://github.com/anomalyco/opencode/releases/download/v1.3.15/opencode-darwin-x64.zip"
|
||||
cmd = "./opencode"
|
||||
args = ["acp"]
|
||||
|
||||
[agent_servers.opencode.targets.linux-aarch64]
|
||||
archive = "https://github.com/anomalyco/opencode/releases/download/v1.3.13/opencode-linux-arm64.tar.gz"
|
||||
archive = "https://github.com/anomalyco/opencode/releases/download/v1.3.15/opencode-linux-arm64.tar.gz"
|
||||
cmd = "./opencode"
|
||||
args = ["acp"]
|
||||
|
||||
[agent_servers.opencode.targets.linux-x86_64]
|
||||
archive = "https://github.com/anomalyco/opencode/releases/download/v1.3.13/opencode-linux-x64.tar.gz"
|
||||
archive = "https://github.com/anomalyco/opencode/releases/download/v1.3.15/opencode-linux-x64.tar.gz"
|
||||
cmd = "./opencode"
|
||||
args = ["acp"]
|
||||
|
||||
[agent_servers.opencode.targets.windows-x86_64]
|
||||
archive = "https://github.com/anomalyco/opencode/releases/download/v1.3.13/opencode-windows-x64.zip"
|
||||
archive = "https://github.com/anomalyco/opencode/releases/download/v1.3.15/opencode-windows-x64.zip"
|
||||
cmd = "./opencode.exe"
|
||||
args = ["acp"]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@opencode-ai/function",
|
||||
"version": "1.3.13",
|
||||
"version": "1.3.15",
|
||||
"$schema": "https://json.schemastore.org/package.json",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/package.json",
|
||||
"version": "1.3.13",
|
||||
"version": "1.3.15",
|
||||
"name": "opencode",
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -209,6 +209,7 @@ for (const item of targets) {
|
||||
conditions: ["browser"],
|
||||
tsconfig: "./tsconfig.json",
|
||||
plugins: [plugin],
|
||||
external: ["node-gyp"],
|
||||
compile: {
|
||||
autoloadBunfig: false,
|
||||
autoloadDotenv: false,
|
||||
|
||||
@@ -235,11 +235,27 @@ Once individual tools are effectified, change `Tool.Info` (`tool/tool.ts`) so `i
|
||||
2. Update `Tool.define()` factory to work with Effects
|
||||
3. Update `SessionPrompt` to `yield*` tool results instead of `await`ing
|
||||
|
||||
### Tool migration details
|
||||
|
||||
Until the tool interface itself returns `Effect`, use this transitional pattern for migrated tools:
|
||||
|
||||
- `Tool.defineEffect(...)` should `yield*` the services the tool depends on and close over them in the returned tool definition.
|
||||
- Keep the bridge at the Promise boundary only. Prefer a single `Effect.runPromise(...)` in the temporary `async execute(...)` implementation, and move the inner logic into `Effect.fn(...)` helpers instead of scattering `runPromise` islands through the tool body.
|
||||
- If a tool starts requiring new services, wire them into `ToolRegistry.defaultLayer` so production callers resolve the same dependencies as tests.
|
||||
|
||||
Tool tests should use the existing Effect helpers in `packages/opencode/test/lib/effect.ts`:
|
||||
|
||||
- Use `testEffect(...)` / `it.live(...)` instead of creating fake local wrappers around effectful tools.
|
||||
- Yield the real tool export, then initialize it: `const info = yield* ReadTool`, `const tool = yield* Effect.promise(() => info.init())`.
|
||||
- Run tests inside a real instance with `provideTmpdirInstance(...)` or `provideInstance(tmpdirScoped(...))` so instance-scoped services resolve exactly as they do in production.
|
||||
|
||||
This keeps migrated tool tests aligned with the production service graph today, and makes the eventual `Tool.Info` → `Effect` cleanup mostly mechanical later.
|
||||
|
||||
Individual tools, ordered by value:
|
||||
|
||||
- [ ] `apply_patch.ts` — HIGH: multi-step orchestration, error accumulation, Bus events
|
||||
- [ ] `bash.ts` — HIGH: shell orchestration, quoting, timeout handling, output capture
|
||||
- [ ] `read.ts` — HIGH: streaming I/O, readline, binary detection → FileSystem + Stream
|
||||
- [x] `read.ts` — HIGH: streaming I/O, readline, binary detection → FileSystem + Stream
|
||||
- [ ] `edit.ts` — HIGH: multi-step diff/format/publish pipeline, FileWatcher lock
|
||||
- [ ] `grep.ts` — MEDIUM: spawns ripgrep → ChildProcessSpawner, timeout handling
|
||||
- [ ] `write.ts` — MEDIUM: permission checks, diagnostics polling, Bus events
|
||||
|
||||
@@ -52,6 +52,11 @@ export type AccountOrgs = {
|
||||
orgs: readonly Org[]
|
||||
}
|
||||
|
||||
export type ActiveOrg = {
|
||||
account: Info
|
||||
org: Org
|
||||
}
|
||||
|
||||
class RemoteConfig extends Schema.Class<RemoteConfig>("RemoteConfig")({
|
||||
config: Schema.Record(Schema.String, Schema.Json),
|
||||
}) {}
|
||||
@@ -137,6 +142,7 @@ const mapAccountServiceError =
|
||||
export namespace Account {
|
||||
export interface Interface {
|
||||
readonly active: () => Effect.Effect<Option.Option<Info>, AccountError>
|
||||
readonly activeOrg: () => Effect.Effect<Option.Option<ActiveOrg>, AccountError>
|
||||
readonly list: () => Effect.Effect<Info[], AccountError>
|
||||
readonly orgsByAccount: () => Effect.Effect<readonly AccountOrgs[], AccountError>
|
||||
readonly remove: (accountID: AccountID) => Effect.Effect<void, AccountError>
|
||||
@@ -279,19 +285,31 @@ export namespace Account {
|
||||
resolveAccess(accountID).pipe(Effect.map(Option.map((r) => r.accessToken))),
|
||||
)
|
||||
|
||||
const activeOrg = Effect.fn("Account.activeOrg")(function* () {
|
||||
const activeAccount = yield* repo.active()
|
||||
if (Option.isNone(activeAccount)) return Option.none<ActiveOrg>()
|
||||
|
||||
const account = activeAccount.value
|
||||
if (!account.active_org_id) return Option.none<ActiveOrg>()
|
||||
|
||||
const accountOrgs = yield* orgs(account.id)
|
||||
const org = accountOrgs.find((item) => item.id === account.active_org_id)
|
||||
if (!org) return Option.none<ActiveOrg>()
|
||||
|
||||
return Option.some({ account, org })
|
||||
})
|
||||
|
||||
const orgsByAccount = Effect.fn("Account.orgsByAccount")(function* () {
|
||||
const accounts = yield* repo.list()
|
||||
const [errors, results] = yield* Effect.partition(
|
||||
return yield* Effect.forEach(
|
||||
accounts,
|
||||
(account) => orgs(account.id).pipe(Effect.map((orgs) => ({ account, orgs }))),
|
||||
(account) =>
|
||||
orgs(account.id).pipe(
|
||||
Effect.catch(() => Effect.succeed([] as readonly Org[])),
|
||||
Effect.map((orgs) => ({ account, orgs })),
|
||||
),
|
||||
{ concurrency: 3 },
|
||||
)
|
||||
for (const error of errors) {
|
||||
yield* Effect.logWarning("failed to fetch orgs for account").pipe(
|
||||
Effect.annotateLogs({ error: String(error) }),
|
||||
)
|
||||
}
|
||||
return results
|
||||
})
|
||||
|
||||
const orgs = Effect.fn("Account.orgs")(function* (accountID: AccountID) {
|
||||
@@ -396,6 +414,7 @@ export namespace Account {
|
||||
|
||||
return Service.of({
|
||||
active: repo.active,
|
||||
activeOrg,
|
||||
list: repo.list,
|
||||
orgsByAccount,
|
||||
remove: repo.remove,
|
||||
@@ -417,6 +436,26 @@ export namespace Account {
|
||||
return Option.getOrUndefined(await runPromise((service) => service.active()))
|
||||
}
|
||||
|
||||
export async function list(): Promise<Info[]> {
|
||||
return runPromise((service) => service.list())
|
||||
}
|
||||
|
||||
export async function activeOrg(): Promise<ActiveOrg | undefined> {
|
||||
return Option.getOrUndefined(await runPromise((service) => service.activeOrg()))
|
||||
}
|
||||
|
||||
export async function orgsByAccount(): Promise<readonly AccountOrgs[]> {
|
||||
return runPromise((service) => service.orgsByAccount())
|
||||
}
|
||||
|
||||
export async function orgs(accountID: AccountID): Promise<readonly Org[]> {
|
||||
return runPromise((service) => service.orgs(accountID))
|
||||
}
|
||||
|
||||
export async function switchOrg(accountID: AccountID, orgID: OrgID) {
|
||||
return runPromise((service) => service.use(accountID, Option.some(orgID)))
|
||||
}
|
||||
|
||||
export async function token(accountID: AccountID): Promise<AccessToken | undefined> {
|
||||
const t = await runPromise((service) => service.token(accountID))
|
||||
return Option.getOrUndefined(t)
|
||||
|
||||
@@ -36,6 +36,7 @@ import { CommandProvider, useCommandDialog } from "@tui/component/dialog-command
|
||||
import { DialogAgent } from "@tui/component/dialog-agent"
|
||||
import { DialogSessionList } from "@tui/component/dialog-session-list"
|
||||
import { DialogWorkspaceList } from "@tui/component/dialog-workspace-list"
|
||||
import { DialogConsoleOrg } from "@tui/component/dialog-console-org"
|
||||
import { KeybindProvider, useKeybind } from "@tui/context/keybind"
|
||||
import { ThemeProvider, useTheme } from "@tui/context/theme"
|
||||
import { Home } from "@tui/routes/home"
|
||||
@@ -629,6 +630,23 @@ function App(props: { onSnapshot?: () => Promise<string[]> }) {
|
||||
},
|
||||
category: "Provider",
|
||||
},
|
||||
...(sync.data.console_state.switchableOrgCount > 1
|
||||
? [
|
||||
{
|
||||
title: "Switch org",
|
||||
value: "console.org.switch",
|
||||
suggested: Boolean(sync.data.console_state.activeOrgName),
|
||||
slash: {
|
||||
name: "org",
|
||||
aliases: ["orgs", "switch-org"],
|
||||
},
|
||||
onSelect: () => {
|
||||
dialog.replace(() => <DialogConsoleOrg />)
|
||||
},
|
||||
category: "Provider",
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
title: "View status",
|
||||
keybind: "status_view",
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
import { createResource, createMemo } from "solid-js"
|
||||
import { DialogSelect } from "@tui/ui/dialog-select"
|
||||
import { useSDK } from "@tui/context/sdk"
|
||||
import { useDialog } from "@tui/ui/dialog"
|
||||
import { useToast } from "@tui/ui/toast"
|
||||
import { useTheme } from "@tui/context/theme"
|
||||
import type { ExperimentalConsoleListOrgsResponse } from "@opencode-ai/sdk/v2"
|
||||
|
||||
type OrgOption = ExperimentalConsoleListOrgsResponse["orgs"][number]
|
||||
|
||||
const accountHost = (url: string) => {
|
||||
try {
|
||||
return new URL(url).host
|
||||
} catch {
|
||||
return url
|
||||
}
|
||||
}
|
||||
|
||||
const accountLabel = (item: Pick<OrgOption, "accountEmail" | "accountUrl">) =>
|
||||
`${item.accountEmail} ${accountHost(item.accountUrl)}`
|
||||
|
||||
export function DialogConsoleOrg() {
|
||||
const sdk = useSDK()
|
||||
const dialog = useDialog()
|
||||
const toast = useToast()
|
||||
const { theme } = useTheme()
|
||||
|
||||
const [orgs] = createResource(async () => {
|
||||
const result = await sdk.client.experimental.console.listOrgs({}, { throwOnError: true })
|
||||
return result.data?.orgs ?? []
|
||||
})
|
||||
|
||||
const current = createMemo(() => orgs()?.find((item) => item.active))
|
||||
|
||||
const options = createMemo(() => {
|
||||
const listed = orgs()
|
||||
if (listed === undefined) {
|
||||
return [
|
||||
{
|
||||
title: "Loading orgs...",
|
||||
value: "loading",
|
||||
onSelect: () => {},
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
if (listed.length === 0) {
|
||||
return [
|
||||
{
|
||||
title: "No orgs found",
|
||||
value: "empty",
|
||||
onSelect: () => {},
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
return listed
|
||||
.toSorted((a, b) => {
|
||||
const activeAccountA = a.active ? 0 : 1
|
||||
const activeAccountB = b.active ? 0 : 1
|
||||
if (activeAccountA !== activeAccountB) return activeAccountA - activeAccountB
|
||||
|
||||
const accountCompare = accountLabel(a).localeCompare(accountLabel(b))
|
||||
if (accountCompare !== 0) return accountCompare
|
||||
|
||||
return a.orgName.localeCompare(b.orgName)
|
||||
})
|
||||
.map((item) => ({
|
||||
title: item.orgName,
|
||||
value: item,
|
||||
category: accountLabel(item),
|
||||
categoryView: (
|
||||
<box flexDirection="row" gap={2}>
|
||||
<text fg={theme.accent}>{item.accountEmail}</text>
|
||||
<text fg={theme.textMuted}>{accountHost(item.accountUrl)}</text>
|
||||
</box>
|
||||
),
|
||||
onSelect: async () => {
|
||||
if (item.active) {
|
||||
dialog.clear()
|
||||
return
|
||||
}
|
||||
|
||||
await sdk.client.experimental.console.switchOrg(
|
||||
{
|
||||
accountID: item.accountID,
|
||||
orgID: item.orgID,
|
||||
},
|
||||
{ throwOnError: true },
|
||||
)
|
||||
|
||||
await sdk.client.instance.dispose()
|
||||
toast.show({
|
||||
message: `Switched to ${item.orgName}`,
|
||||
variant: "info",
|
||||
})
|
||||
dialog.clear()
|
||||
},
|
||||
}))
|
||||
})
|
||||
|
||||
return <DialogSelect<string | OrgOption> title="Switch org" options={options()} current={current()} />
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import { createDialogProviderOptions, DialogProvider } from "./dialog-provider"
|
||||
import { DialogVariant } from "./dialog-variant"
|
||||
import { useKeybind } from "../context/keybind"
|
||||
import * as fuzzysort from "fuzzysort"
|
||||
import { consoleManagedProviderLabel } from "@tui/util/provider-origin"
|
||||
|
||||
export function useConnected() {
|
||||
const sync = useSync()
|
||||
@@ -46,7 +47,11 @@ export function DialogModel(props: { providerID?: string }) {
|
||||
key: item,
|
||||
value: { providerID: provider.id, modelID: model.id },
|
||||
title: model.name ?? item.modelID,
|
||||
description: provider.name,
|
||||
description: consoleManagedProviderLabel(
|
||||
sync.data.console_state.consoleManagedProviders,
|
||||
provider.id,
|
||||
provider.name,
|
||||
),
|
||||
category,
|
||||
disabled: provider.id === "opencode" && model.id.includes("-nano"),
|
||||
footer: model.cost?.input === 0 && provider.id === "opencode" ? "Free" : undefined,
|
||||
@@ -84,7 +89,9 @@ export function DialogModel(props: { providerID?: string }) {
|
||||
description: favorites.some((item) => item.providerID === provider.id && item.modelID === model)
|
||||
? "(Favorite)"
|
||||
: undefined,
|
||||
category: connected() ? provider.name : undefined,
|
||||
category: connected()
|
||||
? consoleManagedProviderLabel(sync.data.console_state.consoleManagedProviders, provider.id, provider.name)
|
||||
: undefined,
|
||||
disabled: provider.id === "opencode" && model.includes("-nano"),
|
||||
footer: info.cost?.input === 0 && provider.id === "opencode" ? "Free" : undefined,
|
||||
onSelect() {
|
||||
@@ -132,7 +139,11 @@ export function DialogModel(props: { providerID?: string }) {
|
||||
props.providerID ? sync.data.provider.find((x) => x.id === props.providerID) : null,
|
||||
)
|
||||
|
||||
const title = createMemo(() => provider()?.name ?? "Select model")
|
||||
const title = createMemo(() => {
|
||||
const value = provider()
|
||||
if (!value) return "Select model"
|
||||
return consoleManagedProviderLabel(sync.data.console_state.consoleManagedProviders, value.id, value.name)
|
||||
})
|
||||
|
||||
function onSelect(providerID: string, modelID: string) {
|
||||
local.model.set({ providerID, modelID }, { recent: true })
|
||||
|
||||
@@ -13,6 +13,7 @@ import { DialogModel } from "./dialog-model"
|
||||
import { useKeyboard } from "@opentui/solid"
|
||||
import { Clipboard } from "@tui/util/clipboard"
|
||||
import { useToast } from "../ui/toast"
|
||||
import { CONSOLE_MANAGED_ICON, isConsoleManagedProvider } from "@tui/util/provider-origin"
|
||||
|
||||
const PROVIDER_PRIORITY: Record<string, number> = {
|
||||
opencode: 0,
|
||||
@@ -28,87 +29,111 @@ export function createDialogProviderOptions() {
|
||||
const dialog = useDialog()
|
||||
const sdk = useSDK()
|
||||
const toast = useToast()
|
||||
const { theme } = useTheme()
|
||||
const options = createMemo(() => {
|
||||
return pipe(
|
||||
sync.data.provider_next.all,
|
||||
sortBy((x) => PROVIDER_PRIORITY[x.id] ?? 99),
|
||||
map((provider) => ({
|
||||
title: provider.name,
|
||||
value: provider.id,
|
||||
description: {
|
||||
opencode: "(Recommended)",
|
||||
anthropic: "(API key)",
|
||||
openai: "(ChatGPT Plus/Pro or API key)",
|
||||
"opencode-go": "Low cost subscription for everyone",
|
||||
}[provider.id],
|
||||
category: provider.id in PROVIDER_PRIORITY ? "Popular" : "Other",
|
||||
async onSelect() {
|
||||
const methods = sync.data.provider_auth[provider.id] ?? [
|
||||
{
|
||||
type: "api",
|
||||
label: "API key",
|
||||
},
|
||||
]
|
||||
let index: number | null = 0
|
||||
if (methods.length > 1) {
|
||||
index = await new Promise<number | null>((resolve) => {
|
||||
dialog.replace(
|
||||
() => (
|
||||
<DialogSelect
|
||||
title="Select auth method"
|
||||
options={methods.map((x, index) => ({
|
||||
title: x.label,
|
||||
value: index,
|
||||
}))}
|
||||
onSelect={(option) => resolve(option.value)}
|
||||
/>
|
||||
),
|
||||
() => resolve(null),
|
||||
)
|
||||
})
|
||||
}
|
||||
if (index == null) return
|
||||
const method = methods[index]
|
||||
if (method.type === "oauth") {
|
||||
let inputs: Record<string, string> | undefined
|
||||
if (method.prompts?.length) {
|
||||
const value = await PromptsMethod({
|
||||
dialog,
|
||||
prompts: method.prompts,
|
||||
})
|
||||
if (!value) return
|
||||
inputs = value
|
||||
}
|
||||
map((provider) => {
|
||||
const consoleManaged = isConsoleManagedProvider(sync.data.console_state.consoleManagedProviders, provider.id)
|
||||
const connected = sync.data.provider_next.connected.includes(provider.id)
|
||||
|
||||
const result = await sdk.client.provider.oauth.authorize({
|
||||
providerID: provider.id,
|
||||
method: index,
|
||||
inputs,
|
||||
})
|
||||
if (result.error) {
|
||||
toast.show({
|
||||
variant: "error",
|
||||
message: JSON.stringify(result.error),
|
||||
return {
|
||||
title: provider.name,
|
||||
value: provider.id,
|
||||
description: {
|
||||
opencode: "(Recommended)",
|
||||
anthropic: "(API key)",
|
||||
openai: "(ChatGPT Plus/Pro or API key)",
|
||||
"opencode-go": "Low cost subscription for everyone",
|
||||
}[provider.id],
|
||||
footer: consoleManaged ? sync.data.console_state.activeOrgName : undefined,
|
||||
category: provider.id in PROVIDER_PRIORITY ? "Popular" : "Other",
|
||||
gutter: consoleManaged ? (
|
||||
<text fg={theme.textMuted}>{CONSOLE_MANAGED_ICON}</text>
|
||||
) : connected ? (
|
||||
<text fg={theme.success}>✓</text>
|
||||
) : undefined,
|
||||
async onSelect() {
|
||||
if (consoleManaged) return
|
||||
|
||||
const methods = sync.data.provider_auth[provider.id] ?? [
|
||||
{
|
||||
type: "api",
|
||||
label: "API key",
|
||||
},
|
||||
]
|
||||
let index: number | null = 0
|
||||
if (methods.length > 1) {
|
||||
index = await new Promise<number | null>((resolve) => {
|
||||
dialog.replace(
|
||||
() => (
|
||||
<DialogSelect
|
||||
title="Select auth method"
|
||||
options={methods.map((x, index) => ({
|
||||
title: x.label,
|
||||
value: index,
|
||||
}))}
|
||||
onSelect={(option) => resolve(option.value)}
|
||||
/>
|
||||
),
|
||||
() => resolve(null),
|
||||
)
|
||||
})
|
||||
dialog.clear()
|
||||
return
|
||||
}
|
||||
if (result.data?.method === "code") {
|
||||
dialog.replace(() => (
|
||||
<CodeMethod providerID={provider.id} title={method.label} index={index} authorization={result.data!} />
|
||||
))
|
||||
if (index == null) return
|
||||
const method = methods[index]
|
||||
if (method.type === "oauth") {
|
||||
let inputs: Record<string, string> | undefined
|
||||
if (method.prompts?.length) {
|
||||
const value = await PromptsMethod({
|
||||
dialog,
|
||||
prompts: method.prompts,
|
||||
})
|
||||
if (!value) return
|
||||
inputs = value
|
||||
}
|
||||
|
||||
const result = await sdk.client.provider.oauth.authorize({
|
||||
providerID: provider.id,
|
||||
method: index,
|
||||
inputs,
|
||||
})
|
||||
if (result.error) {
|
||||
toast.show({
|
||||
variant: "error",
|
||||
message: JSON.stringify(result.error),
|
||||
})
|
||||
dialog.clear()
|
||||
return
|
||||
}
|
||||
if (result.data?.method === "code") {
|
||||
dialog.replace(() => (
|
||||
<CodeMethod
|
||||
providerID={provider.id}
|
||||
title={method.label}
|
||||
index={index}
|
||||
authorization={result.data!}
|
||||
/>
|
||||
))
|
||||
}
|
||||
if (result.data?.method === "auto") {
|
||||
dialog.replace(() => (
|
||||
<AutoMethod
|
||||
providerID={provider.id}
|
||||
title={method.label}
|
||||
index={index}
|
||||
authorization={result.data!}
|
||||
/>
|
||||
))
|
||||
}
|
||||
}
|
||||
if (result.data?.method === "auto") {
|
||||
dialog.replace(() => (
|
||||
<AutoMethod providerID={provider.id} title={method.label} index={index} authorization={result.data!} />
|
||||
))
|
||||
if (method.type === "api") {
|
||||
return dialog.replace(() => <ApiMethod providerID={provider.id} title={method.label} />)
|
||||
}
|
||||
}
|
||||
if (method.type === "api") {
|
||||
return dialog.replace(() => <ApiMethod providerID={provider.id} title={method.label} />)
|
||||
}
|
||||
},
|
||||
})),
|
||||
},
|
||||
}
|
||||
}),
|
||||
)
|
||||
})
|
||||
return options
|
||||
|
||||
@@ -35,6 +35,7 @@ import { useToast } from "../../ui/toast"
|
||||
import { useKV } from "../../context/kv"
|
||||
import { useTextareaKeybindings } from "../textarea-keybindings"
|
||||
import { DialogSkill } from "../dialog-skill"
|
||||
import { CONSOLE_MANAGED_ICON, consoleManagedProviderLabel } from "@tui/util/provider-origin"
|
||||
|
||||
export type PromptProps = {
|
||||
sessionID?: string
|
||||
@@ -94,6 +95,15 @@ export function Prompt(props: PromptProps) {
|
||||
const list = createMemo(() => props.placeholders?.normal ?? [])
|
||||
const shell = createMemo(() => props.placeholders?.shell ?? [])
|
||||
const [auto, setAuto] = createSignal<AutocompleteRef>()
|
||||
const activeOrgName = createMemo(() => sync.data.console_state.activeOrgName)
|
||||
const canSwitchOrgs = createMemo(() => sync.data.console_state.switchableOrgCount > 1)
|
||||
const currentProviderLabel = createMemo(() => {
|
||||
const current = local.model.current()
|
||||
const provider = local.model.parsed().provider
|
||||
if (!current) return provider
|
||||
return consoleManagedProviderLabel(sync.data.console_state.consoleManagedProviders, current.providerID, provider)
|
||||
})
|
||||
const hasRightContent = createMemo(() => Boolean(props.right || activeOrgName()))
|
||||
|
||||
function promptModelWarning() {
|
||||
toast.show({
|
||||
@@ -1095,7 +1105,7 @@ export function Prompt(props: PromptProps) {
|
||||
<text flexShrink={0} fg={keybind.leader ? theme.textMuted : theme.text}>
|
||||
{local.model.parsed().model}
|
||||
</text>
|
||||
<text fg={theme.textMuted}>{local.model.parsed().provider}</text>
|
||||
<text fg={theme.textMuted}>{currentProviderLabel()}</text>
|
||||
<Show when={showVariant()}>
|
||||
<text fg={theme.textMuted}>·</text>
|
||||
<text>
|
||||
@@ -1105,7 +1115,22 @@ export function Prompt(props: PromptProps) {
|
||||
</box>
|
||||
</Show>
|
||||
</box>
|
||||
{props.right}
|
||||
<Show when={hasRightContent()}>
|
||||
<box flexDirection="row" gap={1} alignItems="center">
|
||||
{props.right}
|
||||
<Show when={activeOrgName()}>
|
||||
<text
|
||||
fg={theme.textMuted}
|
||||
onMouseUp={() => {
|
||||
if (!canSwitchOrgs()) return
|
||||
command.trigger("console.org.switch")
|
||||
}}
|
||||
>
|
||||
{`${CONSOLE_MANAGED_ICON} ${activeOrgName()}`}
|
||||
</text>
|
||||
</Show>
|
||||
</box>
|
||||
</Show>
|
||||
</box>
|
||||
</box>
|
||||
</box>
|
||||
|
||||
@@ -29,6 +29,7 @@ import { batch, onMount } from "solid-js"
|
||||
import { Log } from "@/util/log"
|
||||
import type { Path } from "@opencode-ai/sdk"
|
||||
import type { Workspace } from "@opencode-ai/sdk/v2"
|
||||
import { ConsoleState, emptyConsoleState, type ConsoleState as ConsoleStateType } from "@/config/console-state"
|
||||
|
||||
export const { use: useSync, provider: SyncProvider } = createSimpleContext({
|
||||
name: "Sync",
|
||||
@@ -38,6 +39,7 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
|
||||
provider: Provider[]
|
||||
provider_default: Record<string, string>
|
||||
provider_next: ProviderListResponse
|
||||
console_state: ConsoleStateType
|
||||
provider_auth: Record<string, ProviderAuthMethod[]>
|
||||
agent: Agent[]
|
||||
command: Command[]
|
||||
@@ -81,6 +83,7 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
|
||||
default: {},
|
||||
connected: [],
|
||||
},
|
||||
console_state: emptyConsoleState,
|
||||
provider_auth: {},
|
||||
config: {},
|
||||
status: "loading",
|
||||
@@ -365,6 +368,10 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
|
||||
// blocking - include session.list when continuing a session
|
||||
const providersPromise = sdk.client.config.providers({}, { throwOnError: true })
|
||||
const providerListPromise = sdk.client.provider.list({}, { throwOnError: true })
|
||||
const consoleStatePromise = sdk.client.experimental.console
|
||||
.get({}, { throwOnError: true })
|
||||
.then((x) => ConsoleState.parse(x.data))
|
||||
.catch(() => emptyConsoleState)
|
||||
const agentsPromise = sdk.client.app.agents({}, { throwOnError: true })
|
||||
const configPromise = sdk.client.config.get({}, { throwOnError: true })
|
||||
const blockingRequests: Promise<unknown>[] = [
|
||||
@@ -379,6 +386,7 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
|
||||
.then(() => {
|
||||
const providersResponse = providersPromise.then((x) => x.data!)
|
||||
const providerListResponse = providerListPromise.then((x) => x.data!)
|
||||
const consoleStateResponse = consoleStatePromise
|
||||
const agentsResponse = agentsPromise.then((x) => x.data ?? [])
|
||||
const configResponse = configPromise.then((x) => x.data!)
|
||||
const sessionListResponse = args.continue ? sessionListPromise : undefined
|
||||
@@ -386,20 +394,23 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
|
||||
return Promise.all([
|
||||
providersResponse,
|
||||
providerListResponse,
|
||||
consoleStateResponse,
|
||||
agentsResponse,
|
||||
configResponse,
|
||||
...(sessionListResponse ? [sessionListResponse] : []),
|
||||
]).then((responses) => {
|
||||
const providers = responses[0]
|
||||
const providerList = responses[1]
|
||||
const agents = responses[2]
|
||||
const config = responses[3]
|
||||
const sessions = responses[4]
|
||||
const consoleState = responses[2]
|
||||
const agents = responses[3]
|
||||
const config = responses[4]
|
||||
const sessions = responses[5]
|
||||
|
||||
batch(() => {
|
||||
setStore("provider", reconcile(providers.providers))
|
||||
setStore("provider_default", reconcile(providers.default))
|
||||
setStore("provider_next", reconcile(providerList))
|
||||
setStore("console_state", reconcile(consoleState))
|
||||
setStore("agent", reconcile(agents))
|
||||
setStore("config", reconcile(config))
|
||||
if (sessions !== undefined) setStore("session", reconcile(sessions))
|
||||
@@ -411,6 +422,7 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
|
||||
// non-blocking
|
||||
Promise.all([
|
||||
...(args.continue ? [] : [sessionListPromise.then((sessions) => setStore("session", reconcile(sessions)))]),
|
||||
consoleStatePromise.then((consoleState) => setStore("console_state", reconcile(consoleState))),
|
||||
sdk.client.command.list().then((x) => setStore("command", reconcile(x.data ?? []))),
|
||||
sdk.client.lsp.status().then((x) => setStore("lsp", reconcile(x.data!))),
|
||||
sdk.client.mcp.status().then((x) => setStore("mcp", reconcile(x.data!))),
|
||||
|
||||
@@ -38,6 +38,7 @@ export interface DialogSelectOption<T = any> {
|
||||
description?: string
|
||||
footer?: JSX.Element | string
|
||||
category?: string
|
||||
categoryView?: JSX.Element
|
||||
disabled?: boolean
|
||||
bg?: RGBA
|
||||
gutter?: JSX.Element
|
||||
@@ -291,9 +292,16 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
|
||||
<>
|
||||
<Show when={category}>
|
||||
<box paddingTop={index() > 0 ? 1 : 0} paddingLeft={3}>
|
||||
<text fg={theme.accent} attributes={TextAttributes.BOLD}>
|
||||
{category}
|
||||
</text>
|
||||
<Show
|
||||
when={options[0]?.categoryView}
|
||||
fallback={
|
||||
<text fg={theme.accent} attributes={TextAttributes.BOLD}>
|
||||
{category}
|
||||
</text>
|
||||
}
|
||||
>
|
||||
{options[0]?.categoryView}
|
||||
</Show>
|
||||
</box>
|
||||
</Show>
|
||||
<For each={options}>
|
||||
|
||||
20
packages/opencode/src/cli/cmd/tui/util/provider-origin.ts
Normal file
20
packages/opencode/src/cli/cmd/tui/util/provider-origin.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
export const CONSOLE_MANAGED_ICON = "⌂"
|
||||
|
||||
const contains = (consoleManagedProviders: string[] | ReadonlySet<string>, providerID: string) =>
|
||||
Array.isArray(consoleManagedProviders)
|
||||
? consoleManagedProviders.includes(providerID)
|
||||
: consoleManagedProviders.has(providerID)
|
||||
|
||||
export const isConsoleManagedProvider = (consoleManagedProviders: string[] | ReadonlySet<string>, providerID: string) =>
|
||||
contains(consoleManagedProviders, providerID)
|
||||
|
||||
export const consoleManagedProviderSuffix = (
|
||||
consoleManagedProviders: string[] | ReadonlySet<string>,
|
||||
providerID: string,
|
||||
) => (contains(consoleManagedProviders, providerID) ? ` ${CONSOLE_MANAGED_ICON}` : "")
|
||||
|
||||
export const consoleManagedProviderLabel = (
|
||||
consoleManagedProviders: string[] | ReadonlySet<string>,
|
||||
providerID: string,
|
||||
providerName: string,
|
||||
) => `${providerName}${consoleManagedProviderSuffix(consoleManagedProviders, providerID)}`
|
||||
@@ -33,6 +33,7 @@ import { Account } from "@/account"
|
||||
import { isRecord } from "@/util/record"
|
||||
import { ConfigPaths } from "./paths"
|
||||
import { Filesystem } from "@/util/filesystem"
|
||||
import type { ConsoleState } from "./console-state"
|
||||
import { AppFileSystem } from "@/filesystem"
|
||||
import { InstanceState } from "@/effect/instance-state"
|
||||
import { makeRuntime } from "@/effect/run-service"
|
||||
@@ -1050,11 +1051,13 @@ export namespace Config {
|
||||
config: Info
|
||||
directories: string[]
|
||||
deps: Promise<void>[]
|
||||
consoleState: ConsoleState
|
||||
}
|
||||
|
||||
export interface Interface {
|
||||
readonly get: () => Effect.Effect<Info>
|
||||
readonly getGlobal: () => Effect.Effect<Info>
|
||||
readonly getConsoleState: () => Effect.Effect<ConsoleState>
|
||||
readonly update: (config: Info) => Effect.Effect<void>
|
||||
readonly updateGlobal: (config: Info) => Effect.Effect<Info>
|
||||
readonly invalidate: (wait?: boolean) => Effect.Effect<void>
|
||||
@@ -1260,6 +1263,8 @@ export namespace Config {
|
||||
const auth = yield* authSvc.all().pipe(Effect.orDie)
|
||||
|
||||
let result: Info = {}
|
||||
const consoleManagedProviders = new Set<string>()
|
||||
let activeOrgName: string | undefined
|
||||
|
||||
const scope = (source: string): PluginScope => {
|
||||
if (source.startsWith("http://") || source.startsWith("https://")) return "global"
|
||||
@@ -1371,26 +1376,31 @@ export namespace Config {
|
||||
log.debug("loaded custom config from OPENCODE_CONFIG_CONTENT")
|
||||
}
|
||||
|
||||
const active = Option.getOrUndefined(yield* accountSvc.active().pipe(Effect.orDie))
|
||||
if (active?.active_org_id) {
|
||||
const activeOrg = Option.getOrUndefined(
|
||||
yield* accountSvc.activeOrg().pipe(Effect.catch(() => Effect.succeed(Option.none()))),
|
||||
)
|
||||
if (activeOrg) {
|
||||
yield* Effect.gen(function* () {
|
||||
const [configOpt, tokenOpt] = yield* Effect.all(
|
||||
[accountSvc.config(active.id, active.active_org_id!), accountSvc.token(active.id)],
|
||||
[accountSvc.config(activeOrg.account.id, activeOrg.org.id), accountSvc.token(activeOrg.account.id)],
|
||||
{ concurrency: 2 },
|
||||
)
|
||||
const token = Option.getOrUndefined(tokenOpt)
|
||||
if (token) {
|
||||
process.env["OPENCODE_CONSOLE_TOKEN"] = token
|
||||
Env.set("OPENCODE_CONSOLE_TOKEN", token)
|
||||
if (Option.isSome(tokenOpt)) {
|
||||
process.env["OPENCODE_CONSOLE_TOKEN"] = tokenOpt.value
|
||||
Env.set("OPENCODE_CONSOLE_TOKEN", tokenOpt.value)
|
||||
}
|
||||
|
||||
const config = Option.getOrUndefined(configOpt)
|
||||
if (config) {
|
||||
const source = `${active.url}/api/config`
|
||||
const next = yield* loadConfig(JSON.stringify(config), {
|
||||
activeOrgName = activeOrg.org.name
|
||||
|
||||
if (Option.isSome(configOpt)) {
|
||||
const source = `${activeOrg.account.url}/api/config`
|
||||
const next = yield* loadConfig(JSON.stringify(configOpt.value), {
|
||||
dir: path.dirname(source),
|
||||
source,
|
||||
})
|
||||
for (const providerID of Object.keys(next.provider ?? {})) {
|
||||
consoleManagedProviders.add(providerID)
|
||||
}
|
||||
merge(source, next, "global")
|
||||
}
|
||||
}).pipe(
|
||||
@@ -1456,6 +1466,11 @@ export namespace Config {
|
||||
config: result,
|
||||
directories,
|
||||
deps,
|
||||
consoleState: {
|
||||
consoleManagedProviders: Array.from(consoleManagedProviders),
|
||||
activeOrgName,
|
||||
switchableOrgCount: 0,
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1473,6 +1488,10 @@ export namespace Config {
|
||||
return yield* InstanceState.use(state, (s) => s.directories)
|
||||
})
|
||||
|
||||
const getConsoleState = Effect.fn("Config.getConsoleState")(function* () {
|
||||
return yield* InstanceState.use(state, (s) => s.consoleState)
|
||||
})
|
||||
|
||||
const waitForDependencies = Effect.fn("Config.waitForDependencies")(function* () {
|
||||
yield* InstanceState.useEffect(state, (s) => Effect.promise(() => Promise.all(s.deps).then(() => undefined)))
|
||||
})
|
||||
@@ -1528,6 +1547,7 @@ export namespace Config {
|
||||
return Service.of({
|
||||
get,
|
||||
getGlobal,
|
||||
getConsoleState,
|
||||
update,
|
||||
updateGlobal,
|
||||
invalidate,
|
||||
@@ -1553,6 +1573,10 @@ export namespace Config {
|
||||
return runPromise((svc) => svc.getGlobal())
|
||||
}
|
||||
|
||||
export async function getConsoleState() {
|
||||
return runPromise((svc) => svc.getConsoleState())
|
||||
}
|
||||
|
||||
export async function update(config: Info) {
|
||||
return runPromise((svc) => svc.update(config))
|
||||
}
|
||||
|
||||
15
packages/opencode/src/config/console-state.ts
Normal file
15
packages/opencode/src/config/console-state.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import z from "zod"
|
||||
|
||||
export const ConsoleState = z.object({
|
||||
consoleManagedProviders: z.array(z.string()),
|
||||
activeOrgName: z.string().optional(),
|
||||
switchableOrgCount: z.number().int().nonnegative(),
|
||||
})
|
||||
|
||||
export type ConsoleState = z.infer<typeof ConsoleState>
|
||||
|
||||
export const emptyConsoleState: ConsoleState = {
|
||||
consoleManagedProviders: [],
|
||||
activeOrgName: undefined,
|
||||
switchableOrgCount: 0,
|
||||
}
|
||||
@@ -188,13 +188,23 @@ export namespace AppFileSystem {
|
||||
|
||||
export function normalizePath(p: string): string {
|
||||
if (process.platform !== "win32") return p
|
||||
const resolved = pathResolve(windowsPath(p))
|
||||
try {
|
||||
return realpathSync.native(p)
|
||||
return realpathSync.native(resolved)
|
||||
} catch {
|
||||
return p
|
||||
return resolved
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizePathPattern(p: string): string {
|
||||
if (process.platform !== "win32") return p
|
||||
if (p === "*") return p
|
||||
const match = p.match(/^(.*)[\\/]\*$/)
|
||||
if (!match) return normalizePath(p)
|
||||
const dir = /^[A-Za-z]:$/.test(match[1]) ? match[1] + "\\" : match[1]
|
||||
return join(normalizePath(dir), "*")
|
||||
}
|
||||
|
||||
export function resolve(p: string): string {
|
||||
const resolved = pathResolve(windowsPath(p))
|
||||
try {
|
||||
|
||||
@@ -67,6 +67,7 @@ export namespace Npm {
|
||||
binLinks: true,
|
||||
progress: false,
|
||||
savePrefix: "",
|
||||
ignoreScripts: true,
|
||||
})
|
||||
const tree = await arborist.loadVirtual().catch(() => {})
|
||||
if (tree) {
|
||||
@@ -106,6 +107,7 @@ export namespace Npm {
|
||||
binLinks: true,
|
||||
progress: false,
|
||||
savePrefix: "",
|
||||
ignoreScripts: true,
|
||||
})
|
||||
await arb.reify().catch(() => {})
|
||||
}
|
||||
|
||||
@@ -8,13 +8,116 @@ import { Instance } from "../../project/instance"
|
||||
import { Project } from "../../project/project"
|
||||
import { MCP } from "../../mcp"
|
||||
import { Session } from "../../session"
|
||||
import { Config } from "../../config/config"
|
||||
import { ConsoleState } from "../../config/console-state"
|
||||
import { Account, AccountID, OrgID } from "../../account"
|
||||
import { zodToJsonSchema } from "zod-to-json-schema"
|
||||
import { errors } from "../error"
|
||||
import { lazy } from "../../util/lazy"
|
||||
import { WorkspaceRoutes } from "./workspace"
|
||||
|
||||
const ConsoleOrgOption = z.object({
|
||||
accountID: z.string(),
|
||||
accountEmail: z.string(),
|
||||
accountUrl: z.string(),
|
||||
orgID: z.string(),
|
||||
orgName: z.string(),
|
||||
active: z.boolean(),
|
||||
})
|
||||
|
||||
const ConsoleOrgList = z.object({
|
||||
orgs: z.array(ConsoleOrgOption),
|
||||
})
|
||||
|
||||
const ConsoleSwitchBody = z.object({
|
||||
accountID: z.string(),
|
||||
orgID: z.string(),
|
||||
})
|
||||
|
||||
export const ExperimentalRoutes = lazy(() =>
|
||||
new Hono()
|
||||
.get(
|
||||
"/console",
|
||||
describeRoute({
|
||||
summary: "Get active Console provider metadata",
|
||||
description: "Get the active Console org name and the set of provider IDs managed by that Console org.",
|
||||
operationId: "experimental.console.get",
|
||||
responses: {
|
||||
200: {
|
||||
description: "Active Console provider metadata",
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: resolver(ConsoleState),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
const [consoleState, groups] = await Promise.all([Config.getConsoleState(), Account.orgsByAccount()])
|
||||
return c.json({
|
||||
...consoleState,
|
||||
switchableOrgCount: groups.reduce((count, group) => count + group.orgs.length, 0),
|
||||
})
|
||||
},
|
||||
)
|
||||
.get(
|
||||
"/console/orgs",
|
||||
describeRoute({
|
||||
summary: "List switchable Console orgs",
|
||||
description: "Get the available Console orgs across logged-in accounts, including the current active org.",
|
||||
operationId: "experimental.console.listOrgs",
|
||||
responses: {
|
||||
200: {
|
||||
description: "Switchable Console orgs",
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: resolver(ConsoleOrgList),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
const [groups, active] = await Promise.all([Account.orgsByAccount(), Account.active()])
|
||||
|
||||
const orgs = groups.flatMap((group) =>
|
||||
group.orgs.map((org) => ({
|
||||
accountID: group.account.id,
|
||||
accountEmail: group.account.email,
|
||||
accountUrl: group.account.url,
|
||||
orgID: org.id,
|
||||
orgName: org.name,
|
||||
active: !!active && active.id === group.account.id && active.active_org_id === org.id,
|
||||
})),
|
||||
)
|
||||
return c.json({ orgs })
|
||||
},
|
||||
)
|
||||
.post(
|
||||
"/console/switch",
|
||||
describeRoute({
|
||||
summary: "Switch active Console org",
|
||||
description: "Persist a new active Console account/org selection for the current local OpenCode state.",
|
||||
operationId: "experimental.console.switchOrg",
|
||||
responses: {
|
||||
200: {
|
||||
description: "Switch success",
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: resolver(z.boolean()),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
validator("json", ConsoleSwitchBody),
|
||||
async (c) => {
|
||||
const body = c.req.valid("json")
|
||||
await Account.switchOrg(AccountID.make(body.accountID), OrgID.make(body.orgID))
|
||||
return c.json(true)
|
||||
},
|
||||
)
|
||||
.get(
|
||||
"/tool/ids",
|
||||
describeRoute({
|
||||
|
||||
@@ -278,7 +278,7 @@ export namespace Session {
|
||||
const tokens = {
|
||||
total,
|
||||
input: adjustedInputTokens,
|
||||
output: outputTokens,
|
||||
output: outputTokens - reasoningTokens,
|
||||
reasoning: reasoningTokens,
|
||||
cache: {
|
||||
write: cacheWriteInputTokens,
|
||||
|
||||
@@ -82,25 +82,6 @@ If the `AGENTS.md` is empty or insufficient, you may check `README`/`README.md`
|
||||
|
||||
If you modified any files/styles/structures/configurations/workflows/... mentioned in `AGENTS.md` files, you MUST update the corresponding `AGENTS.md` files to keep them up-to-date.
|
||||
|
||||
# Skills
|
||||
|
||||
Skills are reusable, composable capabilities that enhance your abilities. Each skill is a self-contained directory with a `SKILL.md` file that contains instructions, examples, and/or reference material.
|
||||
|
||||
## What are skills?
|
||||
|
||||
Skills are modular extensions that provide:
|
||||
|
||||
- Specialized knowledge: Domain-specific expertise (e.g., PDF processing, data analysis)
|
||||
- Workflow patterns: Best practices for common tasks
|
||||
- Tool integrations: Pre-configured tool chains for specific operations
|
||||
- Reference material: Documentation, templates, and examples
|
||||
|
||||
## How to use skills
|
||||
|
||||
Identify the skills that are likely to be useful for the tasks you are currently working on, use the `skill` tool to load a skill for detailed instructions, guidelines, scripts and more.
|
||||
|
||||
Only load skill details when needed to conserve the context window.
|
||||
|
||||
# Ultimate Reminders
|
||||
|
||||
At any time, you should be HELPFUL, CONCISE, and ACCURATE. Be thorough in your actions — test what you build, verify what you change — not in your explanations.
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import path from "path"
|
||||
import { Effect } from "effect"
|
||||
import type { Tool } from "./tool"
|
||||
import { Instance } from "../project/instance"
|
||||
import { Filesystem } from "@/util/filesystem"
|
||||
import { AppFileSystem } from "../filesystem"
|
||||
|
||||
type Kind = "file" | "directory"
|
||||
|
||||
@@ -15,14 +16,14 @@ export async function assertExternalDirectory(ctx: Tool.Context, target?: string
|
||||
|
||||
if (options?.bypass) return
|
||||
|
||||
const full = process.platform === "win32" ? Filesystem.normalizePath(target) : target
|
||||
const full = process.platform === "win32" ? AppFileSystem.normalizePath(target) : target
|
||||
if (Instance.containsPath(full)) return
|
||||
|
||||
const kind = options?.kind ?? "file"
|
||||
const dir = kind === "directory" ? full : path.dirname(full)
|
||||
const glob =
|
||||
process.platform === "win32"
|
||||
? Filesystem.normalizePathPattern(path.join(dir, "*"))
|
||||
? AppFileSystem.normalizePathPattern(path.join(dir, "*"))
|
||||
: path.join(dir, "*").replaceAll("\\", "/")
|
||||
|
||||
await ctx.ask({
|
||||
@@ -35,3 +36,11 @@ export async function assertExternalDirectory(ctx: Tool.Context, target?: string
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const assertExternalDirectoryEffect = Effect.fn("Tool.assertExternalDirectory")(function* (
|
||||
ctx: Tool.Context,
|
||||
target?: string,
|
||||
options?: Options,
|
||||
) {
|
||||
yield* Effect.promise(() => assertExternalDirectory(ctx, target, options))
|
||||
})
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
import z from "zod"
|
||||
import { Effect, Scope } from "effect"
|
||||
import { createReadStream } from "fs"
|
||||
import * as fs from "fs/promises"
|
||||
import { open } from "fs/promises"
|
||||
import * as path from "path"
|
||||
import { createInterface } from "readline"
|
||||
import { Tool } from "./tool"
|
||||
import { AppFileSystem } from "../filesystem"
|
||||
import { LSP } from "../lsp"
|
||||
import { FileTime } from "../file/time"
|
||||
import DESCRIPTION from "./read.txt"
|
||||
import { Instance } from "../project/instance"
|
||||
import { assertExternalDirectory } from "./external-directory"
|
||||
import { assertExternalDirectoryEffect } from "./external-directory"
|
||||
import { Instruction } from "../session/instruction"
|
||||
import { Filesystem } from "../util/filesystem"
|
||||
|
||||
const DEFAULT_READ_LIMIT = 2000
|
||||
const MAX_LINE_LENGTH = 2000
|
||||
@@ -18,222 +19,257 @@ const MAX_LINE_SUFFIX = `... (line truncated to ${MAX_LINE_LENGTH} chars)`
|
||||
const MAX_BYTES = 50 * 1024
|
||||
const MAX_BYTES_LABEL = `${MAX_BYTES / 1024} KB`
|
||||
|
||||
export const ReadTool = Tool.define("read", {
|
||||
description: DESCRIPTION,
|
||||
parameters: z.object({
|
||||
filePath: z.string().describe("The absolute path to the file or directory to read"),
|
||||
offset: z.coerce.number().describe("The line number to start reading from (1-indexed)").optional(),
|
||||
limit: z.coerce.number().describe("The maximum number of lines to read (defaults to 2000)").optional(),
|
||||
}),
|
||||
async execute(params, ctx) {
|
||||
if (params.offset !== undefined && params.offset < 1) {
|
||||
throw new Error("offset must be greater than or equal to 1")
|
||||
}
|
||||
let filepath = params.filePath
|
||||
if (!path.isAbsolute(filepath)) {
|
||||
filepath = path.resolve(Instance.directory, filepath)
|
||||
}
|
||||
if (process.platform === "win32") {
|
||||
filepath = Filesystem.normalizePath(filepath)
|
||||
}
|
||||
const title = path.relative(Instance.worktree, filepath)
|
||||
const parameters = z.object({
|
||||
filePath: z.string().describe("The absolute path to the file or directory to read"),
|
||||
offset: z.coerce.number().describe("The line number to start reading from (1-indexed)").optional(),
|
||||
limit: z.coerce.number().describe("The maximum number of lines to read (defaults to 2000)").optional(),
|
||||
})
|
||||
|
||||
const stat = Filesystem.stat(filepath)
|
||||
export const ReadTool = Tool.defineEffect(
|
||||
"read",
|
||||
Effect.gen(function* () {
|
||||
const fs = yield* AppFileSystem.Service
|
||||
const instruction = yield* Instruction.Service
|
||||
const lsp = yield* LSP.Service
|
||||
const time = yield* FileTime.Service
|
||||
const scope = yield* Scope.Scope
|
||||
|
||||
await assertExternalDirectory(ctx, filepath, {
|
||||
bypass: Boolean(ctx.extra?.["bypassCwdCheck"]),
|
||||
kind: stat?.isDirectory() ? "directory" : "file",
|
||||
})
|
||||
|
||||
await ctx.ask({
|
||||
permission: "read",
|
||||
patterns: [filepath],
|
||||
always: ["*"],
|
||||
metadata: {},
|
||||
})
|
||||
|
||||
if (!stat) {
|
||||
const miss = Effect.fn("ReadTool.miss")(function* (filepath: string) {
|
||||
const dir = path.dirname(filepath)
|
||||
const base = path.basename(filepath)
|
||||
|
||||
const suggestions = await fs
|
||||
.readdir(dir)
|
||||
.then((entries) =>
|
||||
entries
|
||||
const items = yield* fs.readDirectory(dir).pipe(
|
||||
Effect.map((items) =>
|
||||
items
|
||||
.filter(
|
||||
(entry) =>
|
||||
entry.toLowerCase().includes(base.toLowerCase()) || base.toLowerCase().includes(entry.toLowerCase()),
|
||||
(item) =>
|
||||
item.toLowerCase().includes(base.toLowerCase()) || base.toLowerCase().includes(item.toLowerCase()),
|
||||
)
|
||||
.map((entry) => path.join(dir, entry))
|
||||
.map((item) => path.join(dir, item))
|
||||
.slice(0, 3),
|
||||
)
|
||||
.catch(() => [])
|
||||
),
|
||||
Effect.catch(() => Effect.succeed([] as string[])),
|
||||
)
|
||||
|
||||
if (suggestions.length > 0) {
|
||||
throw new Error(`File not found: ${filepath}\n\nDid you mean one of these?\n${suggestions.join("\n")}`)
|
||||
if (items.length > 0) {
|
||||
return yield* Effect.fail(
|
||||
new Error(`File not found: ${filepath}\n\nDid you mean one of these?\n${items.join("\n")}`),
|
||||
)
|
||||
}
|
||||
|
||||
throw new Error(`File not found: ${filepath}`)
|
||||
}
|
||||
return yield* Effect.fail(new Error(`File not found: ${filepath}`))
|
||||
})
|
||||
|
||||
if (stat.isDirectory()) {
|
||||
const dirents = await fs.readdir(filepath, { withFileTypes: true })
|
||||
const entries = await Promise.all(
|
||||
dirents.map(async (dirent) => {
|
||||
if (dirent.isDirectory()) return dirent.name + "/"
|
||||
if (dirent.isSymbolicLink()) {
|
||||
const target = await fs.stat(path.join(filepath, dirent.name)).catch(() => undefined)
|
||||
if (target?.isDirectory()) return dirent.name + "/"
|
||||
}
|
||||
return dirent.name
|
||||
const list = Effect.fn("ReadTool.list")(function* (filepath: string) {
|
||||
const items = yield* fs.readDirectoryEntries(filepath)
|
||||
return yield* Effect.forEach(
|
||||
items,
|
||||
Effect.fnUntraced(function* (item) {
|
||||
if (item.type === "directory") return item.name + "/"
|
||||
if (item.type !== "symlink") return item.name
|
||||
|
||||
const target = yield* fs
|
||||
.stat(path.join(filepath, item.name))
|
||||
.pipe(Effect.catch(() => Effect.succeed(undefined)))
|
||||
if (target?.type === "Directory") return item.name + "/"
|
||||
return item.name
|
||||
}),
|
||||
{ concurrency: "unbounded" },
|
||||
).pipe(Effect.map((items: string[]) => items.sort((a, b) => a.localeCompare(b))))
|
||||
})
|
||||
|
||||
const warm = Effect.fn("ReadTool.warm")(function* (filepath: string, sessionID: Tool.Context["sessionID"]) {
|
||||
yield* lsp.touchFile(filepath, false).pipe(Effect.ignore, Effect.forkIn(scope))
|
||||
yield* time.read(sessionID, filepath)
|
||||
})
|
||||
|
||||
const run = Effect.fn("ReadTool.execute")(function* (params: z.infer<typeof parameters>, ctx: Tool.Context) {
|
||||
if (params.offset !== undefined && params.offset < 1) {
|
||||
return yield* Effect.fail(new Error("offset must be greater than or equal to 1"))
|
||||
}
|
||||
|
||||
let filepath = params.filePath
|
||||
if (!path.isAbsolute(filepath)) {
|
||||
filepath = path.resolve(Instance.directory, filepath)
|
||||
}
|
||||
if (process.platform === "win32") {
|
||||
filepath = AppFileSystem.normalizePath(filepath)
|
||||
}
|
||||
const title = path.relative(Instance.worktree, filepath)
|
||||
|
||||
const stat = yield* fs.stat(filepath).pipe(
|
||||
Effect.catchIf(
|
||||
(err) => "reason" in err && err.reason._tag === "NotFound",
|
||||
() => Effect.succeed(undefined),
|
||||
),
|
||||
)
|
||||
|
||||
yield* assertExternalDirectoryEffect(ctx, filepath, {
|
||||
bypass: Boolean(ctx.extra?.["bypassCwdCheck"]),
|
||||
kind: stat?.type === "Directory" ? "directory" : "file",
|
||||
})
|
||||
|
||||
yield* Effect.promise(() =>
|
||||
ctx.ask({
|
||||
permission: "read",
|
||||
patterns: [filepath],
|
||||
always: ["*"],
|
||||
metadata: {},
|
||||
}),
|
||||
)
|
||||
entries.sort((a, b) => a.localeCompare(b))
|
||||
|
||||
const limit = params.limit ?? DEFAULT_READ_LIMIT
|
||||
const offset = params.offset ?? 1
|
||||
const start = offset - 1
|
||||
const sliced = entries.slice(start, start + limit)
|
||||
const truncated = start + sliced.length < entries.length
|
||||
if (!stat) return yield* miss(filepath)
|
||||
|
||||
const output = [
|
||||
`<path>${filepath}</path>`,
|
||||
`<type>directory</type>`,
|
||||
`<entries>`,
|
||||
sliced.join("\n"),
|
||||
truncated
|
||||
? `\n(Showing ${sliced.length} of ${entries.length} entries. Use 'offset' parameter to read beyond entry ${offset + sliced.length})`
|
||||
: `\n(${entries.length} entries)`,
|
||||
`</entries>`,
|
||||
].join("\n")
|
||||
if (stat.type === "Directory") {
|
||||
const items = yield* list(filepath)
|
||||
const limit = params.limit ?? DEFAULT_READ_LIMIT
|
||||
const offset = params.offset ?? 1
|
||||
const start = offset - 1
|
||||
const sliced = items.slice(start, start + limit)
|
||||
const truncated = start + sliced.length < items.length
|
||||
|
||||
return {
|
||||
title,
|
||||
output: [
|
||||
`<path>${filepath}</path>`,
|
||||
`<type>directory</type>`,
|
||||
`<entries>`,
|
||||
sliced.join("\n"),
|
||||
truncated
|
||||
? `\n(Showing ${sliced.length} of ${items.length} entries. Use 'offset' parameter to read beyond entry ${offset + sliced.length})`
|
||||
: `\n(${items.length} entries)`,
|
||||
`</entries>`,
|
||||
].join("\n"),
|
||||
metadata: {
|
||||
preview: sliced.slice(0, 20).join("\n"),
|
||||
truncated,
|
||||
loaded: [] as string[],
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
const loaded = yield* instruction.resolve(ctx.messages, filepath, ctx.messageID)
|
||||
|
||||
const mime = AppFileSystem.mimeType(filepath)
|
||||
const isImage = mime.startsWith("image/") && mime !== "image/svg+xml" && mime !== "image/vnd.fastbidsheet"
|
||||
const isPdf = mime === "application/pdf"
|
||||
if (isImage || isPdf) {
|
||||
const msg = `${isImage ? "Image" : "PDF"} read successfully`
|
||||
return {
|
||||
title,
|
||||
output: msg,
|
||||
metadata: {
|
||||
preview: msg,
|
||||
truncated: false,
|
||||
loaded: loaded.map((item) => item.filepath),
|
||||
},
|
||||
attachments: [
|
||||
{
|
||||
type: "file" as const,
|
||||
mime,
|
||||
url: `data:${mime};base64,${Buffer.from(yield* fs.readFile(filepath)).toString("base64")}`,
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
if (yield* Effect.promise(() => isBinaryFile(filepath, Number(stat.size)))) {
|
||||
return yield* Effect.fail(new Error(`Cannot read binary file: ${filepath}`))
|
||||
}
|
||||
|
||||
const file = yield* Effect.promise(() =>
|
||||
lines(filepath, { limit: params.limit ?? DEFAULT_READ_LIMIT, offset: params.offset ?? 1 }),
|
||||
)
|
||||
if (file.count < file.offset && !(file.count === 0 && file.offset === 1)) {
|
||||
return yield* Effect.fail(
|
||||
new Error(`Offset ${file.offset} is out of range for this file (${file.count} lines)`),
|
||||
)
|
||||
}
|
||||
|
||||
let output = [`<path>${filepath}</path>`, `<type>file</type>`, "<content>" + "\n"].join("\n")
|
||||
output += file.raw.map((line, i) => `${i + file.offset}: ${line}`).join("\n")
|
||||
|
||||
const last = file.offset + file.raw.length - 1
|
||||
const next = last + 1
|
||||
const truncated = file.more || file.cut
|
||||
if (file.cut) {
|
||||
output += `\n\n(Output capped at ${MAX_BYTES_LABEL}. Showing lines ${file.offset}-${last}. Use offset=${next} to continue.)`
|
||||
} else if (file.more) {
|
||||
output += `\n\n(Showing lines ${file.offset}-${last} of ${file.count}. Use offset=${next} to continue.)`
|
||||
} else {
|
||||
output += `\n\n(End of file - total ${file.count} lines)`
|
||||
}
|
||||
output += "\n</content>"
|
||||
|
||||
yield* warm(filepath, ctx.sessionID)
|
||||
|
||||
if (loaded.length > 0) {
|
||||
output += `\n\n<system-reminder>\n${loaded.map((item) => item.content).join("\n\n")}\n</system-reminder>`
|
||||
}
|
||||
|
||||
return {
|
||||
title,
|
||||
output,
|
||||
metadata: {
|
||||
preview: sliced.slice(0, 20).join("\n"),
|
||||
preview: file.raw.slice(0, 20).join("\n"),
|
||||
truncated,
|
||||
loaded: [] as string[],
|
||||
loaded: loaded.map((item) => item.filepath),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
const instructions = await Instruction.resolve(ctx.messages, filepath, ctx.messageID)
|
||||
|
||||
// Exclude SVG (XML-based) and vnd.fastbidsheet (.fbs extension, commonly FlatBuffers schema files)
|
||||
const mime = Filesystem.mimeType(filepath)
|
||||
const isImage = mime.startsWith("image/") && mime !== "image/svg+xml" && mime !== "image/vnd.fastbidsheet"
|
||||
const isPdf = mime === "application/pdf"
|
||||
if (isImage || isPdf) {
|
||||
const msg = `${isImage ? "Image" : "PDF"} read successfully`
|
||||
return {
|
||||
title,
|
||||
output: msg,
|
||||
metadata: {
|
||||
preview: msg,
|
||||
truncated: false,
|
||||
loaded: instructions.map((i) => i.filepath),
|
||||
},
|
||||
attachments: [
|
||||
{
|
||||
type: "file",
|
||||
mime,
|
||||
url: `data:${mime};base64,${Buffer.from(await Filesystem.readBytes(filepath)).toString("base64")}`,
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
const isBinary = await isBinaryFile(filepath, Number(stat.size))
|
||||
if (isBinary) throw new Error(`Cannot read binary file: ${filepath}`)
|
||||
|
||||
const stream = createReadStream(filepath, { encoding: "utf8" })
|
||||
const rl = createInterface({
|
||||
input: stream,
|
||||
// Note: we use the crlfDelay option to recognize all instances of CR LF
|
||||
// ('\r\n') in file as a single line break.
|
||||
crlfDelay: Infinity,
|
||||
})
|
||||
|
||||
const limit = params.limit ?? DEFAULT_READ_LIMIT
|
||||
const offset = params.offset ?? 1
|
||||
const start = offset - 1
|
||||
const raw: string[] = []
|
||||
let bytes = 0
|
||||
let lines = 0
|
||||
let truncatedByBytes = false
|
||||
let hasMoreLines = false
|
||||
try {
|
||||
for await (const text of rl) {
|
||||
lines += 1
|
||||
if (lines <= start) continue
|
||||
|
||||
if (raw.length >= limit) {
|
||||
hasMoreLines = true
|
||||
continue
|
||||
}
|
||||
|
||||
const line = text.length > MAX_LINE_LENGTH ? text.substring(0, MAX_LINE_LENGTH) + MAX_LINE_SUFFIX : text
|
||||
const size = Buffer.byteLength(line, "utf-8") + (raw.length > 0 ? 1 : 0)
|
||||
if (bytes + size > MAX_BYTES) {
|
||||
truncatedByBytes = true
|
||||
hasMoreLines = true
|
||||
break
|
||||
}
|
||||
|
||||
raw.push(line)
|
||||
bytes += size
|
||||
}
|
||||
} finally {
|
||||
rl.close()
|
||||
stream.destroy()
|
||||
}
|
||||
|
||||
if (lines < offset && !(lines === 0 && offset === 1)) {
|
||||
throw new Error(`Offset ${offset} is out of range for this file (${lines} lines)`)
|
||||
}
|
||||
|
||||
const content = raw.map((line, index) => {
|
||||
return `${index + offset}: ${line}`
|
||||
})
|
||||
const preview = raw.slice(0, 20).join("\n")
|
||||
|
||||
let output = [`<path>${filepath}</path>`, `<type>file</type>`, "<content>"].join("\n")
|
||||
output += content.join("\n")
|
||||
|
||||
const totalLines = lines
|
||||
const lastReadLine = offset + raw.length - 1
|
||||
const nextOffset = lastReadLine + 1
|
||||
const truncated = hasMoreLines || truncatedByBytes
|
||||
|
||||
if (truncatedByBytes) {
|
||||
output += `\n\n(Output capped at ${MAX_BYTES_LABEL}. Showing lines ${offset}-${lastReadLine}. Use offset=${nextOffset} to continue.)`
|
||||
} else if (hasMoreLines) {
|
||||
output += `\n\n(Showing lines ${offset}-${lastReadLine} of ${totalLines}. Use offset=${nextOffset} to continue.)`
|
||||
} else {
|
||||
output += `\n\n(End of file - total ${totalLines} lines)`
|
||||
}
|
||||
output += "\n</content>"
|
||||
|
||||
// just warms the lsp client
|
||||
LSP.touchFile(filepath, false)
|
||||
await FileTime.read(ctx.sessionID, filepath)
|
||||
|
||||
if (instructions.length > 0) {
|
||||
output += `\n\n<system-reminder>\n${instructions.map((i) => i.content).join("\n\n")}\n</system-reminder>`
|
||||
}
|
||||
|
||||
return {
|
||||
title,
|
||||
output,
|
||||
metadata: {
|
||||
preview,
|
||||
truncated,
|
||||
loaded: instructions.map((i) => i.filepath),
|
||||
description: DESCRIPTION,
|
||||
parameters,
|
||||
async execute(params: z.infer<typeof parameters>, ctx) {
|
||||
return Effect.runPromise(run(params, ctx).pipe(Effect.orDie))
|
||||
},
|
||||
}
|
||||
},
|
||||
})
|
||||
}),
|
||||
)
|
||||
|
||||
async function lines(filepath: string, opts: { limit: number; offset: number }) {
|
||||
const stream = createReadStream(filepath, { encoding: "utf8" })
|
||||
const rl = createInterface({
|
||||
input: stream,
|
||||
// Note: we use the crlfDelay option to recognize all instances of CR LF
|
||||
// ('\r\n') in file as a single line break.
|
||||
crlfDelay: Infinity,
|
||||
})
|
||||
|
||||
const start = opts.offset - 1
|
||||
const raw: string[] = []
|
||||
let bytes = 0
|
||||
let count = 0
|
||||
let cut = false
|
||||
let more = false
|
||||
try {
|
||||
for await (const text of rl) {
|
||||
count += 1
|
||||
if (count <= start) continue
|
||||
|
||||
if (raw.length >= opts.limit) {
|
||||
more = true
|
||||
continue
|
||||
}
|
||||
|
||||
const line = text.length > MAX_LINE_LENGTH ? text.substring(0, MAX_LINE_LENGTH) + MAX_LINE_SUFFIX : text
|
||||
const size = Buffer.byteLength(line, "utf-8") + (raw.length > 0 ? 1 : 0)
|
||||
if (bytes + size > MAX_BYTES) {
|
||||
cut = true
|
||||
more = true
|
||||
break
|
||||
}
|
||||
|
||||
raw.push(line)
|
||||
bytes += size
|
||||
}
|
||||
} finally {
|
||||
rl.close()
|
||||
stream.destroy()
|
||||
}
|
||||
|
||||
return { raw, count, cut, more, offset: opts.offset }
|
||||
}
|
||||
|
||||
async function isBinaryFile(filepath: string, fileSize: number): Promise<boolean> {
|
||||
const ext = path.extname(filepath).toLowerCase()
|
||||
@@ -274,7 +310,7 @@ async function isBinaryFile(filepath: string, fileSize: number): Promise<boolean
|
||||
|
||||
if (fileSize === 0) return false
|
||||
|
||||
const fh = await fs.open(filepath, "r")
|
||||
const fh = await open(filepath, "r")
|
||||
try {
|
||||
const sampleSize = Math.min(4096, fileSize)
|
||||
const bytes = Buffer.alloc(sampleSize)
|
||||
|
||||
@@ -35,6 +35,10 @@ import { makeRuntime } from "@/effect/run-service"
|
||||
import { Env } from "../env"
|
||||
import { Question } from "../question"
|
||||
import { Todo } from "../session/todo"
|
||||
import { LSP } from "../lsp"
|
||||
import { FileTime } from "../file/time"
|
||||
import { Instruction } from "../session/instruction"
|
||||
import { AppFileSystem } from "../filesystem"
|
||||
|
||||
export namespace ToolRegistry {
|
||||
const log = Log.create({ service: "tool.registry" })
|
||||
@@ -57,167 +61,176 @@ export namespace ToolRegistry {
|
||||
|
||||
export class Service extends ServiceMap.Service<Service, Interface>()("@opencode/ToolRegistry") {}
|
||||
|
||||
export const layer: Layer.Layer<Service, never, Config.Service | Plugin.Service | Question.Service | Todo.Service> =
|
||||
Layer.effect(
|
||||
Service,
|
||||
Effect.gen(function* () {
|
||||
const config = yield* Config.Service
|
||||
const plugin = yield* Plugin.Service
|
||||
export const layer: Layer.Layer<
|
||||
Service,
|
||||
never,
|
||||
| Config.Service
|
||||
| Plugin.Service
|
||||
| Question.Service
|
||||
| Todo.Service
|
||||
| LSP.Service
|
||||
| FileTime.Service
|
||||
| Instruction.Service
|
||||
| AppFileSystem.Service
|
||||
> = Layer.effect(
|
||||
Service,
|
||||
Effect.gen(function* () {
|
||||
const config = yield* Config.Service
|
||||
const plugin = yield* Plugin.Service
|
||||
|
||||
const build = <T extends Tool.Info>(tool: T | Effect.Effect<T, never, any>) =>
|
||||
Effect.isEffect(tool) ? tool : Effect.succeed(tool)
|
||||
const build = <T extends Tool.Info>(tool: T | Effect.Effect<T, never, any>) =>
|
||||
Effect.isEffect(tool) ? tool : Effect.succeed(tool)
|
||||
|
||||
const state = yield* InstanceState.make<State>(
|
||||
Effect.fn("ToolRegistry.state")(function* (ctx) {
|
||||
const custom: Tool.Info[] = []
|
||||
const state = yield* InstanceState.make<State>(
|
||||
Effect.fn("ToolRegistry.state")(function* (ctx) {
|
||||
const custom: Tool.Info[] = []
|
||||
|
||||
function fromPlugin(id: string, def: ToolDefinition): Tool.Info {
|
||||
return {
|
||||
id,
|
||||
init: async (initCtx) => ({
|
||||
parameters: z.object(def.args),
|
||||
description: def.description,
|
||||
execute: async (args, toolCtx) => {
|
||||
const pluginCtx = {
|
||||
...toolCtx,
|
||||
directory: ctx.directory,
|
||||
worktree: ctx.worktree,
|
||||
} as unknown as PluginToolContext
|
||||
const result = await def.execute(args as any, pluginCtx)
|
||||
const out = await Truncate.output(result, {}, initCtx?.agent)
|
||||
return {
|
||||
title: "",
|
||||
output: out.truncated ? out.content : result,
|
||||
metadata: { truncated: out.truncated, outputPath: out.truncated ? out.outputPath : undefined },
|
||||
}
|
||||
},
|
||||
}),
|
||||
}
|
||||
function fromPlugin(id: string, def: ToolDefinition): Tool.Info {
|
||||
return {
|
||||
id,
|
||||
init: async (initCtx) => ({
|
||||
parameters: z.object(def.args),
|
||||
description: def.description,
|
||||
execute: async (args, toolCtx) => {
|
||||
const pluginCtx = {
|
||||
...toolCtx,
|
||||
directory: ctx.directory,
|
||||
worktree: ctx.worktree,
|
||||
} as unknown as PluginToolContext
|
||||
const result = await def.execute(args as any, pluginCtx)
|
||||
const out = await Truncate.output(result, {}, initCtx?.agent)
|
||||
return {
|
||||
title: "",
|
||||
output: out.truncated ? out.content : result,
|
||||
metadata: { truncated: out.truncated, outputPath: out.truncated ? out.outputPath : undefined },
|
||||
}
|
||||
},
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
const dirs = yield* config.directories()
|
||||
const matches = dirs.flatMap((dir) =>
|
||||
Glob.scanSync("{tool,tools}/*.{js,ts}", { cwd: dir, absolute: true, dot: true, symlink: true }),
|
||||
)
|
||||
if (matches.length) yield* config.waitForDependencies()
|
||||
for (const match of matches) {
|
||||
const namespace = path.basename(match, path.extname(match))
|
||||
const mod = yield* Effect.promise(
|
||||
() => import(process.platform === "win32" ? match : pathToFileURL(match).href),
|
||||
)
|
||||
for (const [id, def] of Object.entries<ToolDefinition>(mod)) {
|
||||
custom.push(fromPlugin(id === "default" ? namespace : `${namespace}_${id}`, def))
|
||||
}
|
||||
}
|
||||
|
||||
const plugins = yield* plugin.list()
|
||||
for (const p of plugins) {
|
||||
for (const [id, def] of Object.entries(p.tool ?? {})) {
|
||||
custom.push(fromPlugin(id, def))
|
||||
}
|
||||
}
|
||||
|
||||
return { custom }
|
||||
}),
|
||||
)
|
||||
|
||||
const invalid = yield* build(InvalidTool)
|
||||
const ask = yield* build(QuestionTool)
|
||||
const bash = yield* build(BashTool)
|
||||
const read = yield* build(ReadTool)
|
||||
const glob = yield* build(GlobTool)
|
||||
const grep = yield* build(GrepTool)
|
||||
const edit = yield* build(EditTool)
|
||||
const write = yield* build(WriteTool)
|
||||
const task = yield* build(TaskTool)
|
||||
const fetch = yield* build(WebFetchTool)
|
||||
const todo = yield* build(TodoWriteTool)
|
||||
const search = yield* build(WebSearchTool)
|
||||
const code = yield* build(CodeSearchTool)
|
||||
const skill = yield* build(SkillTool)
|
||||
const patch = yield* build(ApplyPatchTool)
|
||||
const lsp = yield* build(LspTool)
|
||||
const batch = yield* build(BatchTool)
|
||||
const plan = yield* build(PlanExitTool)
|
||||
|
||||
const all = Effect.fn("ToolRegistry.all")(function* (custom: Tool.Info[]) {
|
||||
const cfg = yield* config.get()
|
||||
const question =
|
||||
["app", "cli", "desktop"].includes(Flag.OPENCODE_CLIENT) || Flag.OPENCODE_ENABLE_QUESTION_TOOL
|
||||
|
||||
return [
|
||||
invalid,
|
||||
...(question ? [ask] : []),
|
||||
bash,
|
||||
read,
|
||||
glob,
|
||||
grep,
|
||||
edit,
|
||||
write,
|
||||
task,
|
||||
fetch,
|
||||
todo,
|
||||
search,
|
||||
code,
|
||||
skill,
|
||||
patch,
|
||||
...(Flag.OPENCODE_EXPERIMENTAL_LSP_TOOL ? [lsp] : []),
|
||||
...(cfg.experimental?.batch_tool === true ? [batch] : []),
|
||||
...(Flag.OPENCODE_EXPERIMENTAL_PLAN_MODE && Flag.OPENCODE_CLIENT === "cli" ? [plan] : []),
|
||||
...custom,
|
||||
]
|
||||
})
|
||||
|
||||
const ids = Effect.fn("ToolRegistry.ids")(function* () {
|
||||
const s = yield* InstanceState.get(state)
|
||||
const tools = yield* all(s.custom)
|
||||
return tools.map((t) => t.id)
|
||||
})
|
||||
|
||||
const tools = Effect.fn("ToolRegistry.tools")(function* (
|
||||
model: { providerID: ProviderID; modelID: ModelID },
|
||||
agent?: Agent.Info,
|
||||
) {
|
||||
const s = yield* InstanceState.get(state)
|
||||
const allTools = yield* all(s.custom)
|
||||
const filtered = allTools.filter((tool) => {
|
||||
if (tool.id === "codesearch" || tool.id === "websearch") {
|
||||
return model.providerID === ProviderID.opencode || Flag.OPENCODE_ENABLE_EXA
|
||||
}
|
||||
|
||||
const usePatch =
|
||||
!!Env.get("OPENCODE_E2E_LLM_URL") ||
|
||||
(model.modelID.includes("gpt-") && !model.modelID.includes("oss") && !model.modelID.includes("gpt-4"))
|
||||
if (tool.id === "apply_patch") return usePatch
|
||||
if (tool.id === "edit" || tool.id === "write") return !usePatch
|
||||
|
||||
return true
|
||||
})
|
||||
return yield* Effect.forEach(
|
||||
filtered,
|
||||
Effect.fnUntraced(function* (tool: Tool.Info) {
|
||||
using _ = log.time(tool.id)
|
||||
const next = yield* Effect.promise(() => tool.init({ agent }))
|
||||
const output = {
|
||||
description: next.description,
|
||||
parameters: next.parameters,
|
||||
}
|
||||
yield* plugin.trigger("tool.definition", { toolID: tool.id }, output)
|
||||
return {
|
||||
id: tool.id,
|
||||
description: output.description,
|
||||
parameters: output.parameters,
|
||||
execute: next.execute,
|
||||
formatValidationError: next.formatValidationError,
|
||||
}
|
||||
}),
|
||||
{ concurrency: "unbounded" },
|
||||
const dirs = yield* config.directories()
|
||||
const matches = dirs.flatMap((dir) =>
|
||||
Glob.scanSync("{tool,tools}/*.{js,ts}", { cwd: dir, absolute: true, dot: true, symlink: true }),
|
||||
)
|
||||
})
|
||||
if (matches.length) yield* config.waitForDependencies()
|
||||
for (const match of matches) {
|
||||
const namespace = path.basename(match, path.extname(match))
|
||||
const mod = yield* Effect.promise(
|
||||
() => import(process.platform === "win32" ? match : pathToFileURL(match).href),
|
||||
)
|
||||
for (const [id, def] of Object.entries<ToolDefinition>(mod)) {
|
||||
custom.push(fromPlugin(id === "default" ? namespace : `${namespace}_${id}`, def))
|
||||
}
|
||||
}
|
||||
|
||||
return Service.of({ ids, named: { task, read }, tools })
|
||||
}),
|
||||
)
|
||||
const plugins = yield* plugin.list()
|
||||
for (const p of plugins) {
|
||||
for (const [id, def] of Object.entries(p.tool ?? {})) {
|
||||
custom.push(fromPlugin(id, def))
|
||||
}
|
||||
}
|
||||
|
||||
return { custom }
|
||||
}),
|
||||
)
|
||||
|
||||
const invalid = yield* build(InvalidTool)
|
||||
const ask = yield* build(QuestionTool)
|
||||
const bash = yield* build(BashTool)
|
||||
const read = yield* build(ReadTool)
|
||||
const glob = yield* build(GlobTool)
|
||||
const grep = yield* build(GrepTool)
|
||||
const edit = yield* build(EditTool)
|
||||
const write = yield* build(WriteTool)
|
||||
const task = yield* build(TaskTool)
|
||||
const fetch = yield* build(WebFetchTool)
|
||||
const todo = yield* build(TodoWriteTool)
|
||||
const search = yield* build(WebSearchTool)
|
||||
const code = yield* build(CodeSearchTool)
|
||||
const skill = yield* build(SkillTool)
|
||||
const patch = yield* build(ApplyPatchTool)
|
||||
const lsp = yield* build(LspTool)
|
||||
const batch = yield* build(BatchTool)
|
||||
const plan = yield* build(PlanExitTool)
|
||||
|
||||
const all = Effect.fn("ToolRegistry.all")(function* (custom: Tool.Info[]) {
|
||||
const cfg = yield* config.get()
|
||||
const question = ["app", "cli", "desktop"].includes(Flag.OPENCODE_CLIENT) || Flag.OPENCODE_ENABLE_QUESTION_TOOL
|
||||
|
||||
return [
|
||||
invalid,
|
||||
...(question ? [ask] : []),
|
||||
bash,
|
||||
read,
|
||||
glob,
|
||||
grep,
|
||||
edit,
|
||||
write,
|
||||
task,
|
||||
fetch,
|
||||
todo,
|
||||
search,
|
||||
code,
|
||||
skill,
|
||||
patch,
|
||||
...(Flag.OPENCODE_EXPERIMENTAL_LSP_TOOL ? [lsp] : []),
|
||||
...(cfg.experimental?.batch_tool === true ? [batch] : []),
|
||||
...(Flag.OPENCODE_EXPERIMENTAL_PLAN_MODE && Flag.OPENCODE_CLIENT === "cli" ? [plan] : []),
|
||||
...custom,
|
||||
]
|
||||
})
|
||||
|
||||
const ids = Effect.fn("ToolRegistry.ids")(function* () {
|
||||
const s = yield* InstanceState.get(state)
|
||||
const tools = yield* all(s.custom)
|
||||
return tools.map((t) => t.id)
|
||||
})
|
||||
|
||||
const tools = Effect.fn("ToolRegistry.tools")(function* (
|
||||
model: { providerID: ProviderID; modelID: ModelID },
|
||||
agent?: Agent.Info,
|
||||
) {
|
||||
const s = yield* InstanceState.get(state)
|
||||
const allTools = yield* all(s.custom)
|
||||
const filtered = allTools.filter((tool) => {
|
||||
if (tool.id === "codesearch" || tool.id === "websearch") {
|
||||
return model.providerID === ProviderID.opencode || Flag.OPENCODE_ENABLE_EXA
|
||||
}
|
||||
|
||||
const usePatch =
|
||||
!!Env.get("OPENCODE_E2E_LLM_URL") ||
|
||||
(model.modelID.includes("gpt-") && !model.modelID.includes("oss") && !model.modelID.includes("gpt-4"))
|
||||
if (tool.id === "apply_patch") return usePatch
|
||||
if (tool.id === "edit" || tool.id === "write") return !usePatch
|
||||
|
||||
return true
|
||||
})
|
||||
return yield* Effect.forEach(
|
||||
filtered,
|
||||
Effect.fnUntraced(function* (tool: Tool.Info) {
|
||||
using _ = log.time(tool.id)
|
||||
const next = yield* Effect.promise(() => tool.init({ agent }))
|
||||
const output = {
|
||||
description: next.description,
|
||||
parameters: next.parameters,
|
||||
}
|
||||
yield* plugin.trigger("tool.definition", { toolID: tool.id }, output)
|
||||
return {
|
||||
id: tool.id,
|
||||
description: output.description,
|
||||
parameters: output.parameters,
|
||||
execute: next.execute,
|
||||
formatValidationError: next.formatValidationError,
|
||||
}
|
||||
}),
|
||||
{ concurrency: "unbounded" },
|
||||
)
|
||||
})
|
||||
|
||||
return Service.of({ ids, named: { task, read }, tools })
|
||||
}),
|
||||
)
|
||||
|
||||
export const defaultLayer = Layer.unwrap(
|
||||
Effect.sync(() =>
|
||||
@@ -226,6 +239,10 @@ export namespace ToolRegistry {
|
||||
Layer.provide(Plugin.defaultLayer),
|
||||
Layer.provide(Question.defaultLayer),
|
||||
Layer.provide(Todo.defaultLayer),
|
||||
Layer.provide(LSP.defaultLayer),
|
||||
Layer.provide(FileTime.defaultLayer),
|
||||
Layer.provide(Instruction.defaultLayer),
|
||||
Layer.provide(AppFileSystem.defaultLayer),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -25,6 +25,7 @@ import { Npm } from "../../src/npm"
|
||||
|
||||
const emptyAccount = Layer.mock(Account.Service)({
|
||||
active: () => Effect.succeed(Option.none()),
|
||||
activeOrg: () => Effect.succeed(Option.none()),
|
||||
})
|
||||
|
||||
const emptyAuth = Layer.mock(Auth.Service)({
|
||||
@@ -282,6 +283,21 @@ test("resolves env templates in account config with account token", async () =>
|
||||
active_org_id: OrgID.make("org-1"),
|
||||
}),
|
||||
),
|
||||
activeOrg: () =>
|
||||
Effect.succeed(
|
||||
Option.some({
|
||||
account: {
|
||||
id: AccountID.make("account-1"),
|
||||
email: "user@example.com",
|
||||
url: "https://control.example.com",
|
||||
active_org_id: OrgID.make("org-1"),
|
||||
},
|
||||
org: {
|
||||
id: OrgID.make("org-1"),
|
||||
name: "Example Org",
|
||||
},
|
||||
}),
|
||||
),
|
||||
config: () =>
|
||||
Effect.succeed(
|
||||
Option.some({
|
||||
|
||||
@@ -1080,7 +1080,7 @@ describe("session.getUsage", () => {
|
||||
expect(result.tokens.cache.read).toBe(200)
|
||||
})
|
||||
|
||||
test("handles reasoning tokens", () => {
|
||||
test("separates reasoning tokens from output tokens", () => {
|
||||
const model = createModel({ context: 100_000, output: 32_000 })
|
||||
const result = Session.getUsage({
|
||||
model,
|
||||
@@ -1092,7 +1092,35 @@ describe("session.getUsage", () => {
|
||||
},
|
||||
})
|
||||
|
||||
expect(result.tokens.input).toBe(1000)
|
||||
expect(result.tokens.output).toBe(400)
|
||||
expect(result.tokens.reasoning).toBe(100)
|
||||
expect(result.tokens.total).toBe(1500)
|
||||
})
|
||||
|
||||
test("does not double count reasoning tokens in cost", () => {
|
||||
const model = createModel({
|
||||
context: 100_000,
|
||||
output: 32_000,
|
||||
cost: {
|
||||
input: 0,
|
||||
output: 15,
|
||||
cache: { read: 0, write: 0 },
|
||||
},
|
||||
})
|
||||
const result = Session.getUsage({
|
||||
model,
|
||||
usage: {
|
||||
inputTokens: 0,
|
||||
outputTokens: 1_000_000,
|
||||
totalTokens: 1_000_000,
|
||||
reasoningTokens: 250_000,
|
||||
},
|
||||
})
|
||||
|
||||
expect(result.tokens.output).toBe(750_000)
|
||||
expect(result.tokens.reasoning).toBe(250_000)
|
||||
expect(result.cost).toBe(15)
|
||||
})
|
||||
|
||||
test("handles undefined optional values gracefully", () => {
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
import { afterEach, describe, expect, test } from "bun:test"
|
||||
import { afterEach, describe, expect } from "bun:test"
|
||||
import { Cause, Effect, Exit, Layer } from "effect"
|
||||
import path from "path"
|
||||
import { ReadTool } from "../../src/tool/read"
|
||||
import { Instance } from "../../src/project/instance"
|
||||
import { Filesystem } from "../../src/util/filesystem"
|
||||
import { tmpdir } from "../fixture/fixture"
|
||||
import { Permission } from "../../src/permission"
|
||||
import { Agent } from "../../src/agent/agent"
|
||||
import * as CrossSpawnSpawner from "../../src/effect/cross-spawn-spawner"
|
||||
import { AppFileSystem } from "../../src/filesystem"
|
||||
import { FileTime } from "../../src/file/time"
|
||||
import { LSP } from "../../src/lsp"
|
||||
import { Permission } from "../../src/permission"
|
||||
import { Instance } from "../../src/project/instance"
|
||||
import { SessionID, MessageID } from "../../src/session/schema"
|
||||
import { Instruction } from "../../src/session/instruction"
|
||||
import { ReadTool } from "../../src/tool/read"
|
||||
import { Tool } from "../../src/tool/tool"
|
||||
import { Filesystem } from "../../src/util/filesystem"
|
||||
import { provideInstance, tmpdirScoped } from "../fixture/fixture"
|
||||
import { testEffect } from "../lib/effect"
|
||||
|
||||
const FIXTURES_DIR = path.join(import.meta.dir, "fixtures")
|
||||
|
||||
@@ -25,173 +33,171 @@ const ctx = {
|
||||
ask: async () => {},
|
||||
}
|
||||
|
||||
const it = testEffect(
|
||||
Layer.mergeAll(
|
||||
Agent.defaultLayer,
|
||||
AppFileSystem.defaultLayer,
|
||||
CrossSpawnSpawner.defaultLayer,
|
||||
FileTime.defaultLayer,
|
||||
Instruction.defaultLayer,
|
||||
LSP.defaultLayer,
|
||||
),
|
||||
)
|
||||
|
||||
const init = Effect.fn("ReadToolTest.init")(function* () {
|
||||
const info = yield* ReadTool
|
||||
return yield* Effect.promise(() => info.init())
|
||||
})
|
||||
|
||||
const run = Effect.fn("ReadToolTest.run")(function* (
|
||||
args: Tool.InferParameters<typeof ReadTool>,
|
||||
next: Tool.Context = ctx,
|
||||
) {
|
||||
const tool = yield* init()
|
||||
return yield* Effect.promise(() => tool.execute(args, next))
|
||||
})
|
||||
|
||||
const exec = Effect.fn("ReadToolTest.exec")(function* (
|
||||
dir: string,
|
||||
args: Tool.InferParameters<typeof ReadTool>,
|
||||
next: Tool.Context = ctx,
|
||||
) {
|
||||
return yield* provideInstance(dir)(run(args, next))
|
||||
})
|
||||
|
||||
const fail = Effect.fn("ReadToolTest.fail")(function* (
|
||||
dir: string,
|
||||
args: Tool.InferParameters<typeof ReadTool>,
|
||||
next: Tool.Context = ctx,
|
||||
) {
|
||||
const exit = yield* exec(dir, args, next).pipe(Effect.exit)
|
||||
if (Exit.isFailure(exit)) {
|
||||
const err = Cause.squash(exit.cause)
|
||||
return err instanceof Error ? err : new Error(String(err))
|
||||
}
|
||||
throw new Error("expected read to fail")
|
||||
})
|
||||
|
||||
const full = (p: string) => (process.platform === "win32" ? Filesystem.normalizePath(p) : p)
|
||||
const glob = (p: string) =>
|
||||
process.platform === "win32" ? Filesystem.normalizePathPattern(p) : p.replaceAll("\\", "/")
|
||||
const put = Effect.fn("ReadToolTest.put")(function* (p: string, content: string | Buffer | Uint8Array) {
|
||||
const fs = yield* AppFileSystem.Service
|
||||
yield* fs.writeWithDirs(p, content)
|
||||
})
|
||||
const load = Effect.fn("ReadToolTest.load")(function* (p: string) {
|
||||
const fs = yield* AppFileSystem.Service
|
||||
return yield* fs.readFileString(p)
|
||||
})
|
||||
const asks = () => {
|
||||
const items: Array<Omit<Permission.Request, "id" | "sessionID" | "tool">> = []
|
||||
return {
|
||||
items,
|
||||
next: {
|
||||
...ctx,
|
||||
ask: async (req: Omit<Permission.Request, "id" | "sessionID" | "tool">) => {
|
||||
items.push(req)
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
describe("tool.read external_directory permission", () => {
|
||||
test("allows reading absolute path inside project directory", async () => {
|
||||
await using tmp = await tmpdir({
|
||||
init: async (dir) => {
|
||||
await Bun.write(path.join(dir, "test.txt"), "hello world")
|
||||
},
|
||||
})
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const read = await ReadTool.init()
|
||||
const result = await read.execute({ filePath: path.join(tmp.path, "test.txt") }, ctx)
|
||||
expect(result.output).toContain("hello world")
|
||||
},
|
||||
})
|
||||
})
|
||||
it.live("allows reading absolute path inside project directory", () =>
|
||||
Effect.gen(function* () {
|
||||
const dir = yield* tmpdirScoped()
|
||||
yield* put(path.join(dir, "test.txt"), "hello world")
|
||||
|
||||
test("allows reading file in subdirectory inside project directory", async () => {
|
||||
await using tmp = await tmpdir({
|
||||
init: async (dir) => {
|
||||
await Bun.write(path.join(dir, "subdir", "test.txt"), "nested content")
|
||||
},
|
||||
})
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const read = await ReadTool.init()
|
||||
const result = await read.execute({ filePath: path.join(tmp.path, "subdir", "test.txt") }, ctx)
|
||||
expect(result.output).toContain("nested content")
|
||||
},
|
||||
})
|
||||
})
|
||||
const result = yield* exec(dir, { filePath: path.join(dir, "test.txt") })
|
||||
expect(result.output).toContain("hello world")
|
||||
}),
|
||||
)
|
||||
|
||||
test("asks for external_directory permission when reading absolute path outside project", async () => {
|
||||
await using outerTmp = await tmpdir({
|
||||
init: async (dir) => {
|
||||
await Bun.write(path.join(dir, "secret.txt"), "secret data")
|
||||
},
|
||||
})
|
||||
await using tmp = await tmpdir({ git: true })
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const read = await ReadTool.init()
|
||||
const requests: Array<Omit<Permission.Request, "id" | "sessionID" | "tool">> = []
|
||||
const testCtx = {
|
||||
...ctx,
|
||||
ask: async (req: Omit<Permission.Request, "id" | "sessionID" | "tool">) => {
|
||||
requests.push(req)
|
||||
},
|
||||
}
|
||||
await read.execute({ filePath: path.join(outerTmp.path, "secret.txt") }, testCtx)
|
||||
const extDirReq = requests.find((r) => r.permission === "external_directory")
|
||||
expect(extDirReq).toBeDefined()
|
||||
expect(extDirReq!.patterns).toContain(glob(path.join(outerTmp.path, "*")))
|
||||
},
|
||||
})
|
||||
})
|
||||
it.live("allows reading file in subdirectory inside project directory", () =>
|
||||
Effect.gen(function* () {
|
||||
const dir = yield* tmpdirScoped()
|
||||
yield* put(path.join(dir, "subdir", "test.txt"), "nested content")
|
||||
|
||||
const result = yield* exec(dir, { filePath: path.join(dir, "subdir", "test.txt") })
|
||||
expect(result.output).toContain("nested content")
|
||||
}),
|
||||
)
|
||||
|
||||
it.live("asks for external_directory permission when reading absolute path outside project", () =>
|
||||
Effect.gen(function* () {
|
||||
const outer = yield* tmpdirScoped()
|
||||
const dir = yield* tmpdirScoped({ git: true })
|
||||
yield* put(path.join(outer, "secret.txt"), "secret data")
|
||||
|
||||
const { items, next } = asks()
|
||||
|
||||
yield* exec(dir, { filePath: path.join(outer, "secret.txt") }, next)
|
||||
const ext = items.find((item) => item.permission === "external_directory")
|
||||
expect(ext).toBeDefined()
|
||||
expect(ext!.patterns).toContain(glob(path.join(outer, "*")))
|
||||
}),
|
||||
)
|
||||
|
||||
if (process.platform === "win32") {
|
||||
test("normalizes read permission paths on Windows", async () => {
|
||||
await using tmp = await tmpdir({
|
||||
git: true,
|
||||
init: async (dir) => {
|
||||
await Bun.write(path.join(dir, "test.txt"), "hello world")
|
||||
},
|
||||
})
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const read = await ReadTool.init()
|
||||
const requests: Array<Omit<Permission.Request, "id" | "sessionID" | "tool">> = []
|
||||
const testCtx = {
|
||||
...ctx,
|
||||
ask: async (req: Omit<Permission.Request, "id" | "sessionID" | "tool">) => {
|
||||
requests.push(req)
|
||||
},
|
||||
}
|
||||
const target = path.join(tmp.path, "test.txt")
|
||||
const alt = target
|
||||
.replace(/^[A-Za-z]:/, "")
|
||||
.replaceAll("\\", "/")
|
||||
.toLowerCase()
|
||||
await read.execute({ filePath: alt }, testCtx)
|
||||
const readReq = requests.find((r) => r.permission === "read")
|
||||
expect(readReq).toBeDefined()
|
||||
expect(readReq!.patterns).toEqual([full(target)])
|
||||
},
|
||||
})
|
||||
})
|
||||
it.live("normalizes read permission paths on Windows", () =>
|
||||
Effect.gen(function* () {
|
||||
const dir = yield* tmpdirScoped({ git: true })
|
||||
yield* put(path.join(dir, "test.txt"), "hello world")
|
||||
|
||||
const { items, next } = asks()
|
||||
const target = path.join(dir, "test.txt")
|
||||
const alt = target
|
||||
.replace(/^[A-Za-z]:/, "")
|
||||
.replaceAll("\\", "/")
|
||||
.toLowerCase()
|
||||
|
||||
yield* exec(dir, { filePath: alt }, next)
|
||||
const read = items.find((item) => item.permission === "read")
|
||||
expect(read).toBeDefined()
|
||||
expect(read!.patterns).toEqual([full(target)])
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
test("asks for directory-scoped external_directory permission when reading external directory", async () => {
|
||||
await using outerTmp = await tmpdir({
|
||||
init: async (dir) => {
|
||||
await Bun.write(path.join(dir, "external", "a.txt"), "a")
|
||||
},
|
||||
})
|
||||
await using tmp = await tmpdir({ git: true })
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const read = await ReadTool.init()
|
||||
const requests: Array<Omit<Permission.Request, "id" | "sessionID" | "tool">> = []
|
||||
const testCtx = {
|
||||
...ctx,
|
||||
ask: async (req: Omit<Permission.Request, "id" | "sessionID" | "tool">) => {
|
||||
requests.push(req)
|
||||
},
|
||||
}
|
||||
await read.execute({ filePath: path.join(outerTmp.path, "external") }, testCtx)
|
||||
const extDirReq = requests.find((r) => r.permission === "external_directory")
|
||||
expect(extDirReq).toBeDefined()
|
||||
expect(extDirReq!.patterns).toContain(glob(path.join(outerTmp.path, "external", "*")))
|
||||
},
|
||||
})
|
||||
})
|
||||
it.live("asks for directory-scoped external_directory permission when reading external directory", () =>
|
||||
Effect.gen(function* () {
|
||||
const outer = yield* tmpdirScoped()
|
||||
const dir = yield* tmpdirScoped({ git: true })
|
||||
yield* put(path.join(outer, "external", "a.txt"), "a")
|
||||
|
||||
test("asks for external_directory permission when reading relative path outside project", async () => {
|
||||
await using tmp = await tmpdir({ git: true })
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const read = await ReadTool.init()
|
||||
const requests: Array<Omit<Permission.Request, "id" | "sessionID" | "tool">> = []
|
||||
const testCtx = {
|
||||
...ctx,
|
||||
ask: async (req: Omit<Permission.Request, "id" | "sessionID" | "tool">) => {
|
||||
requests.push(req)
|
||||
},
|
||||
}
|
||||
// This will fail because file doesn't exist, but we can check if permission was asked
|
||||
await read.execute({ filePath: "../outside.txt" }, testCtx).catch(() => {})
|
||||
const extDirReq = requests.find((r) => r.permission === "external_directory")
|
||||
expect(extDirReq).toBeDefined()
|
||||
},
|
||||
})
|
||||
})
|
||||
const { items, next } = asks()
|
||||
|
||||
test("does not ask for external_directory permission when reading inside project", async () => {
|
||||
await using tmp = await tmpdir({
|
||||
git: true,
|
||||
init: async (dir) => {
|
||||
await Bun.write(path.join(dir, "internal.txt"), "internal content")
|
||||
},
|
||||
})
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const read = await ReadTool.init()
|
||||
const requests: Array<Omit<Permission.Request, "id" | "sessionID" | "tool">> = []
|
||||
const testCtx = {
|
||||
...ctx,
|
||||
ask: async (req: Omit<Permission.Request, "id" | "sessionID" | "tool">) => {
|
||||
requests.push(req)
|
||||
},
|
||||
}
|
||||
await read.execute({ filePath: path.join(tmp.path, "internal.txt") }, testCtx)
|
||||
const extDirReq = requests.find((r) => r.permission === "external_directory")
|
||||
expect(extDirReq).toBeUndefined()
|
||||
},
|
||||
})
|
||||
})
|
||||
yield* exec(dir, { filePath: path.join(outer, "external") }, next)
|
||||
const ext = items.find((item) => item.permission === "external_directory")
|
||||
expect(ext).toBeDefined()
|
||||
expect(ext!.patterns).toContain(glob(path.join(outer, "external", "*")))
|
||||
}),
|
||||
)
|
||||
|
||||
it.live("asks for external_directory permission when reading relative path outside project", () =>
|
||||
Effect.gen(function* () {
|
||||
const dir = yield* tmpdirScoped({ git: true })
|
||||
|
||||
const { items, next } = asks()
|
||||
|
||||
yield* fail(dir, { filePath: "../outside.txt" }, next)
|
||||
const ext = items.find((item) => item.permission === "external_directory")
|
||||
expect(ext).toBeDefined()
|
||||
}),
|
||||
)
|
||||
|
||||
it.live("does not ask for external_directory permission when reading inside project", () =>
|
||||
Effect.gen(function* () {
|
||||
const dir = yield* tmpdirScoped({ git: true })
|
||||
yield* put(path.join(dir, "internal.txt"), "internal content")
|
||||
|
||||
const { items, next } = asks()
|
||||
|
||||
yield* exec(dir, { filePath: path.join(dir, "internal.txt") }, next)
|
||||
const ext = items.find((item) => item.permission === "external_directory")
|
||||
expect(ext).toBeUndefined()
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
describe("tool.read env file permissions", () => {
|
||||
@@ -205,261 +211,204 @@ describe("tool.read env file permissions", () => {
|
||||
["environment.ts", false],
|
||||
]
|
||||
|
||||
describe.each(["build", "plan"])("agent=%s", (agentName) => {
|
||||
test.each(cases)("%s asks=%s", async (filename, shouldAsk) => {
|
||||
await using tmp = await tmpdir({
|
||||
init: (dir) => Bun.write(path.join(dir, filename), "content"),
|
||||
})
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const agent = await Agent.get(agentName)
|
||||
let askedForEnv = false
|
||||
const ctxWithPermissions = {
|
||||
...ctx,
|
||||
ask: async (req: Omit<Permission.Request, "id" | "sessionID" | "tool">) => {
|
||||
for (const pattern of req.patterns) {
|
||||
const rule = Permission.evaluate(req.permission, pattern, agent.permission)
|
||||
if (rule.action === "ask" && req.permission === "read") {
|
||||
askedForEnv = true
|
||||
for (const agentName of ["build", "plan"] as const) {
|
||||
describe(`agent=${agentName}`, () => {
|
||||
for (const [filename, shouldAsk] of cases) {
|
||||
it.live(`${filename} asks=${shouldAsk}`, () =>
|
||||
Effect.gen(function* () {
|
||||
const dir = yield* tmpdirScoped()
|
||||
yield* put(path.join(dir, filename), "content")
|
||||
|
||||
const asked = yield* provideInstance(dir)(
|
||||
Effect.gen(function* () {
|
||||
const agent = yield* Agent.Service
|
||||
const info = yield* agent.get(agentName)
|
||||
let asked = false
|
||||
const next = {
|
||||
...ctx,
|
||||
ask: async (req: Omit<Permission.Request, "id" | "sessionID" | "tool">) => {
|
||||
for (const pattern of req.patterns) {
|
||||
const rule = Permission.evaluate(req.permission, pattern, info.permission)
|
||||
if (rule.action === "ask" && req.permission === "read") {
|
||||
asked = true
|
||||
}
|
||||
if (rule.action === "deny") {
|
||||
throw new Permission.DeniedError({ ruleset: info.permission })
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
if (rule.action === "deny") {
|
||||
throw new Permission.DeniedError({ ruleset: agent.permission })
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
const read = await ReadTool.init()
|
||||
await read.execute({ filePath: path.join(tmp.path, filename) }, ctxWithPermissions)
|
||||
expect(askedForEnv).toBe(shouldAsk)
|
||||
},
|
||||
})
|
||||
|
||||
yield* run({ filePath: path.join(dir, filename) }, next)
|
||||
return asked
|
||||
}),
|
||||
)
|
||||
|
||||
expect(asked).toBe(shouldAsk)
|
||||
}),
|
||||
)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
describe("tool.read truncation", () => {
|
||||
test("truncates large file by bytes and sets truncated metadata", async () => {
|
||||
await using tmp = await tmpdir({
|
||||
init: async (dir) => {
|
||||
const base = await Filesystem.readText(path.join(FIXTURES_DIR, "models-api.json"))
|
||||
const target = 60 * 1024
|
||||
const content = base.length >= target ? base : base.repeat(Math.ceil(target / base.length))
|
||||
await Filesystem.write(path.join(dir, "large.json"), content)
|
||||
},
|
||||
})
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const read = await ReadTool.init()
|
||||
const result = await read.execute({ filePath: path.join(tmp.path, "large.json") }, ctx)
|
||||
expect(result.metadata.truncated).toBe(true)
|
||||
expect(result.output).toContain("Output capped at")
|
||||
expect(result.output).toContain("Use offset=")
|
||||
},
|
||||
})
|
||||
})
|
||||
it.live("truncates large file by bytes and sets truncated metadata", () =>
|
||||
Effect.gen(function* () {
|
||||
const dir = yield* tmpdirScoped()
|
||||
const base = yield* load(path.join(FIXTURES_DIR, "models-api.json"))
|
||||
const target = 60 * 1024
|
||||
const content = base.length >= target ? base : base.repeat(Math.ceil(target / base.length))
|
||||
yield* put(path.join(dir, "large.json"), content)
|
||||
|
||||
test("truncates by line count when limit is specified", async () => {
|
||||
await using tmp = await tmpdir({
|
||||
init: async (dir) => {
|
||||
const lines = Array.from({ length: 100 }, (_, i) => `line${i}`).join("\n")
|
||||
await Bun.write(path.join(dir, "many-lines.txt"), lines)
|
||||
},
|
||||
})
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const read = await ReadTool.init()
|
||||
const result = await read.execute({ filePath: path.join(tmp.path, "many-lines.txt"), limit: 10 }, ctx)
|
||||
expect(result.metadata.truncated).toBe(true)
|
||||
expect(result.output).toContain("Showing lines 1-10 of 100")
|
||||
expect(result.output).toContain("Use offset=11")
|
||||
expect(result.output).toContain("line0")
|
||||
expect(result.output).toContain("line9")
|
||||
expect(result.output).not.toContain("line10")
|
||||
},
|
||||
})
|
||||
})
|
||||
const result = yield* exec(dir, { filePath: path.join(dir, "large.json") })
|
||||
expect(result.metadata.truncated).toBe(true)
|
||||
expect(result.output).toContain("Output capped at")
|
||||
expect(result.output).toContain("Use offset=")
|
||||
}),
|
||||
)
|
||||
|
||||
test("does not truncate small file", async () => {
|
||||
await using tmp = await tmpdir({
|
||||
init: async (dir) => {
|
||||
await Bun.write(path.join(dir, "small.txt"), "hello world")
|
||||
},
|
||||
})
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const read = await ReadTool.init()
|
||||
const result = await read.execute({ filePath: path.join(tmp.path, "small.txt") }, ctx)
|
||||
expect(result.metadata.truncated).toBe(false)
|
||||
expect(result.output).toContain("End of file")
|
||||
},
|
||||
})
|
||||
})
|
||||
it.live("truncates by line count when limit is specified", () =>
|
||||
Effect.gen(function* () {
|
||||
const dir = yield* tmpdirScoped()
|
||||
const lines = Array.from({ length: 100 }, (_, i) => `line${i}`).join("\n")
|
||||
yield* put(path.join(dir, "many-lines.txt"), lines)
|
||||
|
||||
test("respects offset parameter", async () => {
|
||||
await using tmp = await tmpdir({
|
||||
init: async (dir) => {
|
||||
const lines = Array.from({ length: 20 }, (_, i) => `line${i + 1}`).join("\n")
|
||||
await Bun.write(path.join(dir, "offset.txt"), lines)
|
||||
},
|
||||
})
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const read = await ReadTool.init()
|
||||
const result = await read.execute({ filePath: path.join(tmp.path, "offset.txt"), offset: 10, limit: 5 }, ctx)
|
||||
expect(result.output).toContain("10: line10")
|
||||
expect(result.output).toContain("14: line14")
|
||||
expect(result.output).not.toContain("9: line10")
|
||||
expect(result.output).not.toContain("15: line15")
|
||||
expect(result.output).toContain("line10")
|
||||
expect(result.output).toContain("line14")
|
||||
expect(result.output).not.toContain("line0")
|
||||
expect(result.output).not.toContain("line15")
|
||||
},
|
||||
})
|
||||
})
|
||||
const result = yield* exec(dir, { filePath: path.join(dir, "many-lines.txt"), limit: 10 })
|
||||
expect(result.metadata.truncated).toBe(true)
|
||||
expect(result.output).toContain("Showing lines 1-10 of 100")
|
||||
expect(result.output).toContain("Use offset=11")
|
||||
expect(result.output).toContain("line0")
|
||||
expect(result.output).toContain("line9")
|
||||
expect(result.output).not.toContain("line10")
|
||||
}),
|
||||
)
|
||||
|
||||
test("throws when offset is beyond end of file", async () => {
|
||||
await using tmp = await tmpdir({
|
||||
init: async (dir) => {
|
||||
const lines = Array.from({ length: 3 }, (_, i) => `line${i + 1}`).join("\n")
|
||||
await Bun.write(path.join(dir, "short.txt"), lines)
|
||||
},
|
||||
})
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const read = await ReadTool.init()
|
||||
await expect(
|
||||
read.execute({ filePath: path.join(tmp.path, "short.txt"), offset: 4, limit: 5 }, ctx),
|
||||
).rejects.toThrow("Offset 4 is out of range for this file (3 lines)")
|
||||
},
|
||||
})
|
||||
})
|
||||
it.live("does not truncate small file", () =>
|
||||
Effect.gen(function* () {
|
||||
const dir = yield* tmpdirScoped()
|
||||
yield* put(path.join(dir, "small.txt"), "hello world")
|
||||
|
||||
test("allows reading empty file at default offset", async () => {
|
||||
await using tmp = await tmpdir({
|
||||
init: async (dir) => {
|
||||
await Bun.write(path.join(dir, "empty.txt"), "")
|
||||
},
|
||||
})
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const read = await ReadTool.init()
|
||||
const result = await read.execute({ filePath: path.join(tmp.path, "empty.txt") }, ctx)
|
||||
expect(result.metadata.truncated).toBe(false)
|
||||
expect(result.output).toContain("End of file - total 0 lines")
|
||||
},
|
||||
})
|
||||
})
|
||||
const result = yield* exec(dir, { filePath: path.join(dir, "small.txt") })
|
||||
expect(result.metadata.truncated).toBe(false)
|
||||
expect(result.output).toContain("End of file")
|
||||
}),
|
||||
)
|
||||
|
||||
test("throws when offset > 1 for empty file", async () => {
|
||||
await using tmp = await tmpdir({
|
||||
init: async (dir) => {
|
||||
await Bun.write(path.join(dir, "empty.txt"), "")
|
||||
},
|
||||
})
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const read = await ReadTool.init()
|
||||
await expect(read.execute({ filePath: path.join(tmp.path, "empty.txt"), offset: 2 }, ctx)).rejects.toThrow(
|
||||
"Offset 2 is out of range for this file (0 lines)",
|
||||
)
|
||||
},
|
||||
})
|
||||
})
|
||||
it.live("respects offset parameter", () =>
|
||||
Effect.gen(function* () {
|
||||
const dir = yield* tmpdirScoped()
|
||||
const lines = Array.from({ length: 20 }, (_, i) => `line${i + 1}`).join("\n")
|
||||
yield* put(path.join(dir, "offset.txt"), lines)
|
||||
|
||||
test("does not mark final directory page as truncated", async () => {
|
||||
await using tmp = await tmpdir({
|
||||
init: async (dir) => {
|
||||
await Promise.all(
|
||||
Array.from({ length: 10 }, (_, i) => Bun.write(path.join(dir, "dir", `file-${i + 1}.txt`), `line${i}`)),
|
||||
)
|
||||
},
|
||||
})
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const read = await ReadTool.init()
|
||||
const result = await read.execute({ filePath: path.join(tmp.path, "dir"), offset: 6, limit: 5 }, ctx)
|
||||
expect(result.metadata.truncated).toBe(false)
|
||||
expect(result.output).not.toContain("Showing 5 of 10 entries")
|
||||
},
|
||||
})
|
||||
})
|
||||
const result = yield* exec(dir, { filePath: path.join(dir, "offset.txt"), offset: 10, limit: 5 })
|
||||
expect(result.output).toContain("10: line10")
|
||||
expect(result.output).toContain("14: line14")
|
||||
expect(result.output).not.toContain("9: line10")
|
||||
expect(result.output).not.toContain("15: line15")
|
||||
expect(result.output).toContain("line10")
|
||||
expect(result.output).toContain("line14")
|
||||
expect(result.output).not.toContain("line0")
|
||||
expect(result.output).not.toContain("line15")
|
||||
}),
|
||||
)
|
||||
|
||||
test("truncates long lines", async () => {
|
||||
await using tmp = await tmpdir({
|
||||
init: async (dir) => {
|
||||
const longLine = "x".repeat(3000)
|
||||
await Bun.write(path.join(dir, "long-line.txt"), longLine)
|
||||
},
|
||||
})
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const read = await ReadTool.init()
|
||||
const result = await read.execute({ filePath: path.join(tmp.path, "long-line.txt") }, ctx)
|
||||
expect(result.output).toContain("(line truncated to 2000 chars)")
|
||||
expect(result.output.length).toBeLessThan(3000)
|
||||
},
|
||||
})
|
||||
})
|
||||
it.live("throws when offset is beyond end of file", () =>
|
||||
Effect.gen(function* () {
|
||||
const dir = yield* tmpdirScoped()
|
||||
const lines = Array.from({ length: 3 }, (_, i) => `line${i + 1}`).join("\n")
|
||||
yield* put(path.join(dir, "short.txt"), lines)
|
||||
|
||||
test("image files set truncated to false", async () => {
|
||||
await using tmp = await tmpdir({
|
||||
init: async (dir) => {
|
||||
// 1x1 red PNG
|
||||
const png = Buffer.from(
|
||||
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8DwHwAFBQIAX8jx0gAAAABJRU5ErkJggg==",
|
||||
"base64",
|
||||
)
|
||||
await Bun.write(path.join(dir, "image.png"), png)
|
||||
},
|
||||
})
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const read = await ReadTool.init()
|
||||
const result = await read.execute({ filePath: path.join(tmp.path, "image.png") }, ctx)
|
||||
expect(result.metadata.truncated).toBe(false)
|
||||
expect(result.attachments).toBeDefined()
|
||||
expect(result.attachments?.length).toBe(1)
|
||||
expect(result.attachments?.[0]).not.toHaveProperty("id")
|
||||
expect(result.attachments?.[0]).not.toHaveProperty("sessionID")
|
||||
expect(result.attachments?.[0]).not.toHaveProperty("messageID")
|
||||
},
|
||||
})
|
||||
})
|
||||
const err = yield* fail(dir, { filePath: path.join(dir, "short.txt"), offset: 4, limit: 5 })
|
||||
expect(err.message).toContain("Offset 4 is out of range for this file (3 lines)")
|
||||
}),
|
||||
)
|
||||
|
||||
test("large image files are properly attached without error", async () => {
|
||||
await Instance.provide({
|
||||
directory: FIXTURES_DIR,
|
||||
fn: async () => {
|
||||
const read = await ReadTool.init()
|
||||
const result = await read.execute({ filePath: path.join(FIXTURES_DIR, "large-image.png") }, ctx)
|
||||
expect(result.metadata.truncated).toBe(false)
|
||||
expect(result.attachments).toBeDefined()
|
||||
expect(result.attachments?.length).toBe(1)
|
||||
expect(result.attachments?.[0].type).toBe("file")
|
||||
expect(result.attachments?.[0]).not.toHaveProperty("id")
|
||||
expect(result.attachments?.[0]).not.toHaveProperty("sessionID")
|
||||
expect(result.attachments?.[0]).not.toHaveProperty("messageID")
|
||||
},
|
||||
})
|
||||
})
|
||||
it.live("allows reading empty file at default offset", () =>
|
||||
Effect.gen(function* () {
|
||||
const dir = yield* tmpdirScoped()
|
||||
yield* put(path.join(dir, "empty.txt"), "")
|
||||
|
||||
test(".fbs files (FlatBuffers schema) are read as text, not images", async () => {
|
||||
await using tmp = await tmpdir({
|
||||
init: async (dir) => {
|
||||
// FlatBuffers schema content
|
||||
const fbsContent = `namespace MyGame;
|
||||
const result = yield* exec(dir, { filePath: path.join(dir, "empty.txt") })
|
||||
expect(result.metadata.truncated).toBe(false)
|
||||
expect(result.output).toContain("End of file - total 0 lines")
|
||||
}),
|
||||
)
|
||||
|
||||
it.live("throws when offset > 1 for empty file", () =>
|
||||
Effect.gen(function* () {
|
||||
const dir = yield* tmpdirScoped()
|
||||
yield* put(path.join(dir, "empty.txt"), "")
|
||||
|
||||
const err = yield* fail(dir, { filePath: path.join(dir, "empty.txt"), offset: 2 })
|
||||
expect(err.message).toContain("Offset 2 is out of range for this file (0 lines)")
|
||||
}),
|
||||
)
|
||||
|
||||
it.live("does not mark final directory page as truncated", () =>
|
||||
Effect.gen(function* () {
|
||||
const dir = yield* tmpdirScoped()
|
||||
yield* Effect.forEach(
|
||||
Array.from({ length: 10 }, (_, i) => i),
|
||||
(i) => put(path.join(dir, "dir", `file-${i + 1}.txt`), `line${i}`),
|
||||
{
|
||||
concurrency: "unbounded",
|
||||
},
|
||||
)
|
||||
|
||||
const result = yield* exec(dir, { filePath: path.join(dir, "dir"), offset: 6, limit: 5 })
|
||||
expect(result.metadata.truncated).toBe(false)
|
||||
expect(result.output).not.toContain("Showing 5 of 10 entries")
|
||||
}),
|
||||
)
|
||||
|
||||
it.live("truncates long lines", () =>
|
||||
Effect.gen(function* () {
|
||||
const dir = yield* tmpdirScoped()
|
||||
yield* put(path.join(dir, "long-line.txt"), "x".repeat(3000))
|
||||
|
||||
const result = yield* exec(dir, { filePath: path.join(dir, "long-line.txt") })
|
||||
expect(result.output).toContain("(line truncated to 2000 chars)")
|
||||
expect(result.output.length).toBeLessThan(3000)
|
||||
}),
|
||||
)
|
||||
|
||||
it.live("image files set truncated to false", () =>
|
||||
Effect.gen(function* () {
|
||||
const dir = yield* tmpdirScoped()
|
||||
const png = Buffer.from(
|
||||
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8DwHwAFBQIAX8jx0gAAAABJRU5ErkJggg==",
|
||||
"base64",
|
||||
)
|
||||
yield* put(path.join(dir, "image.png"), png)
|
||||
|
||||
const result = yield* exec(dir, { filePath: path.join(dir, "image.png") })
|
||||
expect(result.metadata.truncated).toBe(false)
|
||||
expect(result.attachments).toBeDefined()
|
||||
expect(result.attachments?.length).toBe(1)
|
||||
expect(result.attachments?.[0]).not.toHaveProperty("id")
|
||||
expect(result.attachments?.[0]).not.toHaveProperty("sessionID")
|
||||
expect(result.attachments?.[0]).not.toHaveProperty("messageID")
|
||||
}),
|
||||
)
|
||||
|
||||
it.live("large image files are properly attached without error", () =>
|
||||
Effect.gen(function* () {
|
||||
const result = yield* exec(FIXTURES_DIR, { filePath: path.join(FIXTURES_DIR, "large-image.png") })
|
||||
expect(result.metadata.truncated).toBe(false)
|
||||
expect(result.attachments).toBeDefined()
|
||||
expect(result.attachments?.length).toBe(1)
|
||||
expect(result.attachments?.[0].type).toBe("file")
|
||||
expect(result.attachments?.[0]).not.toHaveProperty("id")
|
||||
expect(result.attachments?.[0]).not.toHaveProperty("sessionID")
|
||||
expect(result.attachments?.[0]).not.toHaveProperty("messageID")
|
||||
}),
|
||||
)
|
||||
|
||||
it.live(".fbs files (FlatBuffers schema) are read as text, not images", () =>
|
||||
Effect.gen(function* () {
|
||||
const dir = yield* tmpdirScoped()
|
||||
const fbs = `namespace MyGame;
|
||||
|
||||
table Monster {
|
||||
pos:Vec3;
|
||||
@@ -468,79 +417,52 @@ table Monster {
|
||||
}
|
||||
|
||||
root_type Monster;`
|
||||
await Bun.write(path.join(dir, "schema.fbs"), fbsContent)
|
||||
},
|
||||
})
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const read = await ReadTool.init()
|
||||
const result = await read.execute({ filePath: path.join(tmp.path, "schema.fbs") }, ctx)
|
||||
// Should be read as text, not as image
|
||||
expect(result.attachments).toBeUndefined()
|
||||
expect(result.output).toContain("namespace MyGame")
|
||||
expect(result.output).toContain("table Monster")
|
||||
},
|
||||
})
|
||||
})
|
||||
yield* put(path.join(dir, "schema.fbs"), fbs)
|
||||
|
||||
const result = yield* exec(dir, { filePath: path.join(dir, "schema.fbs") })
|
||||
expect(result.attachments).toBeUndefined()
|
||||
expect(result.output).toContain("namespace MyGame")
|
||||
expect(result.output).toContain("table Monster")
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
describe("tool.read loaded instructions", () => {
|
||||
test("loads AGENTS.md from parent directory and includes in metadata", async () => {
|
||||
await using tmp = await tmpdir({
|
||||
init: async (dir) => {
|
||||
await Bun.write(path.join(dir, "subdir", "AGENTS.md"), "# Test Instructions\nDo something special.")
|
||||
await Bun.write(path.join(dir, "subdir", "nested", "test.txt"), "test content")
|
||||
},
|
||||
})
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const read = await ReadTool.init()
|
||||
const result = await read.execute({ filePath: path.join(tmp.path, "subdir", "nested", "test.txt") }, ctx)
|
||||
expect(result.output).toContain("test content")
|
||||
expect(result.output).toContain("system-reminder")
|
||||
expect(result.output).toContain("Test Instructions")
|
||||
expect(result.metadata.loaded).toBeDefined()
|
||||
expect(result.metadata.loaded).toContain(path.join(tmp.path, "subdir", "AGENTS.md"))
|
||||
},
|
||||
})
|
||||
})
|
||||
it.live("loads AGENTS.md from parent directory and includes in metadata", () =>
|
||||
Effect.gen(function* () {
|
||||
const dir = yield* tmpdirScoped()
|
||||
yield* put(path.join(dir, "subdir", "AGENTS.md"), "# Test Instructions\nDo something special.")
|
||||
yield* put(path.join(dir, "subdir", "nested", "test.txt"), "test content")
|
||||
|
||||
const result = yield* exec(dir, { filePath: path.join(dir, "subdir", "nested", "test.txt") })
|
||||
expect(result.output).toContain("test content")
|
||||
expect(result.output).toContain("system-reminder")
|
||||
expect(result.output).toContain("Test Instructions")
|
||||
expect(result.metadata.loaded).toBeDefined()
|
||||
expect(result.metadata.loaded).toContain(path.join(dir, "subdir", "AGENTS.md"))
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
describe("tool.read binary detection", () => {
|
||||
test("rejects text extension files with null bytes", async () => {
|
||||
await using tmp = await tmpdir({
|
||||
init: async (dir) => {
|
||||
const bytes = Buffer.from([0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x00, 0x77, 0x6f, 0x72, 0x6c, 0x64])
|
||||
await Bun.write(path.join(dir, "null-byte.txt"), bytes)
|
||||
},
|
||||
})
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const read = await ReadTool.init()
|
||||
await expect(read.execute({ filePath: path.join(tmp.path, "null-byte.txt") }, ctx)).rejects.toThrow(
|
||||
"Cannot read binary file",
|
||||
)
|
||||
},
|
||||
})
|
||||
})
|
||||
it.live("rejects text extension files with null bytes", () =>
|
||||
Effect.gen(function* () {
|
||||
const dir = yield* tmpdirScoped()
|
||||
const bytes = Buffer.from([0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x00, 0x77, 0x6f, 0x72, 0x6c, 0x64])
|
||||
yield* put(path.join(dir, "null-byte.txt"), bytes)
|
||||
|
||||
test("rejects known binary extensions", async () => {
|
||||
await using tmp = await tmpdir({
|
||||
init: async (dir) => {
|
||||
await Bun.write(path.join(dir, "module.wasm"), "not really wasm")
|
||||
},
|
||||
})
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const read = await ReadTool.init()
|
||||
await expect(read.execute({ filePath: path.join(tmp.path, "module.wasm") }, ctx)).rejects.toThrow(
|
||||
"Cannot read binary file",
|
||||
)
|
||||
},
|
||||
})
|
||||
})
|
||||
const err = yield* fail(dir, { filePath: path.join(dir, "null-byte.txt") })
|
||||
expect(err.message).toContain("Cannot read binary file")
|
||||
}),
|
||||
)
|
||||
|
||||
it.live("rejects known binary extensions", () =>
|
||||
Effect.gen(function* () {
|
||||
const dir = yield* tmpdirScoped()
|
||||
yield* put(path.join(dir, "module.wasm"), "not really wasm")
|
||||
|
||||
const err = yield* fail(dir, { filePath: path.join(dir, "module.wasm") })
|
||||
expect(err.message).toContain("Cannot read binary file")
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/package.json",
|
||||
"name": "@opencode-ai/plugin",
|
||||
"version": "1.3.13",
|
||||
"version": "1.3.15",
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/package.json",
|
||||
"name": "@opencode-ai/sdk",
|
||||
"version": "1.3.13",
|
||||
"version": "1.3.15",
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
|
||||
@@ -24,6 +24,9 @@ import type {
|
||||
EventTuiPromptAppend,
|
||||
EventTuiSessionSelect,
|
||||
EventTuiToastShow,
|
||||
ExperimentalConsoleGetResponses,
|
||||
ExperimentalConsoleListOrgsResponses,
|
||||
ExperimentalConsoleSwitchOrgResponses,
|
||||
ExperimentalResourceListResponses,
|
||||
ExperimentalSessionListResponses,
|
||||
ExperimentalWorkspaceCreateErrors,
|
||||
@@ -981,13 +984,13 @@ export class Config2 extends HeyApiClient {
|
||||
}
|
||||
}
|
||||
|
||||
export class Tool extends HeyApiClient {
|
||||
export class Console extends HeyApiClient {
|
||||
/**
|
||||
* List tool IDs
|
||||
* Get active Console provider metadata
|
||||
*
|
||||
* Get a list of all available tool IDs, including both built-in tools and dynamically registered tools.
|
||||
* Get the active Console org name and the set of provider IDs managed by that Console org.
|
||||
*/
|
||||
public ids<ThrowOnError extends boolean = false>(
|
||||
public get<ThrowOnError extends boolean = false>(
|
||||
parameters?: {
|
||||
directory?: string
|
||||
workspace?: string
|
||||
@@ -1005,24 +1008,22 @@ export class Tool extends HeyApiClient {
|
||||
},
|
||||
],
|
||||
)
|
||||
return (options?.client ?? this.client).get<ToolIdsResponses, ToolIdsErrors, ThrowOnError>({
|
||||
url: "/experimental/tool/ids",
|
||||
return (options?.client ?? this.client).get<ExperimentalConsoleGetResponses, unknown, ThrowOnError>({
|
||||
url: "/experimental/console",
|
||||
...options,
|
||||
...params,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* List tools
|
||||
* List switchable Console orgs
|
||||
*
|
||||
* Get a list of available tools with their JSON schema parameters for a specific provider and model combination.
|
||||
* Get the available Console orgs across logged-in accounts, including the current active org.
|
||||
*/
|
||||
public list<ThrowOnError extends boolean = false>(
|
||||
parameters: {
|
||||
public listOrgs<ThrowOnError extends boolean = false>(
|
||||
parameters?: {
|
||||
directory?: string
|
||||
workspace?: string
|
||||
provider: string
|
||||
model: string
|
||||
},
|
||||
options?: Options<never, ThrowOnError>,
|
||||
) {
|
||||
@@ -1033,18 +1034,55 @@ export class Tool extends HeyApiClient {
|
||||
args: [
|
||||
{ in: "query", key: "directory" },
|
||||
{ in: "query", key: "workspace" },
|
||||
{ in: "query", key: "provider" },
|
||||
{ in: "query", key: "model" },
|
||||
],
|
||||
},
|
||||
],
|
||||
)
|
||||
return (options?.client ?? this.client).get<ToolListResponses, ToolListErrors, ThrowOnError>({
|
||||
url: "/experimental/tool",
|
||||
return (options?.client ?? this.client).get<ExperimentalConsoleListOrgsResponses, unknown, ThrowOnError>({
|
||||
url: "/experimental/console/orgs",
|
||||
...options,
|
||||
...params,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Switch active Console org
|
||||
*
|
||||
* Persist a new active Console account/org selection for the current local OpenCode state.
|
||||
*/
|
||||
public switchOrg<ThrowOnError extends boolean = false>(
|
||||
parameters?: {
|
||||
directory?: string
|
||||
workspace?: string
|
||||
accountID?: string
|
||||
orgID?: string
|
||||
},
|
||||
options?: Options<never, ThrowOnError>,
|
||||
) {
|
||||
const params = buildClientParams(
|
||||
[parameters],
|
||||
[
|
||||
{
|
||||
args: [
|
||||
{ in: "query", key: "directory" },
|
||||
{ in: "query", key: "workspace" },
|
||||
{ in: "body", key: "accountID" },
|
||||
{ in: "body", key: "orgID" },
|
||||
],
|
||||
},
|
||||
],
|
||||
)
|
||||
return (options?.client ?? this.client).post<ExperimentalConsoleSwitchOrgResponses, unknown, ThrowOnError>({
|
||||
url: "/experimental/console/switch",
|
||||
...options,
|
||||
...params,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...options?.headers,
|
||||
...params.headers,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export class Workspace extends HeyApiClient {
|
||||
@@ -1239,6 +1277,11 @@ export class Resource extends HeyApiClient {
|
||||
}
|
||||
|
||||
export class Experimental extends HeyApiClient {
|
||||
private _console?: Console
|
||||
get console(): Console {
|
||||
return (this._console ??= new Console({ client: this.client }))
|
||||
}
|
||||
|
||||
private _workspace?: Workspace
|
||||
get workspace(): Workspace {
|
||||
return (this._workspace ??= new Workspace({ client: this.client }))
|
||||
@@ -1255,6 +1298,72 @@ export class Experimental extends HeyApiClient {
|
||||
}
|
||||
}
|
||||
|
||||
export class Tool extends HeyApiClient {
|
||||
/**
|
||||
* List tool IDs
|
||||
*
|
||||
* Get a list of all available tool IDs, including both built-in tools and dynamically registered tools.
|
||||
*/
|
||||
public ids<ThrowOnError extends boolean = false>(
|
||||
parameters?: {
|
||||
directory?: string
|
||||
workspace?: string
|
||||
},
|
||||
options?: Options<never, ThrowOnError>,
|
||||
) {
|
||||
const params = buildClientParams(
|
||||
[parameters],
|
||||
[
|
||||
{
|
||||
args: [
|
||||
{ in: "query", key: "directory" },
|
||||
{ in: "query", key: "workspace" },
|
||||
],
|
||||
},
|
||||
],
|
||||
)
|
||||
return (options?.client ?? this.client).get<ToolIdsResponses, ToolIdsErrors, ThrowOnError>({
|
||||
url: "/experimental/tool/ids",
|
||||
...options,
|
||||
...params,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* List tools
|
||||
*
|
||||
* Get a list of available tools with their JSON schema parameters for a specific provider and model combination.
|
||||
*/
|
||||
public list<ThrowOnError extends boolean = false>(
|
||||
parameters: {
|
||||
directory?: string
|
||||
workspace?: string
|
||||
provider: string
|
||||
model: string
|
||||
},
|
||||
options?: Options<never, ThrowOnError>,
|
||||
) {
|
||||
const params = buildClientParams(
|
||||
[parameters],
|
||||
[
|
||||
{
|
||||
args: [
|
||||
{ in: "query", key: "directory" },
|
||||
{ in: "query", key: "workspace" },
|
||||
{ in: "query", key: "provider" },
|
||||
{ in: "query", key: "model" },
|
||||
],
|
||||
},
|
||||
],
|
||||
)
|
||||
return (options?.client ?? this.client).get<ToolListResponses, ToolListErrors, ThrowOnError>({
|
||||
url: "/experimental/tool",
|
||||
...options,
|
||||
...params,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export class Worktree extends HeyApiClient {
|
||||
/**
|
||||
* Remove worktree
|
||||
@@ -4017,16 +4126,16 @@ export class OpencodeClient extends HeyApiClient {
|
||||
return (this._config ??= new Config2({ client: this.client }))
|
||||
}
|
||||
|
||||
private _tool?: Tool
|
||||
get tool(): Tool {
|
||||
return (this._tool ??= new Tool({ client: this.client }))
|
||||
}
|
||||
|
||||
private _experimental?: Experimental
|
||||
get experimental(): Experimental {
|
||||
return (this._experimental ??= new Experimental({ client: this.client }))
|
||||
}
|
||||
|
||||
private _tool?: Tool
|
||||
get tool(): Tool {
|
||||
return (this._tool ??= new Tool({ client: this.client }))
|
||||
}
|
||||
|
||||
private _worktree?: Worktree
|
||||
get worktree(): Worktree {
|
||||
return (this._worktree ??= new Worktree({ client: this.client }))
|
||||
|
||||
@@ -2653,6 +2653,81 @@ export type ConfigProvidersResponses = {
|
||||
|
||||
export type ConfigProvidersResponse = ConfigProvidersResponses[keyof ConfigProvidersResponses]
|
||||
|
||||
export type ExperimentalConsoleGetData = {
|
||||
body?: never
|
||||
path?: never
|
||||
query?: {
|
||||
directory?: string
|
||||
workspace?: string
|
||||
}
|
||||
url: "/experimental/console"
|
||||
}
|
||||
|
||||
export type ExperimentalConsoleGetResponses = {
|
||||
/**
|
||||
* Active Console provider metadata
|
||||
*/
|
||||
200: {
|
||||
consoleManagedProviders: Array<string>
|
||||
activeOrgName?: string
|
||||
switchableOrgCount: number
|
||||
}
|
||||
}
|
||||
|
||||
export type ExperimentalConsoleGetResponse = ExperimentalConsoleGetResponses[keyof ExperimentalConsoleGetResponses]
|
||||
|
||||
export type ExperimentalConsoleListOrgsData = {
|
||||
body?: never
|
||||
path?: never
|
||||
query?: {
|
||||
directory?: string
|
||||
workspace?: string
|
||||
}
|
||||
url: "/experimental/console/orgs"
|
||||
}
|
||||
|
||||
export type ExperimentalConsoleListOrgsResponses = {
|
||||
/**
|
||||
* Switchable Console orgs
|
||||
*/
|
||||
200: {
|
||||
orgs: Array<{
|
||||
accountID: string
|
||||
accountEmail: string
|
||||
accountUrl: string
|
||||
orgID: string
|
||||
orgName: string
|
||||
active: boolean
|
||||
}>
|
||||
}
|
||||
}
|
||||
|
||||
export type ExperimentalConsoleListOrgsResponse =
|
||||
ExperimentalConsoleListOrgsResponses[keyof ExperimentalConsoleListOrgsResponses]
|
||||
|
||||
export type ExperimentalConsoleSwitchOrgData = {
|
||||
body?: {
|
||||
accountID: string
|
||||
orgID: string
|
||||
}
|
||||
path?: never
|
||||
query?: {
|
||||
directory?: string
|
||||
workspace?: string
|
||||
}
|
||||
url: "/experimental/console/switch"
|
||||
}
|
||||
|
||||
export type ExperimentalConsoleSwitchOrgResponses = {
|
||||
/**
|
||||
* Switch success
|
||||
*/
|
||||
200: boolean
|
||||
}
|
||||
|
||||
export type ExperimentalConsoleSwitchOrgResponse =
|
||||
ExperimentalConsoleSwitchOrgResponses[keyof ExperimentalConsoleSwitchOrgResponses]
|
||||
|
||||
export type ToolIdsData = {
|
||||
body?: never
|
||||
path?: never
|
||||
|
||||
@@ -1220,6 +1220,194 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"/experimental/console": {
|
||||
"get": {
|
||||
"operationId": "experimental.console.get",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "query",
|
||||
"name": "directory",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"in": "query",
|
||||
"name": "workspace",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"summary": "Get active Console provider metadata",
|
||||
"description": "Get the active Console org name and the set of provider IDs managed by that Console org.",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Active Console provider metadata",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"consoleManagedProviders": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"activeOrgName": {
|
||||
"type": "string"
|
||||
},
|
||||
"switchableOrgCount": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 9007199254740991
|
||||
}
|
||||
},
|
||||
"required": ["consoleManagedProviders", "switchableOrgCount"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"x-codeSamples": [
|
||||
{
|
||||
"lang": "js",
|
||||
"source": "import { createOpencodeClient } from \"@opencode-ai/sdk\n\nconst client = createOpencodeClient()\nawait client.experimental.console.get({\n ...\n})"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/experimental/console/orgs": {
|
||||
"get": {
|
||||
"operationId": "experimental.console.listOrgs",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "query",
|
||||
"name": "directory",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"in": "query",
|
||||
"name": "workspace",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"summary": "List switchable Console orgs",
|
||||
"description": "Get the available Console orgs across logged-in accounts, including the current active org.",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Switchable Console orgs",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"orgs": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"accountID": {
|
||||
"type": "string"
|
||||
},
|
||||
"accountEmail": {
|
||||
"type": "string"
|
||||
},
|
||||
"accountUrl": {
|
||||
"type": "string"
|
||||
},
|
||||
"orgID": {
|
||||
"type": "string"
|
||||
},
|
||||
"orgName": {
|
||||
"type": "string"
|
||||
},
|
||||
"active": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": ["accountID", "accountEmail", "accountUrl", "orgID", "orgName", "active"]
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["orgs"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"x-codeSamples": [
|
||||
{
|
||||
"lang": "js",
|
||||
"source": "import { createOpencodeClient } from \"@opencode-ai/sdk\n\nconst client = createOpencodeClient()\nawait client.experimental.console.listOrgs({\n ...\n})"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/experimental/console/switch": {
|
||||
"post": {
|
||||
"operationId": "experimental.console.switchOrg",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "query",
|
||||
"name": "directory",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"in": "query",
|
||||
"name": "workspace",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"summary": "Switch active Console org",
|
||||
"description": "Persist a new active Console account/org selection for the current local OpenCode state.",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Switch success",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"accountID": {
|
||||
"type": "string"
|
||||
},
|
||||
"orgID": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["accountID", "orgID"]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"x-codeSamples": [
|
||||
{
|
||||
"lang": "js",
|
||||
"source": "import { createOpencodeClient } from \"@opencode-ai/sdk\n\nconst client = createOpencodeClient()\nawait client.experimental.console.switchOrg({\n ...\n})"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/experimental/tool/ids": {
|
||||
"get": {
|
||||
"operationId": "tool.ids",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@opencode-ai/slack",
|
||||
"version": "1.3.13",
|
||||
"version": "1.3.15",
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@opencode-ai/ui",
|
||||
"version": "1.3.13",
|
||||
"version": "1.3.15",
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@opencode-ai/util",
|
||||
"version": "1.3.13",
|
||||
"version": "1.3.15",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"name": "@opencode-ai/web",
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
"version": "1.3.13",
|
||||
"version": "1.3.15",
|
||||
"scripts": {
|
||||
"dev": "astro dev",
|
||||
"dev:remote": "VITE_API_URL=https://api.opencode.ai astro dev",
|
||||
|
||||
@@ -94,8 +94,6 @@ You can also access our models through the following API endpoints.
|
||||
| GLM 5 | glm-5 | `https://opencode.ai/zen/v1/chat/completions` | `@ai-sdk/openai-compatible` |
|
||||
| Kimi K2.5 | kimi-k2.5 | `https://opencode.ai/zen/v1/chat/completions` | `@ai-sdk/openai-compatible` |
|
||||
| Big Pickle | big-pickle | `https://opencode.ai/zen/v1/chat/completions` | `@ai-sdk/openai-compatible` |
|
||||
| MiMo V2 Pro Free | mimo-v2-pro-free | `https://opencode.ai/zen/v1/chat/completions` | `@ai-sdk/openai-compatible` |
|
||||
| MiMo V2 Omni Free | mimo-v2-omni-free | `https://opencode.ai/zen/v1/chat/completions` | `@ai-sdk/openai-compatible` |
|
||||
| Qwen3.6 Plus Free | qwen3.6-plus-free | `https://opencode.ai/zen/v1/chat/completions` | `@ai-sdk/openai-compatible` |
|
||||
| Nemotron 3 Super Free | nemotron-3-super-free | `https://opencode.ai/zen/v1/chat/completions` | `@ai-sdk/openai-compatible` |
|
||||
|
||||
@@ -122,8 +120,6 @@ We support a pay-as-you-go model. Below are the prices **per 1M tokens**.
|
||||
| Model | Input | Output | Cached Read | Cached Write |
|
||||
| --------------------------------- | ------ | ------- | ----------- | ------------ |
|
||||
| Big Pickle | Free | Free | Free | - |
|
||||
| MiMo V2 Pro Free | Free | Free | Free | - |
|
||||
| MiMo V2 Omni Free | Free | Free | Free | - |
|
||||
| Qwen3.6 Plus Free | Free | Free | Free | - |
|
||||
| Nemotron 3 Super Free | Free | Free | Free | - |
|
||||
| MiniMax M2.5 Free | Free | Free | Free | - |
|
||||
@@ -169,8 +165,6 @@ Credit card fees are passed along at cost (4.4% + $0.30 per transaction); we don
|
||||
The free models:
|
||||
|
||||
- MiniMax M2.5 Free is available on OpenCode for a limited time. The team is using this time to collect feedback and improve the model.
|
||||
- MiMo V2 Pro Free is available on OpenCode for a limited time. The team is using this time to collect feedback and improve the model.
|
||||
- MiMo V2 Omni Free is available on OpenCode for a limited time. The team is using this time to collect feedback and improve the model.
|
||||
- Qwen3.6 Plus Free is available on OpenCode for a limited time. The team is using this time to collect feedback and improve the model.
|
||||
- Nemotron 3 Super Free is available on OpenCode for a limited time. The team is using this time to collect feedback and improve the model.
|
||||
- Big Pickle is a stealth model that's free on OpenCode for a limited time. The team is using this time to collect feedback and improve the model.
|
||||
@@ -218,8 +212,6 @@ All our models are hosted in the US. Our providers follow a zero-retention polic
|
||||
|
||||
- Big Pickle: During its free period, collected data may be used to improve the model.
|
||||
- MiniMax M2.5 Free: During its free period, collected data may be used to improve the model.
|
||||
- MiMo V2 Pro Free: During its free period, collected data may be used to improve the model.
|
||||
- MiMo V2 Omni Free: During its free period, collected data may be used to improve the model.
|
||||
- Qwen3.6 Plus Free: During its free period, collected data may be used to improve the model.
|
||||
- Nemotron 3 Super Free: During its free period, collected data may be used to improve the model.
|
||||
- OpenAI APIs: Requests are retained for 30 days in accordance with [OpenAI's Data Policies](https://platform.openai.com/docs/guides/your-data).
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"name": "opencode",
|
||||
"displayName": "opencode",
|
||||
"description": "opencode for VS Code",
|
||||
"version": "1.3.13",
|
||||
"version": "1.3.15",
|
||||
"publisher": "sst-dev",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
Reference in New Issue
Block a user