Skip to content

Commit d38e01d

Browse files
chore: sync from internal
1 parent 0e39f89 commit d38e01d

10 files changed

Lines changed: 389 additions & 40 deletions

File tree

packages/cli/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,5 @@ export type { DeviceCodeAuthDisplayOptions } from "./auth/DeviceCodeAuthProvider
132132
export type { PhantomClient } from "@phantom/client";
133133
export { tools, getTool, getToolNames } from "./tools/index.js";
134134
export type { ToolHandler, ToolContext, ToolInputSchema } from "./tools/types.js";
135+
export { PluginConfigSchema, PluginConfigJsonSchema } from "./plugin-config.js";
136+
export type { PluginConfig } from "./plugin-config.js";

packages/cli/src/plugin-config.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { z } from "zod";
2+
3+
const TrimmedStringSchema = z.string().trim().min(1).optional().catch(undefined);
4+
5+
const PortSchema = z.coerce.number().int().min(1).max(65535).optional().catch(undefined);
6+
7+
export const PluginConfigSchema = z.object({
8+
PHANTOM_AUTH_BASE_URL: TrimmedStringSchema,
9+
PHANTOM_CONNECT_BASE_URL: TrimmedStringSchema,
10+
PHANTOM_WALLETS_API_BASE_URL: TrimmedStringSchema,
11+
PHANTOM_API_BASE_URL: TrimmedStringSchema,
12+
PHANTOM_VERSION: TrimmedStringSchema,
13+
PHANTOM_CALLBACK_PORT: PortSchema,
14+
PHANTOM_CALLBACK_PATH: TrimmedStringSchema,
15+
PHANTOM_MCP_DEBUG: TrimmedStringSchema,
16+
PHANTOM_APP_ID: TrimmedStringSchema,
17+
PHANTOM_CLIENT_ID: TrimmedStringSchema,
18+
});
19+
20+
export type PluginConfig = z.infer<typeof PluginConfigSchema>;
21+
22+
export const PluginConfigJsonSchema = z.toJSONSchema(PluginConfigSchema);

packages/cli/tsup.config.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
import { defineConfig } from "tsup";
22

3+
const BIG_INT_WARNING_PREFIX = "bigint: Failed to load bindings, pure JS will be used";
4+
const PUNYCODE_DEPRECATION_WARNING_CODE = "DEP0040";
5+
6+
const suppressNoisyWarnings = `
7+
const __origWarn = console.warn;
8+
console.warn = (...args) => {
9+
if (typeof args[0] === "string" && args[0].startsWith("${BIG_INT_WARNING_PREFIX}")) return;
10+
__origWarn.apply(console, args);
11+
};
12+
const __origEmitWarning = process.emitWarning.bind(process);
13+
process.emitWarning = (warning, ...args) => {
14+
if (args[1] === "${PUNYCODE_DEPRECATION_WARNING_CODE}") return;
15+
__origEmitWarning(warning, ...args);
16+
};
17+
`;
18+
319
export default defineConfig({
420
entry: ["src/index.ts", "src/bin.ts"],
521
format: ["cjs"],
@@ -8,4 +24,5 @@ export default defineConfig({
824
platform: "node",
925
target: "node18",
1026
noExternal: [/.*/],
27+
banner: { js: suppressNoisyWarnings },
1128
});

packages/phantom-openclaw-plugin/openclaw.plugin.json

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"skills": ["./skills"],
66
"configSchema": {
77
"type": "object",
8-
"additionalProperties": false,
98
"properties": {
109
"PHANTOM_AUTH_BASE_URL": {
1110
"type": "string",
@@ -37,9 +36,19 @@
3736
"minLength": 1
3837
},
3938
"PHANTOM_MCP_DEBUG": {
40-
"type": "string"
39+
"type": "string",
40+
"minLength": 1
41+
},
42+
"PHANTOM_APP_ID": {
43+
"type": "string",
44+
"minLength": 1
45+
},
46+
"PHANTOM_CLIENT_ID": {
47+
"type": "string",
48+
"minLength": 1
4149
}
42-
}
50+
},
51+
"additionalProperties": false
4352
},
4453
"uiHints": {
4554
"PHANTOM_AUTH_BASE_URL": {
@@ -69,6 +78,14 @@
6978
"PHANTOM_MCP_DEBUG": {
7079
"label": "Enable Debug Logging",
7180
"placeholder": "1"
81+
},
82+
"PHANTOM_APP_ID": {
83+
"label": "App ID",
84+
"placeholder": "your-app-id"
85+
},
86+
"PHANTOM_CLIENT_ID": {
87+
"label": "Client ID",
88+
"placeholder": "your-client-id"
7289
}
7390
}
7491
}

packages/phantom-openclaw-plugin/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@phantom/phantom-openclaw-plugin",
3-
"version": "1.2.3",
3+
"version": "1.2.4",
44
"description": "Phantom Embedded Wallet — sign transactions, transfer tokens, and swap on Solana and Ethereum. Powered by Phantom.",
55
"repository": {
66
"type": "git",
@@ -25,7 +25,8 @@
2525
"scripts": {
2626
"?pack-release": "When https://github.com/changesets/changesets/issues/432 has a solution we can remove this trick",
2727
"pack-release": "rimraf ./_release && yarn pack && mkdir ./_release && tar zxvf ./package.tgz --directory ./_release && rm ./package.tgz",
28-
"build": "rimraf ./dist && tsup",
28+
"generate": "tsx scripts/generate-manifest.ts && yarn prettier --write openclaw.plugin.json",
29+
"build": "yarn generate && rimraf ./dist && tsup",
2930
"dev": "tsup --watch",
3031
"clean": "rimraf dist",
3132
"test": "jest",
@@ -43,6 +44,7 @@
4344
"rimraf": "^6.0.1",
4445
"ts-jest": "^29.1.2",
4546
"tsup": "^6.7.0",
47+
"tsx": "^4.21.0",
4648
"typescript": "^5.0.4"
4749
},
4850
"dependencies": {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { PluginConfigJsonSchema } from "@phantom/cli";
2+
import { readFileSync, writeFileSync } from "node:fs";
3+
import { dirname, resolve } from "node:path";
4+
import { fileURLToPath } from "node:url";
5+
6+
const dir = dirname(fileURLToPath(import.meta.url));
7+
const manifestPath = resolve(dir, "..", "openclaw.plugin.json");
8+
9+
const existing = JSON.parse(readFileSync(manifestPath, "utf-8")) as Record<string, unknown>;
10+
11+
const { $schema, ...configSchema } = { ...PluginConfigJsonSchema, additionalProperties: false } as Record<
12+
string,
13+
unknown
14+
>;
15+
void $schema;
16+
17+
writeFileSync(manifestPath, JSON.stringify({ ...existing, configSchema }, null, 2) + "\n");
18+
// eslint-disable-next-line no-console
19+
console.log("Generated configSchema in openclaw.plugin.json");
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"rootDir": ".",
5+
"noEmit": true
6+
},
7+
"include": ["./**/*"]
8+
}

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

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,12 @@
88
import type { OpenClawApi } from "./client/types.js";
99
import { PluginSession } from "./session.js";
1010
import { registerPhantomTools } from "./tools/register-tools.js";
11+
import { PluginConfigSchema } from "@phantom/cli";
1112

1213
// Singleton session instance
1314
let sessionInstance: PluginSession | null = null;
1415
const PLUGIN_ID = "phantom-openclaw-plugin";
1516

16-
const STRING_CONFIG_KEYS = [
17-
"PHANTOM_AUTH_BASE_URL",
18-
"PHANTOM_CONNECT_BASE_URL",
19-
"PHANTOM_WALLETS_API_BASE_URL",
20-
"PHANTOM_API_BASE_URL",
21-
"PHANTOM_VERSION",
22-
"PHANTOM_CALLBACK_PATH",
23-
"PHANTOM_MCP_DEBUG",
24-
] as const;
25-
2617
function isRecord(value: unknown): value is Record<string, unknown> {
2718
return typeof value === "object" && value !== null;
2819
}
@@ -60,29 +51,14 @@ function getPluginConfig(fullConfig?: Record<string, unknown>): Record<string, u
6051
}
6152

