Skip to content

Commit ee45e93

Browse files
chore: sync from internal
1 parent dd832e1 commit ee45e93

7 files changed

Lines changed: 32 additions & 31 deletions

File tree

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@phantom/cli",
3-
"version": "1.2.4",
3+
"version": "1.2.5",
44
"description": "Phantom CLI — interact with your Phantom wallet from the terminal",
55
"repository": {
66
"type": "git",

packages/mcp-server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@phantom/mcp-server",
3-
"version": "1.2.4",
3+
"version": "1.2.5",
44
"description": "MCP Server for Phantom Wallet",
55
"repository": {
66
"type": "git",
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import baseConfig from "../../eslint.shared.mjs";
2+
3+
export default [
4+
...baseConfig,
5+
{
6+
files: ["**/*.ts"],
7+
rules: {
8+
"no-restricted-syntax": [
9+
"error",
10+
{
11+
selector: "MemberExpression[object.name='process'][property.name='env']",
12+
message: "Do not use process.env — pass config explicitly.",
13+
},
14+
],
15+
},
16+
},
17+
];

packages/phantom-openclaw-plugin/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@phantom/phantom-openclaw-plugin",
3-
"version": "1.2.4",
3+
"version": "1.2.5",
44
"description": "Phantom Embedded Wallet — sign transactions, transfer tokens, and swap on Solana and Ethereum. Powered by Phantom.",
55
"repository": {
66
"type": "git",

packages/phantom-openclaw-plugin/src/index.ts

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,28 +50,11 @@ function getPluginConfig(fullConfig?: Record<string, unknown>): Record<string, u
5050
return fullConfig;
5151
}
5252

53-
function applyConfigToEnv(config?: Record<string, unknown>): void {
54-
if (!config) return;
55-
56-
const pluginConfig = PluginConfigSchema.parse(config);
57-
58-
for (const [key, value] of Object.entries(pluginConfig)) {
59-
if (value !== undefined) {
60-
process.env[key] = String(value);
61-
}
62-
}
63-
}
64-
6553
/**
6654
* Get or create the plugin session with configuration
6755
*/
68-
function getSession(config?: Record<string, unknown>): PluginSession {
56+
function getSession(callbackPort?: number): PluginSession {
6957
if (!sessionInstance) {
70-
const pluginConfig = getPluginConfig(config);
71-
applyConfigToEnv(pluginConfig);
72-
const envPort = process.env.PHANTOM_CALLBACK_PORT;
73-
const callbackPort = envPort ? Number.parseInt(envPort, 10) : undefined;
74-
7558
sessionInstance = new PluginSession({
7659
callbackPort,
7760
authFlow: "device-code",
@@ -92,8 +75,10 @@ function resetSession(): void {
9275
*/
9376
export default function register(api: OpenClawApi) {
9477
try {
95-
const session = getSession(api.config);
96-
registerPhantomTools(api, session);
78+
const rawConfig = getPluginConfig(api.config) ?? {};
79+
const config = PluginConfigSchema.parse(rawConfig);
80+
const session = getSession(config.PHANTOM_CALLBACK_PORT);
81+
registerPhantomTools(api, session, config);
9782
} catch (error) {
9883
console.error("Failed to initialize Phantom OpenClaw plugin:", error);
9984
// Reset singleton so next attempt gets a fresh instance

packages/phantom-openclaw-plugin/src/tools/register-tools.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function registerToolsForTest() {
6868
getOAuthHeaders: jest.fn().mockReturnValue({ authorization: "Bearer token", "x-auth-user-id": "user-1" }),
6969
} as unknown as PluginSession;
7070

71-
registerPhantomTools(api, session);
71+
registerPhantomTools(api, session, {});
7272
return { registeredTools, registeredContexts };
7373
}
7474

packages/phantom-openclaw-plugin/src/tools/register-tools.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44

55
import { Type } from "@sinclair/typebox";
66
import type { TSchema } from "@sinclair/typebox";
7-
import { SessionManager, tools } from "@phantom/cli";
7+
import { SessionManager, tools, type PluginConfig, type ToolContext } from "@phantom/cli";
88
import { PhantomApiClient } from "@phantom/phantom-api-client";
99
import type { OpenClawApi } from "../client/types.js";
1010
import type { PluginSession } from "../session.js";
1111
import * as packageJson from "../../package.json";
12-
import type { ToolContext } from "@phantom/cli";
1312

1413
/**
1514
* Convert MCP tool JSON schema to TypeBox schema
@@ -347,16 +346,16 @@ function addPluginVersion(result: unknown): unknown {
347346
/**
348347
* Register all Phantom MCP tools with OpenClaw
349348
*/
350-
export function registerPhantomTools(api: OpenClawApi, pluginSession: PluginSession): void {
349+
export function registerPhantomTools(api: OpenClawApi, pluginSession: PluginSession, config: PluginConfig): void {
351350
const apiClient = new PhantomApiClient({
352-
baseUrl: process.env.PHANTOM_API_BASE_URL ?? "https://api.phantom.app",
351+
baseUrl: config.PHANTOM_API_BASE_URL ?? "https://api.phantom.app",
353352
});
354353
const manager = new SessionManager();
355354

356355
const staticHeaders: Record<string, string> = {
357356
[ANALYTICS_HEADER_PLATFORM]: "ext-sdk",
358357
[ANALYTICS_HEADER_CLIENT]: "mcp",
359-
[ANALYTICS_HEADER_SDK_VERSION]: process.env.PHANTOM_VERSION ?? packageJson.version ?? "unknown",
358+
[ANALYTICS_HEADER_SDK_VERSION]: config.PHANTOM_VERSION ?? packageJson.version ?? "unknown",
360359
};
361360
apiClient.setHeaders(staticHeaders);
362361
apiClient.setGetHeaders(() => pluginSession.getOAuthHeaders());
@@ -464,8 +463,8 @@ export function registerPhantomTools(api: OpenClawApi, pluginSession: PluginSess
464463

465464
const sessionData = pluginSession.getSession();
466465
const appId =
467-
process.env.PHANTOM_APP_ID ??
468-
process.env.PHANTOM_CLIENT_ID ??
466+
config.PHANTOM_APP_ID ??
467+
config.PHANTOM_CLIENT_ID ??
469468
(typeof sessionData.appId === "string" ? sessionData.appId : undefined);
470469
if (appId) {
471470
apiClient.setHeaders({

0 commit comments

Comments
 (0)