Skip to content

Commit aa0d6e1

Browse files
authored
refactor: extract LLM core packages (#88117)
* refactor: extract llm core packages * chore: drop generated llm package artifacts * fix: align llm package export artifacts * test: fix moving main CI expectations * fix: align llm core subpath aliases * fix: use llm package exports * fix: stabilize llm package boundary artifacts * fix: sync llm boundary path contract * test: isolate crabbox provider env * test: pin crabbox configured-provider cases * test: apply crabbox lease provider override
1 parent 17e75f8 commit aa0d6e1

52 files changed

Lines changed: 1581 additions & 1508 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ jobs:
601601
uses: actions/cache@v5
602602
with:
603603
path: .artifacts/build-all-cache
604-
key: ${{ runner.os }}-build-all-v3-${{ hashFiles('package.json', 'pnpm-lock.yaml', 'npm-shrinkwrap.json', 'packages/plugin-sdk/package.json', 'packages/memory-host-sdk/package.json', 'scripts/build-all.mjs', 'scripts/write-plugin-sdk-entry-dts.ts', 'scripts/lib/plugin-sdk-entries.mjs', 'tsconfig.json', 'tsconfig.plugin-sdk.dts.json', 'src/plugin-sdk/**', 'packages/memory-host-sdk/src/**', 'src/types/**', 'src/video-generation/dashscope-compatible.ts', 'src/video-generation/types.ts', 'scripts/copy-export-html-templates.ts', 'scripts/lib/copy-assets.ts', 'src/auto-reply/reply/export-html/**') }}
604+
key: ${{ runner.os }}-build-all-v3-${{ hashFiles('package.json', 'pnpm-lock.yaml', 'npm-shrinkwrap.json', 'packages/plugin-sdk/package.json', 'packages/llm-core/package.json', 'packages/memory-host-sdk/package.json', 'scripts/build-all.mjs', 'scripts/write-plugin-sdk-entry-dts.ts', 'scripts/lib/plugin-sdk-entries.mjs', 'tsconfig.json', 'tsconfig.plugin-sdk.dts.json', 'src/plugin-sdk/**', 'packages/llm-core/src/**', 'packages/memory-host-sdk/src/**', 'src/types/**', 'src/video-generation/dashscope-compatible.ts', 'src/video-generation/types.ts', 'scripts/copy-export-html-templates.ts', 'scripts/lib/copy-assets.ts', 'src/auto-reply/reply/export-html/**') }}
605605
restore-keys: |
606606
${{ runner.os }}-build-all-v3-
607607
@@ -1403,7 +1403,7 @@ jobs:
14031403
packages/plugin-sdk/dist
14041404
extensions/*/dist/.boundary-tsc.tsbuildinfo
14051405
extensions/*/dist/.boundary-tsc.stamp
1406-
key: ${{ runner.os }}-extension-package-boundary-v1-${{ hashFiles('tsconfig.json', 'tsconfig.plugin-sdk.dts.json', 'packages/plugin-sdk/tsconfig.json', 'scripts/check-extension-package-tsc-boundary.mjs', 'scripts/prepare-extension-package-boundary-artifacts.mjs', 'scripts/write-plugin-sdk-entry-dts.ts', 'scripts/lib/plugin-sdk-entrypoints.json', 'scripts/lib/plugin-sdk-entries.mjs', 'src/plugin-sdk/**', 'src/auto-reply/**', 'src/video-generation/dashscope-compatible.ts', 'src/video-generation/types.ts', 'src/types/**', 'extensions/**', 'extensions/tsconfig.package-boundary*.json', 'package.json', 'pnpm-lock.yaml') }}
1406+
key: ${{ runner.os }}-extension-package-boundary-v1-${{ hashFiles('tsconfig.json', 'tsconfig.plugin-sdk.dts.json', 'packages/plugin-sdk/tsconfig.json', 'packages/llm-core/package.json', 'scripts/check-extension-package-tsc-boundary.mjs', 'scripts/prepare-extension-package-boundary-artifacts.mjs', 'scripts/write-plugin-sdk-entry-dts.ts', 'scripts/lib/plugin-sdk-entrypoints.json', 'scripts/lib/plugin-sdk-entries.mjs', 'src/plugin-sdk/**', 'src/auto-reply/**', 'packages/llm-core/src/**', 'src/video-generation/dashscope-compatible.ts', 'src/video-generation/types.ts', 'src/types/**', 'extensions/**', 'extensions/tsconfig.package-boundary*.json', 'package.json', 'pnpm-lock.yaml') }}
14071407
restore-keys: |
14081408
${{ runner.os }}-extension-package-boundary-v1-
14091409
@@ -1420,10 +1420,14 @@ jobs:
14201420
find src \
14211421
-type f \( -name '*.ts' -o -name '*.tsx' -o -name '*.mts' -o -name '*.cts' -o -name '*.js' -o -name '*.mjs' -o -name '*.json' \) \
14221422
-exec touch -t 200001010000 {} +
1423+
find packages/llm-core/src \
1424+
-type f \( -name '*.ts' -o -name '*.tsx' -o -name '*.mts' -o -name '*.cts' -o -name '*.js' -o -name '*.mjs' -o -name '*.json' \) \
1425+
-exec touch -t 200001010000 {} +
14231426
touch -t 200001010000 \
14241427
tsconfig.json \
14251428
tsconfig.plugin-sdk.dts.json \
14261429
packages/plugin-sdk/tsconfig.json \
1430+
packages/llm-core/package.json \
14271431
scripts/check-extension-package-tsc-boundary.mjs \
14281432
scripts/prepare-extension-package-boundary-artifacts.mjs \
14291433
scripts/write-plugin-sdk-entry-dts.ts \

extensions/tsconfig.package-boundary.paths.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@
9090
"@openclaw/discord/api.js": ["../dist/plugin-sdk/extensions/discord/api.d.ts"],
9191
"@openclaw/slack/api.js": ["../dist/plugin-sdk/extensions/slack/api.d.ts"],
9292
"@openclaw/whatsapp/api.js": ["../dist/plugin-sdk/extensions/whatsapp/api.d.ts"],
93+
"@openclaw/llm-core": ["../dist/plugin-sdk/packages/llm-core/src/index.d.ts"],
94+
"@openclaw/llm-core/diagnostics": [
95+
"../dist/plugin-sdk/packages/llm-core/src/utils/diagnostics.d.ts"
96+
],
97+
"@openclaw/llm-core/event-stream": [
98+
"../dist/plugin-sdk/packages/llm-core/src/utils/event-stream.d.ts"
99+
],
100+
"@openclaw/llm-core/types": ["../dist/plugin-sdk/packages/llm-core/src/types.d.ts"],
101+
"@openclaw/llm-core/validation": [
102+
"../dist/plugin-sdk/packages/llm-core/src/validation.d.ts"
103+
],
104+
"@openclaw/llm-core/*": ["../dist/plugin-sdk/packages/llm-core/src/*.d.ts"],
93105
"@openclaw/*.js": ["../packages/plugin-sdk/dist/extensions/*.d.ts", "../extensions/*"],
94106
"@openclaw/*": ["../packages/plugin-sdk/dist/extensions/*", "../extensions/*"],
95107
"openclaw/plugin-sdk/qa-channel": ["../dist/plugin-sdk/src/plugin-sdk/qa-channel.d.ts"],

extensions/xai/tsconfig.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,24 @@
9393
"../../dist/plugin-sdk/ssrf-runtime.d.ts"
9494
],
9595
"@openclaw/qa-channel/api.js": ["../../dist/plugin-sdk/extensions/qa-channel/api.d.ts"],
96+
"@openclaw/llm-core": [
97+
"../../dist/plugin-sdk/packages/llm-core/src/index.d.ts"
98+
],
99+
"@openclaw/llm-core/diagnostics": [
100+
"../../dist/plugin-sdk/packages/llm-core/src/utils/diagnostics.d.ts"
101+
],
102+
"@openclaw/llm-core/event-stream": [
103+
"../../dist/plugin-sdk/packages/llm-core/src/utils/event-stream.d.ts"
104+
],
105+
"@openclaw/llm-core/types": [
106+
"../../dist/plugin-sdk/packages/llm-core/src/types.d.ts"
107+
],
108+
"@openclaw/llm-core/validation": [
109+
"../../dist/plugin-sdk/packages/llm-core/src/validation.d.ts"
110+
],
111+
"@openclaw/llm-core/*": [
112+
"../../dist/plugin-sdk/packages/llm-core/src/*.d.ts"
113+
],
96114
"@openclaw/*.js": ["../../packages/plugin-sdk/dist/extensions/*.d.ts", "../*"],
97115
"@openclaw/*": ["../*"],
98116
"openclaw/plugin-sdk/qa-channel": [

packages/agent-core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
}
116116
},
117117
"dependencies": {
118+
"@openclaw/llm-core": "workspace:*",
118119
"ignore": "7.0.5",
119120
"typebox": "1.1.38",
120121
"yaml": "2.9.0"

packages/agent-core/src/agent-loop.ts

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@
33
* Transforms to Message[] only at the LLM call boundary.
44
*/
55

6-
import { type AssistantMessage, type Context, EventStream, type ToolResultMessage } from "./llm.js";
6+
// Keep the runtime class on the package specifier so built agent-core shares
7+
// constructor identity with @openclaw/llm-core; source types keep SDK d.ts bundled.
8+
import { EventStream as LlmEventStream } from "@openclaw/llm-core";
9+
import {
10+
type AssistantMessage,
11+
type Context,
12+
type EventStream,
13+
type ToolResultMessage,
14+
} from "../../llm-core/src/index.js";
15+
import type { EventStream as SourceEventStream } from "../../llm-core/src/index.js";
716
import { type AgentCoreStreamRuntimeDeps, resolveAgentCoreStreamFn } from "./runtime-deps.js";
817
import type {
918
AgentContext,
@@ -28,6 +37,8 @@ const EMPTY_USAGE = {
2837
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
2938
};
3039

40+
const EventStreamConstructor: typeof SourceEventStream = LlmEventStream;
41+
3142
/**
3243
* Start an agent loop with a new prompt message.
3344
* The prompt is added to the context and events are emitted for it.
@@ -52,11 +63,13 @@ export function agentLoop(
5263
signal,
5364
streamFn,
5465
runtime,
55-
).then((messages) => {
56-
stream.end(messages);
57-
}).catch((error) => {
58-
pushLoopFailure(stream, config, error, signal?.aborted === true);
59-
});
66+
)
67+
.then((messages) => {
68+
stream.end(messages);
69+
})
70+
.catch((error) => {
71+
pushLoopFailure(stream, config, error, signal?.aborted === true);
72+
});
6073

6174
return stream;
6275
}
@@ -95,11 +108,13 @@ export function agentLoopContinue(
95108
signal,
96109
streamFn,
97110
runtime,
98-
).then((messages) => {
99-
stream.end(messages);
100-
}).catch((error) => {
101-
pushLoopFailure(stream, config, error, signal?.aborted === true);
102-
});
111+
)
112+
.then((messages) => {
113+
stream.end(messages);
114+
})
115+
.catch((error) => {
116+
pushLoopFailure(stream, config, error, signal?.aborted === true);
117+
});
103118

104119
return stream;
105120
}
@@ -157,7 +172,7 @@ export async function runAgentLoopContinue(
157172
}
158173

159174
function createAgentStream(): EventStream<AgentEvent, AgentMessage[]> {
160-
return new EventStream<AgentEvent, AgentMessage[]>(
175+
return new EventStreamConstructor<AgentEvent, AgentMessage[]>(
161176
(event: AgentEvent) => event.type === "agent_end",
162177
(event: AgentEvent) => (event.type === "agent_end" ? event.messages : []),
163178
);

packages/agent-core/src/agent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { runAgentLoop, runAgentLoopContinue } from "./agent-loop.js";
21
import {
32
type ImageContent,
43
type Message,
@@ -7,7 +6,8 @@ import {
76
type TextContent,
87
type ThinkingBudgets,
98
type Transport,
10-
} from "./llm.js";
9+
} from "../../llm-core/src/index.js";
10+
import { runAgentLoop, runAgentLoopContinue } from "./agent-loop.js";
1111
import { type AgentCoreStreamRuntimeDeps, resolveAgentCoreStreamFn } from "./runtime-deps.js";
1212
import type {
1313
AfterToolCallContext,

packages/agent-core/src/harness/agent-harness.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
import {
2+
type AssistantMessage,
3+
type ImageContent,
4+
type Model,
5+
type UserMessage,
6+
} from "../../../llm-core/src/index.js";
17
import { runAgentLoop } from "../agent-loop.js";
2-
import { type AssistantMessage, type ImageContent, type Model, type UserMessage } from "../llm.js";
38
import { type AgentCoreRuntimeDeps, resolveAgentCoreStreamFn } from "../runtime-deps.js";
49
import type {
510
AgentContext,

packages/agent-core/src/harness/compaction/branch-summarization.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Model, StreamFn } from "../../llm.js";
1+
import type { Model, StreamFn } from "../../../../llm-core/src/index.js";
22
import {
33
type AgentCoreCompletionRuntimeDeps,
44
resolveAgentCoreCompleteFn,

packages/agent-core/src/harness/compaction/compaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {
55
SimpleStreamOptions,
66
StreamFn,
77
Usage,
8-
} from "../../llm.js";
8+
} from "../../../../llm-core/src/index.js";
99
import {
1010
type AgentCoreCompletionRuntimeDeps,
1111
resolveAgentCoreCompleteFn,

packages/agent-core/src/harness/compaction/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Message } from "../../llm.js";
1+
import type { Message } from "../../../../llm-core/src/index.js";
22
import type { AgentMessage } from "../../types.js";
33

44
/** File paths touched by a session branch or compaction range. */

0 commit comments

Comments
 (0)