@ynhcj/xiaoyi 0.0.1-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/README.md +207 -0
  2. package/dist/auth.d.ts +36 -0
  3. package/dist/auth.js +111 -0
  4. package/dist/channel.d.ts +189 -0
  5. package/dist/channel.js +354 -0
  6. package/dist/config-schema.d.ts +46 -0
  7. package/dist/config-schema.js +28 -0
  8. package/dist/file-download.d.ts +17 -0
  9. package/dist/file-download.js +69 -0
  10. package/dist/file-handler.d.ts +36 -0
  11. package/dist/file-handler.js +113 -0
  12. package/dist/index.d.ts +29 -0
  13. package/dist/index.js +49 -0
  14. package/dist/onboarding.d.ts +6 -0
  15. package/dist/onboarding.js +167 -0
  16. package/dist/push.d.ts +28 -0
  17. package/dist/push.js +135 -0
  18. package/dist/runtime.d.ts +191 -0
  19. package/dist/runtime.js +438 -0
  20. package/dist/types.d.ts +280 -0
  21. package/dist/types.js +8 -0
  22. package/dist/websocket.d.ts +219 -0
  23. package/dist/websocket.js +1068 -0
  24. package/dist/xiaoyi-media.d.ts +81 -0
  25. package/dist/xiaoyi-media.js +216 -0
  26. package/dist/xy-bot.d.ts +19 -0
  27. package/dist/xy-bot.js +277 -0
  28. package/dist/xy-client.d.ts +26 -0
  29. package/dist/xy-client.js +78 -0
  30. package/dist/xy-config.d.ts +18 -0
  31. package/dist/xy-config.js +37 -0
  32. package/dist/xy-formatter.d.ts +94 -0
  33. package/dist/xy-formatter.js +303 -0
  34. package/dist/xy-monitor.d.ts +17 -0
  35. package/dist/xy-monitor.js +194 -0
  36. package/dist/xy-parser.d.ts +49 -0
  37. package/dist/xy-parser.js +109 -0
  38. package/dist/xy-reply-dispatcher.d.ts +17 -0
  39. package/dist/xy-reply-dispatcher.js +308 -0
  40. package/dist/xy-tools/session-manager.d.ts +29 -0
  41. package/dist/xy-tools/session-manager.js +80 -0
  42. package/dist/xy-utils/config-manager.d.ts +26 -0
  43. package/dist/xy-utils/config-manager.js +61 -0
  44. package/dist/xy-utils/crypto.d.ts +8 -0
  45. package/dist/xy-utils/crypto.js +21 -0
  46. package/dist/xy-utils/logger.d.ts +6 -0
  47. package/dist/xy-utils/logger.js +37 -0
  48. package/dist/xy-utils/session.d.ts +34 -0
  49. package/dist/xy-utils/session.js +55 -0
  50. package/openclaw.plugin.json +9 -0
  51. package/package.json +73 -0
  52. package/xiaoyi.js +1 -0
