Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"dependencies": {
"@clawe/backend": "workspace:*",
"@clawe/shared": "workspace:*",
"@clawe/ui": "workspace:*",
"@tanstack/react-query": "^5.75.5",
"@tiptap/core": "^3.15.3",
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/api/agency/health/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NextResponse } from "next/server";
import { checkHealth } from "@/lib/openclaw/client";
import { checkHealth } from "@clawe/shared/openclaw";

export async function POST() {
const result = await checkHealth();
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/api/agency/pairing/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NextResponse } from "next/server";
import {
listChannelPairingRequests,
approveChannelPairingCode,
} from "@/lib/openclaw/pairing";
} from "@clawe/shared/openclaw";

// GET /api/agency/pairing?channel=telegram - List pending pairing requests
export async function GET(request: Request) {
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/api/chat/abort/route.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const mockRequest = vi.fn();
const mockConnect = vi.fn();
const mockClose = vi.fn();

vi.mock("@/lib/openclaw/gateway-client", () => ({
vi.mock("@clawe/shared/openclaw", () => ({
createGatewayClient: vi.fn(() => ({
connect: mockConnect,
request: mockRequest,
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/api/chat/abort/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NextRequest, NextResponse } from "next/server";
import { createGatewayClient } from "@/lib/openclaw/gateway-client";
import { createGatewayClient } from "@clawe/shared/openclaw";

export const runtime = "nodejs";
export const dynamic = "force-dynamic";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/api/chat/history/route.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const mockRequest = vi.fn();
const mockConnect = vi.fn();
const mockClose = vi.fn();

vi.mock("@/lib/openclaw/gateway-client", () => ({
vi.mock("@clawe/shared/openclaw", () => ({
createGatewayClient: vi.fn(() => ({
connect: mockConnect,
request: mockRequest,
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/app/api/chat/history/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NextRequest, NextResponse } from "next/server";
import { createGatewayClient } from "@/lib/openclaw/gateway-client";
import type { ChatHistoryResponse } from "@/lib/openclaw/gateway-types";
import { createGatewayClient } from "@clawe/shared/openclaw";
import type { ChatHistoryResponse } from "@clawe/shared/openclaw";

export const runtime = "nodejs";
export const dynamic = "force-dynamic";
Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/app/api/chat/route.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { NextRequest } from "next/server";
import { POST } from "./route";

// Mock the gateway client
vi.mock("@/lib/openclaw/gateway-client", () => ({
vi.mock("@clawe/shared/openclaw", () => ({
createGatewayClient: vi.fn(() => ({
connect: vi.fn().mockResolvedValue({ type: "hello-ok", protocol: 3 }),
request: vi.fn().mockResolvedValue({}),
close: vi.fn(),
isConnected: vi.fn().mockReturnValue(true),
})),
GatewayClient: vi.fn(),
}));

describe("POST /api/chat", () => {
Expand Down
7 changes: 2 additions & 5 deletions apps/web/src/app/api/chat/route.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { NextRequest } from "next/server";
import {
GatewayClient,
createGatewayClient,
} from "@/lib/openclaw/gateway-client";
import { GatewayClient, createGatewayClient } from "@clawe/shared/openclaw";
import type {
ChatEvent,
ChatSendParams,
ChatAttachment,
} from "@/lib/openclaw/gateway-types";
} from "@clawe/shared/openclaw";

export const runtime = "nodejs";
export const dynamic = "force-dynamic";
Expand Down
7 changes: 4 additions & 3 deletions apps/web/src/lib/openclaw/actions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { describe, it, expect, vi, beforeEach } from "vitest";

// Mock the client module
vi.mock("./client", () => ({
// Mock the shared package
vi.mock("@clawe/shared/openclaw", () => ({
checkHealth: vi.fn(),
getConfig: vi.fn(),
saveTelegramBotToken: vi.fn(),
probeTelegramToken: vi.fn(),
approveChannelPairingCode: vi.fn(),
}));

import {
Expand All @@ -17,7 +18,7 @@ import {
checkHealth,
saveTelegramBotToken as saveTelegramBotTokenClient,
probeTelegramToken,
} from "./client";
} from "@clawe/shared/openclaw";

describe("OpenClaw Actions", () => {
beforeEach(() => {
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/lib/openclaw/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
getConfig,
saveTelegramBotToken as saveTelegramBotTokenClient,
probeTelegramToken,
} from "./client";
import { approveChannelPairingCode } from "./pairing";
} from "@clawe/shared/openclaw";
import { approveChannelPairingCode } from "@clawe/shared/openclaw";

export async function checkOpenClawHealth() {
return checkHealth();
Expand Down
4 changes: 4 additions & 0 deletions packages/shared/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { config } from "@clawe/eslint-config/base";

/** @type {import("eslint").Linter.Config} */
export default config;
32 changes: 32 additions & 0 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "@clawe/shared",
"version": "0.1.0",
"private": true,
"type": "module",
"exports": {
"./openclaw": {
"types": "./src/openclaw/index.ts",
"default": "./src/openclaw/index.ts"
}
},
"scripts": {
"lint": "eslint . --max-warnings 0",
"lint:fix": "eslint . --fix --max-warnings 0",
"check-types": "tsc --noEmit",
"test": "vitest run",
"test:watch": "vitest"
},
"dependencies": {
"axios": "^1.13.4",
"ws": "^8.19.0"
},
"devDependencies": {
"@clawe/eslint-config": "workspace:*",
"@clawe/typescript-config": "workspace:*",
"@types/node": "^22.15.3",
"@types/ws": "^8.18.1",
"eslint": "^9.39.1",
"typescript": "5.9.2",
"vitest": "^4.0.18"
}
}
64 changes: 64 additions & 0 deletions packages/shared/src/openclaw/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Client
export {
checkHealth,
saveTelegramBotToken,
probeTelegramToken,
getConfig,
patchConfig,
listSessions,
sendMessage,
} from "./client";

// Gateway Client
export { GatewayClient, createGatewayClient } from "./gateway-client";
export type { GatewayClientOptions } from "./gateway-client";

// Pairing
export {
listChannelPairingRequests,
approveChannelPairingCode,
} from "./pairing";

// Types
export type {
ToolResult,
ConfigGetResult,
ConfigPatchResult,
Session,
SessionsListResult,
ChannelStatus,
GatewayHealthResult,
TelegramProbeResult,
PairingRequest,
PairingListResult,
PairingApproveResult,
} from "./types";

// Gateway Types
export type {
GatewayRequestFrame,
GatewayResponseFrame,
GatewayEventFrame,
GatewayFrame,
GatewayError,
ConnectParams,
HelloOkResponse,
ChatSendParams,
ChatHistoryParams,
ChatAbortParams,
ChatAttachment,
ChatEventState,
ChatEvent,
ChatUsage,
MessageRole,
ChatMessage,
MessageContent,
TextContent,
ImageContent,
ToolUseContent,
ToolResultContent,
ThinkingContent,
ChatHistoryResponse,
SSEEventType,
SSEEvent,
} from "./gateway-types";
10 changes: 10 additions & 0 deletions packages/shared/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "@clawe/typescript-config/base.json",
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "bundler",
"noEmit": true
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
}
9 changes: 9 additions & 0 deletions packages/shared/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
globals: false,
environment: "node",
include: ["src/**/*.spec.ts"],
},
});
36 changes: 36 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.