6253
function applyConfigToEnv(config?: Record<string, unknown>): void {
63-
if (!config) {
64-
return;
65-
}
66-
67-
for (const key of STRING_CONFIG_KEYS) {
68-
const value = config[key];
69-
if (typeof value === "string" && value.trim().length > 0) {
70-
process.env[key] = value.trim();
71-
}
72-
}
73-
74-
const rawPort = config.PHANTOM_CALLBACK_PORT;
75-
let parsedPort: number | null = null;
54+
if (!config) return;
7655

77-
if (typeof rawPort === "number") {
78-
parsedPort = rawPort;
79-
} else if (typeof rawPort === "string") {
80-
const parsed = Number.parseInt(rawPort, 10);
81-
parsedPort = Number.isNaN(parsed) ? null : parsed;
82-
}
56+
const pluginConfig = PluginConfigSchema.parse(config);
8357

84-
if (parsedPort !== null && Number.isInteger(parsedPort) && parsedPort > 0 && parsedPort <= 65535) {
85-
process.env.PHANTOM_CALLBACK_PORT = String(parsedPort);
58+
for (const [key, value] of Object.entries(pluginConfig)) {
59+
if (value !== undefined) {
60+
process.env[key] = String(value);
61+
}
8662
}
8763
}
8864

@@ -93,9 +69,8 @@ function getSession(config?: Record<string, unknown>): PluginSession {
9369
if (!sessionInstance) {
9470
const pluginConfig = getPluginConfig(config);
9571
applyConfigToEnv(pluginConfig);
96-
const envPort = process.env.PHANTOM_CALLBACK_PORT?.trim();
97-
const parsedPort = envPort ? Number.parseInt(envPort, 10) : NaN;
98-
const callbackPort = Number.isInteger(parsedPort) && parsedPort > 0 && parsedPort <= 65535 ? parsedPort : undefined;
72+
const envPort = process.env.PHANTOM_CALLBACK_PORT;
73+
const callbackPort = envPort ? Number.parseInt(envPort, 10) : undefined;
9974

10075
sessionInstance = new PluginSession({
10176
callbackPort,

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,6 @@ export function registerPhantomTools(api: OpenClawApi, pluginSession: PluginSess
352352
baseUrl: process.env.PHANTOM_API_BASE_URL ?? "https://api.phantom.app",
353353
});
354354
const manager = new SessionManager();
355-
void manager.initialize();
356355

357356
const staticHeaders: Record<string, string> = {
358357
[ANALYTICS_HEADER_PLATFORM]: "ext-sdk",

0 commit comments

Comments
 (0)