@@ -0,0 +1,29 @@
1
+ import type { XiaoYiChannelConfig } from "../types.js";
2
+ export interface SessionContext {
3
+ config: XiaoYiChannelConfig;
4
+ sessionId: string;
5
+ taskId: string;
6
+ messageId: string;
7
+ agentId: string;
8
+ }
9
+ /**
10
+ * Register a session context for tool access.
11
+ * Should be called when starting to process a message.
12
+ */
13
+ export declare function registerSession(sessionKey: string, context: SessionContext): void;
14
+ /**
15
+ * Unregister a session context.
16
+ * Should be called when message processing is complete.
17
+ */
18
+ export declare function unregisterSession(sessionKey: string): void;
19
+ /**
20
+ * Get session context by sessionKey.
21
+ * Returns null if session not found.
22
+ */
23
+ export declare function getSessionContext(sessionKey: string): SessionContext | null;
24
+ /**
25
+ * Get the most recent session context.
26
+ * This is a fallback for tools that don't have access to sessionKey.
27
+ * Returns null if no sessions are active.
28
+ */
29
+ export declare function getLatestSessionContext(): SessionContext | null;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerSession = registerSession;
4
+ exports.unregisterSession = unregisterSession;
5
+ exports.getSessionContext = getSessionContext;
6
+ exports.getLatestSessionContext = getLatestSessionContext;
7
+ const logger_js_1 = require("../xy-utils/logger.js");
8
+ const config_manager_js_1 = require("../xy-utils/config-manager.js");
9
+ // Map of sessionKey -> SessionContext
10
+ const activeSessions = new Map();
11
+ /**
12
+ * Register a session context for tool access.
13
+ * Should be called when starting to process a message.
14
+ */
15
+ function registerSession(sessionKey, context) {
16
+ logger_js_1.logger.log(`[SESSION_MANAGER] 📝 Registering session: ${sessionKey}`);
17
+ logger_js_1.logger.log(`[SESSION_MANAGER] - sessionId: ${context.sessionId}`);
18
+ logger_js_1.logger.log(`[SESSION_MANAGER] - taskId: ${context.taskId}`);
19
+ logger_js_1.logger.log(`[SESSION_MANAGER] - messageId: ${context.messageId}`);
20
+ logger_js_1.logger.log(`[SESSION_MANAGER] - agentId: ${context.agentId}`);
21
+ logger_js_1.logger.log(`[SESSION_MANAGER] - Active sessions before: ${activeSessions.size}`);
22
+ activeSessions.set(sessionKey, context);
23
+ logger_js_1.logger.log(`[SESSION_MANAGER] - Active sessions after: ${activeSessions.size}`);
24
+ logger_js_1.logger.log(`[SESSION_MANAGER] - All session keys: [${Array.from(activeSessions.keys()).join(", ")}]`);
25
+ }
26
+ /**
27
+ * Unregister a session context.
28
+ * Should be called when message processing is complete.
29
+ */
30
+ function unregisterSession(sessionKey) {
31
+ logger_js_1.logger.log(`[SESSION_MANAGER] 🗑️ Unregistering session: ${sessionKey}`);
32
+ logger_js_1.logger.log(`[SESSION_MANAGER] - Active sessions before: ${activeSessions.size}`);
33
+ logger_js_1.logger.log(`[SESSION_MANAGER] - Session existed: ${activeSessions.has(sessionKey)}`);
34
+ // Get session context before deleting to clear associated pushId
35
+ const context = activeSessions.get(sessionKey);
36
+ const existed = activeSessions.delete(sessionKey);
37
+ // Clear cached pushId for this session
38
+ if (context) {
39
+ config_manager_js_1.configManager.clearSession(context.sessionId);
40
+ }
41
+ logger_js_1.logger.log(`[SESSION_MANAGER] - Deleted: ${existed}`);
42
+ logger_js_1.logger.log(`[SESSION_MANAGER] - Active sessions after: ${activeSessions.size}`);
43
+ logger_js_1.logger.log(`[SESSION_MANAGER] - Remaining session keys: [${Array.from(activeSessions.keys()).join(", ")}]`);
44
+ }
45
+ /**
46
+ * Get session context by sessionKey.
47
+ * Returns null if session not found.
48
+ */
49
+ function getSessionContext(sessionKey) {
50
+ logger_js_1.logger.log(`[SESSION_MANAGER] 🔍 Getting session by key: ${sessionKey}`);
51
+ logger_js_1.logger.log(`[SESSION_MANAGER] - Active sessions: ${activeSessions.size}`);
52
+ const context = activeSessions.get(sessionKey) ?? null;
53
+ logger_js_1.logger.log(`[SESSION_MANAGER] - Found: ${context !== null}`);
54
+ if (context) {
55
+ logger_js_1.logger.log(`[SESSION_MANAGER] - sessionId: ${context.sessionId}`);
56
+ }
57
+ return context;
58
+ }
59
+ /**
60
+ * Get the most recent session context.
61
+ * This is a fallback for tools that don't have access to sessionKey.
62
+ * Returns null if no sessions are active.
63
+ */
64
+ function getLatestSessionContext() {
65
+ logger_js_1.logger.log(`[SESSION_MANAGER] 🔍 Getting latest session context`);
66
+ logger_js_1.logger.log(`[SESSION_MANAGER] - Active sessions count: ${activeSessions.size}`);
67
+ logger_js_1.logger.log(`[SESSION_MANAGER] - Active session keys: [${Array.from(activeSessions.keys()).join(", ")}]`);
68
+ if (activeSessions.size === 0) {
69
+ logger_js_1.logger.error(`[SESSION_MANAGER] - ❌ No active sessions found!`);
70
+ return null;
71
+ }
72
+ // Return the last added session
73
+ const sessions = Array.from(activeSessions.values());
74
+ const latestSession = sessions[sessions.length - 1];
75
+ logger_js_1.logger.log(`[SESSION_MANAGER] - ✅ Found latest session:`);
76
+ logger_js_1.logger.log(`[SESSION_MANAGER] - sessionId: ${latestSession.sessionId}`);
77
+ logger_js_1.logger.log(`[SESSION_MANAGER] - taskId: ${latestSession.taskId}`);
78
+ logger_js_1.logger.log(`[SESSION_MANAGER] - messageId: ${latestSession.messageId}`);
79
+ return latestSession;
80
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Manages dynamic configuration updates that can change at runtime.
3
+ * Specifically handles pushId which can be updated per-session.
4
+ */
5
+ declare class ConfigManager {
6
+ private sessionPushIds;
7
+ private globalPushId;
8
+ /**
9
+ * Update push ID for a specific session.
10
+ */
11
+ updatePushId(sessionId: string, pushId: string): void;
12
+ /**
13
+ * Get push ID for a session (falls back to global if not found).
14
+ */
15
+ getPushId(sessionId?: string): string | null;
16
+ /**
17
+ * Clear push ID for a session.
18
+ */
19
+ clearSession(sessionId: string): void;
20
+ /**
21
+ * Clear all cached push IDs.
22
+ */
23
+ clear(): void;
24
+ }
25
+ export declare const configManager: ConfigManager;
26
+ export {};
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configManager = void 0;
4
+ // Dynamic configuration manager for runtime updates
5
+ const logger_js_1 = require("./logger.js");
6
+ /**
7
+ * Manages dynamic configuration updates that can change at runtime.
8
+ * Specifically handles pushId which can be updated per-session.
9
+ */
10
+ class ConfigManager {
11
+ constructor() {
12
+ this.sessionPushIds = new Map();
13
+ this.globalPushId = null;
14
+ }
15
+ /**
16
+ * Update push ID for a specific session.
17
+ */
18
+ updatePushId(sessionId, pushId) {
19
+ if (!pushId) {
20
+ logger_js_1.logger.warn(`[ConfigManager] Attempted to set empty pushId for session ${sessionId}`);
21
+ return;
22
+ }
23
+ const previous = this.sessionPushIds.get(sessionId);
24
+ if (previous !== pushId) {
25
+ logger_js_1.logger.log(`[ConfigManager] ✨ Updated pushId for session ${sessionId}`);
26
+ logger_js_1.logger.log(`[ConfigManager] - Previous: ${previous ? previous.substring(0, 20) + '...' : 'none'}`);
27
+ logger_js_1.logger.log(`[ConfigManager] - New: ${pushId.substring(0, 20)}...`);
28
+ logger_js_1.logger.log(`[ConfigManager] - Full new pushId: ${pushId}`);
29
+ this.sessionPushIds.set(sessionId, pushId);
30
+ this.globalPushId = pushId; // Also update global for backward compatibility
31
+ }
32
+ }
33
+ /**
34
+ * Get push ID for a session (falls back to global if not found).
35
+ */
36
+ getPushId(sessionId) {
37
+ if (sessionId) {
38
+ const sessionPushId = this.sessionPushIds.get(sessionId);
39
+ if (sessionPushId) {
40
+ return sessionPushId;
41
+ }
42
+ }
43
+ return this.globalPushId;
44
+ }
45
+ /**
46
+ * Clear push ID for a session.
47
+ */
48
+ clearSession(sessionId) {
49
+ this.sessionPushIds.delete(sessionId);
50
+ logger_js_1.logger.debug(`[ConfigManager] Cleared pushId for session ${sessionId}`);
51
+ }
52
+ /**
53
+ * Clear all cached push IDs.
54
+ */
55
+ clear() {
56
+ this.sessionPushIds.clear();
57
+ this.globalPushId = null;
58
+ logger_js_1.logger.debug(`[ConfigManager] Cleared all cached pushIds`);
59
+ }
60
+ }
61
+ exports.configManager = new ConfigManager();
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Calculate SHA256 hash of a buffer.
3
+ */
4
+ export declare function calculateSHA256(buffer: Buffer): string;
5
+ /**
6
+ * Calculate SHA256 hash of a string.
7
+ */
8
+ export declare function calculateSHA256String(text: string): string;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.calculateSHA256 = calculateSHA256;
7
+ exports.calculateSHA256String = calculateSHA256String;
8
+ // Cryptographic utilities
9
+ const crypto_1 = __importDefault(require("crypto"));
10
+ /**
11
+ * Calculate SHA256 hash of a buffer.
12
+ */
13
+ function calculateSHA256(buffer) {
14
+ return crypto_1.default.createHash("sha256").update(buffer).digest("hex");
15
+ }
16
+ /**
17
+ * Calculate SHA256 hash of a string.
18
+ */
19
+ function calculateSHA256String(text) {
20
+ return crypto_1.default.createHash("sha256").update(text, "utf8").digest("hex");
21
+ }
@@ -0,0 +1,6 @@
1
+ export declare const logger: {
2
+ log(message: string, ...args: any[]): void;
3
+ warn(message: string, ...args: any[]): void;
4
+ error(message: string, ...args: any[]): void;
5
+ debug(message: string, ...args: any[]): void;
6
+ };
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.logger = void 0;
4
+ // Logging utilities for XY channel
5
+ const runtime_js_1 = require("../runtime.js");
6
+ /**
7
+ * Log a message using the OpenClaw runtime logger.
8
+ */
9
+ function logMessage(level, message, ...args) {
10
+ try {
11
+ const runtime = (0, runtime_js_1.getXiaoYiRuntime)();
12
+ const logFn = runtime[level];
13
+ if (logFn) {
14
+ const formattedMessage = `[XY] ${message}`;
15
+ logFn(formattedMessage, ...args);
16
+ }
17
+ }
18
+ catch (error) {
19
+ // Fallback to console if runtime not available
20
+ console[level](`[XY] ${message}`, ...args);
21
+ }
22
+ }
23
+ exports.logger = {
24
+ log(message, ...args) {
25
+ logMessage("log", message, ...args);
26
+ },
27
+ warn(message, ...args) {
28
+ logMessage("warn", message, ...args);
29
+ },
30
+ error(message, ...args) {
31
+ logMessage("error", message, ...args);
32
+ },
33
+ debug(message, ...args) {
34
+ // Debug messages go to log level
35
+ logMessage("log", `[DEBUG] ${message}`, ...args);
36
+ },
37
+ };
@@ -0,0 +1,34 @@
1
+ import type { SessionBinding, ServerIdentifier } from "../types.js";
2
+ /**
3
+ * Session-to-server binding cache.
4
+ * Tracks which WebSocket server each session is bound to.
5
+ */
6
+ declare class SessionManager {
7
+ private bindings;
8
+ /**
9
+ * Bind a session to a specific server.
10
+ */
11
+ bind(sessionId: string, server: ServerIdentifier): void;
12
+ /**
13
+ * Get the server binding for a session.
14
+ */
15
+ getBinding(sessionId: string): ServerIdentifier | null;
16
+ /**
17
+ * Check if a session is bound to a server.
18
+ */
19
+ isBound(sessionId: string): boolean;
20
+ /**
21
+ * Unbind a session.
22
+ */
23
+ unbind(sessionId: string): void;
24
+ /**
25
+ * Clear all bindings.
26
+ */
27
+ clear(): void;
28
+ /**
29
+ * Get all bindings.
30
+ */
31
+ getAll(): SessionBinding[];
32
+ }
33
+ export declare const sessionManager: SessionManager;
34
+ export {};
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sessionManager = void 0;
4
+ /**
5
+ * Session-to-server binding cache.
6
+ * Tracks which WebSocket server each session is bound to.
7
+ */
8
+ class SessionManager {
9
+ constructor() {
10
+ this.bindings = new Map();
11
+ }
12
+ /**
13
+ * Bind a session to a specific server.
14
+ */
15
+ bind(sessionId, server) {
16
+ this.bindings.set(sessionId, {
17
+ sessionId,
18
+ server,
19
+ boundAt: Date.now(),
20
+ });
21
+ }
22
+ /**
23
+ * Get the server binding for a session.
24
+ */
25
+ getBinding(sessionId) {
26
+ const binding = this.bindings.get(sessionId);
27
+ return binding ? binding.server : null;
28
+ }
29
+ /**
30
+ * Check if a session is bound to a server.
31
+ */
32
+ isBound(sessionId) {
33
+ return this.bindings.has(sessionId);
34
+ }
35
+ /**
36
+ * Unbind a session.
37
+ */
38
+ unbind(sessionId) {
39
+ this.bindings.delete(sessionId);
40
+ }
41
+ /**
42
+ * Clear all bindings.
43
+ */
44
+ clear() {
45
+ this.bindings.clear();
46
+ }
47
+ /**
48
+ * Get all bindings.
49
+ */
50
+ getAll() {
51
+ return Array.from(this.bindings.values());
52
+ }
53
+ }
54
+ // Singleton instance
55
+ exports.sessionManager = new SessionManager();
@@ -0,0 +1,9 @@
1
+ {
2
+ "id": "xiaoyi",
3
+ "channels": ["xiaoyi"],
4
+ "configSchema": {
5
+ "type": "object",
6
+ "additionalProperties": true,
7
+ "properties": {}
8
+ }
9
+ }
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "@ynhcj/xiaoyi",
3
+ "version": "0.0.1-beta",
4
+ "description": "XiaoYi channel plugin for OpenClaw",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc && node fix-imports.js",
9
+ "prepublishOnly": "npm run build"
10
+ },
11
+ "keywords": [
12
+ "openclaw",
13
+ "openclaw-plugin",
14
+ "xiaoyi",
15
+ "channel"
16
+ ],
17
+ "author": "ynhcj",
18
+ "license": "MIT",
19
+ "openclaw": {
20
+ "extensions": [
21
+ "xiaoyi.js"
22
+ ],
23
+ "channels": [
24
+ "xiaoyi"
25
+ ],
26
+ "installDependencies": true,
27
+ "install": {
28
+ "npmSpec": "@ynhcj/xiaoyi@latest",
29
+ "localPath": ".",
30
+ "defaultChoice": "npm"
31
+ },
32
+ "channel": {
33
+ "id": "xiaoyi",
34
+ "label": "XiaoYi",
35
+ "selectionLabel": "XiaoYi (小艺)",
36
+ "docsPath": "/channels/xiaoyi",
37
+ "docsLabel": "xiaoyi",
38
+ "blurb": "小艺 A2A 协议支持,通过 WebSocket 连接。",
39
+ "order": 80,
40
+ "aliases": [
41
+ "xy"
42
+ ]
43
+ }
44
+ },
45
+ "peerDependencies": {
46
+ "openclaw": "*"
47
+ },
48
+ "peerDependenciesMeta": {
49
+ "openclaw": {
50
+ "optional": true
51
+ }
52
+ },
53
+ "dependencies": {
54
+ "node-fetch": "^3.3.2",
55
+ "uuid": "^13.0.0",
56
+ "ws": "^8.16.0",
57
+ "zod": "^3.22.4"
58
+ },
59
+ "devDependencies": {
60
+ "@types/node": "^20.11.0",
61
+ "@types/node-fetch": "^2.6.13",
62
+ "@types/uuid": "^10.0.0",
63
+ "@types/ws": "^8.5.10",
64
+ "openclaw": "^2026.3.13",
65
+ "typescript": "^5.3.3"
66
+ },
67
+ "files": [
68
+ "dist",
69
+ "xiaoyi.js",
70
+ "openclaw.plugin.json",
71
+ "README.md"
72
+ ]
73
+ }
package/xiaoyi.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/index.js');