mirror of
https://github.com/lobehub/lobehub
synced 2026-04-21 09:37:28 +00:00
♻️ refactor: extract agent-stream into @lobechat/agent-gateway-client package (#13866)
* ♻️ refactor: extract agent-stream into @lobechat/agent-gateway-client package
Move the Agent Gateway WebSocket client from src/libs/agent-stream/ into
a standalone workspace package at packages/agent-gateway-client/. This
eliminates the duplicate AgentStreamEvent type in apps/cli and provides
a single source of truth for the Gateway WS protocol types shared by
SPA, server, and CLI consumers.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* add agent-gateway-client
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
f6c70210f2
commit
dd81642d83
18 changed files with 56 additions and 27 deletions
|
|
@ -28,6 +28,7 @@
|
|||
"type-check": "tsc --noEmit"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@lobechat/agent-gateway-client": "workspace:*",
|
||||
"@lobechat/device-gateway-client": "workspace:*",
|
||||
"@lobechat/local-file-shell": "workspace:*",
|
||||
"@trpc/client": "^11.8.1",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
packages:
|
||||
- '../../packages/agent-gateway-client'
|
||||
- '../../packages/device-gateway-client'
|
||||
- '../../packages/local-file-shell'
|
||||
- '../../packages/file-loaders'
|
||||
|
|
|
|||
|
|
@ -1,16 +1,10 @@
|
|||
import type { AgentStreamEvent } from '@lobechat/agent-gateway-client';
|
||||
import pc from 'picocolors';
|
||||
import urlJoin from 'url-join';
|
||||
|
||||
import { log } from './logger';
|
||||
|
||||
export interface AgentStreamEvent {
|
||||
data: any;
|
||||
id?: string;
|
||||
operationId: string;
|
||||
stepIndex: number;
|
||||
timestamp: number;
|
||||
type: string;
|
||||
}
|
||||
export type { AgentStreamEvent } from '@lobechat/agent-gateway-client';
|
||||
|
||||
interface StreamOptions {
|
||||
json?: boolean;
|
||||
|
|
|
|||
|
|
@ -200,6 +200,7 @@
|
|||
"@khmyznikov/pwa-install": "0.3.9",
|
||||
"@larksuiteoapi/node-sdk": "^1.60.0",
|
||||
"@lexical/utils": "^0.42.0",
|
||||
"@lobechat/agent-gateway-client": "workspace:*",
|
||||
"@lobechat/agent-runtime": "workspace:*",
|
||||
"@lobechat/agent-templates": "workspace:*",
|
||||
"@lobechat/builtin-agents": "workspace:*",
|
||||
|
|
|
|||
18
packages/agent-gateway-client/package.json
Normal file
18
packages/agent-gateway-client/package.json
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"name": "@lobechat/agent-gateway-client",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"description": "Browser-compatible WebSocket client for the LobeHub Agent Gateway",
|
||||
"exports": {
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
"main": "./src/index.ts",
|
||||
"types": "./src/index.ts",
|
||||
"scripts": {
|
||||
"test": "bunx vitest run --silent='passed-only'",
|
||||
"test:coverage": "bunx vitest run --coverage"
|
||||
},
|
||||
"devDependencies": {
|
||||
"vitest": "^3.0.0"
|
||||
}
|
||||
}
|
||||
18
packages/agent-gateway-client/vitest.config.mts
Normal file
18
packages/agent-gateway-client/vitest.config.mts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import { defineConfig } from 'vitest/config';
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
coverage: {
|
||||
exclude: [
|
||||
'coverage/**',
|
||||
'dist/**',
|
||||
'**/node_modules/**',
|
||||
'**/*.d.ts',
|
||||
'**/*.config.*',
|
||||
'**/index.ts',
|
||||
],
|
||||
reporter: ['text', 'json', 'lcov', 'text-summary'],
|
||||
},
|
||||
environment: 'happy-dom',
|
||||
},
|
||||
});
|
||||
|
|
@ -1,8 +1,7 @@
|
|||
import type { ToolExecuteData } from '@lobechat/agent-gateway-client';
|
||||
import debug from 'debug';
|
||||
import urlJoin from 'url-join';
|
||||
|
||||
import type { ToolExecuteData } from '@/libs/agent-stream/types';
|
||||
|
||||
import {
|
||||
getDefaultReasonDetail,
|
||||
type StreamChunkData,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import type { ToolExecuteData } from '@lobechat/agent-gateway-client';
|
||||
import { type AgentState } from '@lobechat/agent-runtime';
|
||||
|
||||
import type { ToolExecuteData } from '@/libs/agent-stream/types';
|
||||
|
||||
import { type AgentOperationMetadata, type StepResult } from './AgentStateManager';
|
||||
import { type StreamChunkData, type StreamEvent } from './StreamEventManager';
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import type { ToolExecuteData } from '@lobechat/agent-gateway-client';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import type { ToolExecuteData } from '@/libs/agent-stream';
|
||||
|
||||
import { ClientToolExecutionActionImpl } from '../clientToolExecution';
|
||||
|
||||
// ─── Hoisted mocks ───
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import type { AgentStreamEvent } from '@lobechat/agent-gateway-client';
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import type { AgentStreamEvent } from '@/libs/agent-stream';
|
||||
import { aiAgentService } from '@/services/aiAgent';
|
||||
|
||||
import type { GatewayConnection } from '../gateway';
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import type { AgentStreamEvent } from '@lobechat/agent-gateway-client';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import type { AgentStreamEvent } from '@/libs/agent-stream';
|
||||
|
||||
import { createGatewayEventHandler } from '../gatewayEventHandler';
|
||||
|
||||
vi.mock('@/services/message', () => ({
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { type ToolExecuteData, type ToolResultMessage } from '@lobechat/agent-gateway-client';
|
||||
import { type BuiltinToolContext } from '@lobechat/types';
|
||||
import debug from 'debug';
|
||||
import { produce } from 'immer';
|
||||
|
||||
import { type ToolExecuteData, type ToolResultMessage } from '@/libs/agent-stream';
|
||||
import { mcpService } from '@/services/mcp';
|
||||
import { type ChatStore } from '@/store/chat/store';
|
||||
import { hasExecutor, invokeExecutor } from '@/store/tool/slices/builtin/executors';
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import {
|
||||
AgentStreamClient,
|
||||
type AgentStreamClientOptions,
|
||||
type AgentStreamEvent,
|
||||
type ConnectionStatus,
|
||||
} from '@lobechat/agent-gateway-client';
|
||||
import type { ConversationContext, ExecAgentResult } from '@lobechat/types';
|
||||
|
||||
import { isDesktop } from '@/const/version';
|
||||
import type {
|
||||
AgentStreamClientOptions,
|
||||
AgentStreamEvent,
|
||||
ConnectionStatus,
|
||||
} from '@/libs/agent-stream';
|
||||
import { AgentStreamClient } from '@/libs/agent-stream/client';
|
||||
import { aiAgentService, type ResumeApprovalParam } from '@/services/aiAgent';
|
||||
import { messageService } from '@/services/message';
|
||||
import { topicService } from '@/services/topic';
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import type { ConversationContext } from '@lobechat/types';
|
||||
|
||||
import type {
|
||||
AgentStreamEvent,
|
||||
StepCompleteData,
|
||||
StreamChunkData,
|
||||
StreamStartData,
|
||||
ToolExecuteData,
|
||||
} from '@/libs/agent-stream';
|
||||
} from '@lobechat/agent-gateway-client';
|
||||
import type { ConversationContext } from '@lobechat/types';
|
||||
|
||||
import { messageService } from '@/services/message';
|
||||
import type { ChatStore } from '@/store/chat/store';
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue