Commit 772e69a
authored
refactor(agent-core-v2): remove the legacy kosong request layer (#352)
## Requirement or Bug
Remove the legacy `packages/agent-core-v2/src/kosong` request layer.
Port the features that existed only there and fix the bugs it caused.
Stacked on #349.
## Bug Reproduction Steps
1. Configure a provider with `type = "openai"` and `env = {
OPENAI_API_KEY = "sk-..." }`, with no `apiKey` and no process env key.
2. Start a session and send a turn.
3. The auth check fails with `AuthTokenMissingError`, even though the
request path would find the key.
## Root Cause
20 of the 62 files under `src/kosong` still loaded at runtime through
`app/auth/*` and `app/kosongConfig/*`. kosong keeps its own
provider-definition map, and at runtime that map held only the pythinker
definitions, because the standard definitions never loaded. So
`resolveModelAuthMaterial` / `resolveModelForReady` (auth check) and
`envOverlay` (vendor `*_BASE_URL`) ignored provider-`env` values for
every non-pythinker provider. Real requests use `llm-adapter` and find
them. This is a fundamental fix: one provider-definition registry, the
live one.
## Code Changes
- Delete `src/kosong` (61 files, about 11k lines). The 19 importers now
import the same symbols from `#/llm-adapter/*` (types are identical
apart from the import path).
- Port features that existed only in the deleted copy, each with a test
that fails before and passes after:
- **OpenCode billing errors:** a 401/402/403 whose body says
"insufficient balance", "insufficient credit", "credits exhausted" or
"please recharge" is a provider error, not `provider.auth_error`.
Ordinary 401s stay auth errors.
- **DSML / Hermes tool calls:** tool calls that some models write as
text tags on the chat-completions stream are parsed into real tool
calls.
- **`modelRecordProviderId`** moved to `llm-adapter/model/model.ts`.
- `apps/vis` imports
`@pymodel/agent-core-v2/llm-adapter/contract/tokens` instead of the
`kosong` subpath.
- `scripts/check-identity-freeze.mjs` drops the deleted kosong path.
- Test fix: an MCP registry test set the wrong home variable, so it did
not isolate the home directory. It now sets `PYTHINKER_CODE_HOME`.
The default-model fallback that also lived only in kosong is **not**
restored: since #323 the gateway tests require that `default_model` is
never rewritten. That is a product decision, tracked in #351.
## Behavior Changes and Affected Users
| Behavior | Before | After | Who relies on the old behavior | Escape
hatch |
|---|---|---|---|---|
| Vendor API key in a provider's `env` table | Auth check ignores it,
turn fails with `AuthTokenMissingError` | Key is found, turn runs |
Nobody (the old behavior was a bug) | n/a |
| Vendor `*_BASE_URL` in an `env` provider of non-pythinker type |
Ignored by `envOverlay` | Applied | Nobody (bug) | Remove the variable
from `env` |
| OpenCode 401/402/403 with a billing message | `provider.auth_error`
("not logged in") | Provider error with the billing message, not retried
| Clients that map `provider.auth_error` to a re-login prompt for this
case | None needed; the old message was wrong |
| Chat-completions stream with DSML/Hermes tool tags | Tags shown as
assistant text, no tool call | Parsed into tool calls. Text that could
start a tag is held back until it is known not to be a tag, and
`llm.streaming.finish` arrives after the stream ends | Nobody relies on
raw tags | None |
| `@pymodel/agent-core-v2/kosong/*` subpath import | Resolves | Gone |
`apps/vis` (updated in this PR); no other consumer found in the repo |
Import from `.../llm-adapter/*` |
Affected modules and coverage:
- `app/auth`: `test/app/auth/auth.test.ts` (provider-env key case, fails
on `main`).
- `app/kosongConfig/envOverlay`: new non-pythinker base-url case (fails
on `main`).
- `human/llm` openai format and stream: billing-error tests and DSML
parser/recovery tests.
- Full suites: agent-core-v2 6,491 pass, agent-gateway 1,407 pass,
vis-server 173 pass; `tsc` and `tsgo` clean; no-comments and
identity-freeze checks pass.
## Checklist
- [x] I have read the
[CONTRIBUTING](https://github.com/PyModel/pythinker-code/blob/main/CONTRIBUTING.md)
document.
- [x] I have linked a related issue (external PRs: issue must have a
maintainer's `/approve`).
- [x] I have added tests that prove my feature works.
- [x] The behavior-change table above is complete, and every removed
behavior or flipped default is named in the changeset and either has an
escape hatch or was explicitly approved by a maintainer in this PR.
- [x] Ran `gen-changesets` skill, or this PR needs no changeset.
- [x] Ran `gen-docs` skill, or this PR needs no doc update.1 parent 69cc714 commit 772e69a
98 files changed
Lines changed: 803 additions & 10897 deletions
File tree
- .changeset
- apps
- pythinker-code/src/cli/sub
- vis/server
- src/lib
- test/lib
- packages/agent-core-v2
- src
- app
- auth
- config
- kosongConfig
- plugin
- features/cron
- human
- llm/requester/bases/openai
- test/llm
- kosong
- contract
- model
- protocol
- provider
- bases
- anthropic
- google-genai
- openai
- providers
- pythinker
- llm-adapter
- contract
- model
- session/subagent
- test
- .skip
- app
- auth
- kosongConfig
- mcpRegistry
- llm-adapter
- contract
- model
- scripts
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
406 | 406 | | |
407 | 407 | | |
408 | 408 | | |
409 | | - | |
| 409 | + | |
410 | 410 | | |
411 | 411 | | |
412 | 412 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
678 | 678 | | |
679 | 679 | | |
680 | 680 | | |
681 | | - | |
| 681 | + | |
682 | 682 | | |
683 | 683 | | |
684 | 684 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | | - | |
| 24 | + | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
0 commit comments