@byte5ai/palaia 2.0.13 → 2.2.0

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.
package/src/types.ts ADDED
@@ -0,0 +1,119 @@
1
+ /**
2
+ * OpenClaw Plugin SDK types.
3
+ *
4
+ * These interfaces define the contract with OpenClaw's plugin system.
5
+ * They are maintained locally to avoid a build-time dependency on the
6
+ * openclaw package (which is a peerDependency loaded at runtime).
7
+ *
8
+ * Based on OpenClaw v2026.3.22 plugin-sdk.
9
+ */
10
+
11
+ import type { TObject } from "@sinclair/typebox";
12
+
13
+ // ── Tool Types ──────────────────────────────────────────────────────────
14
+
15
+ export interface ToolDefinition {
16
+ name: string;
17
+ description: string;
18
+ parameters: TObject;
19
+ execute(id: string, params: Record<string, unknown>): Promise<ToolResult>;
20
+ }
21
+
22
+ export interface ToolResult {
23
+ content: Array<{ type: "text"; text: string }>;
24
+ }
25
+
26
+ export interface ToolOptions {
27
+ /** Mark this tool as optional (not registered by default). */
28
+ optional?: boolean;
29
+ }
30
+
31
+ export type ToolFactory = ToolDefinition;
32
+
33
+ // ── Hook Types ──────────────────────────────────────────────────────────
34
+
35
+ export type HookName =
36
+ | "before_prompt_build"
37
+ | "agent_end"
38
+ | "message_received"
39
+ | "message_sending";
40
+
41
+ export type HookHandler = (event: unknown, ctx: unknown) => void | Promise<unknown>;
42
+
43
+ export interface HookOptions {
44
+ priority?: number;
45
+ }
46
+
47
+ // ── Command Types ───────────────────────────────────────────────────────
48
+
49
+ export interface CommandDefinition {
50
+ name: string;
51
+ description: string;
52
+ handler(args: string): Promise<{ text: string }> | { text: string };
53
+ }
54
+
55
+ // ── Service Types ───────────────────────────────────────────────────────
56
+
57
+ export interface ServiceDefinition {
58
+ id: string;
59
+ start(): Promise<void>;
60
+ stop?(): Promise<void>;
61
+ }
62
+
63
+ // ── Context Engine Types ────────────────────────────────────────────────
64
+
65
+ export interface ContextEngine {
66
+ bootstrap?(): Promise<void>;
67
+ ingest?(messages: unknown[]): Promise<void>;
68
+ assemble(budget: { maxTokens: number }): Promise<{ content: string; tokenEstimate: number }>;
69
+ compact?(): Promise<void>;
70
+ afterTurn?(turn: unknown): Promise<void>;
71
+ prepareSubagentSpawn?(parentContext: unknown): Promise<unknown>;
72
+ onSubagentEnded?(result: unknown): Promise<void>;
73
+ }
74
+
75
+ // ── Logger ──────────────────────────────────────────────────────────────
76
+
77
+ export interface PluginLogger {
78
+ info(...args: unknown[]): void;
79
+ warn(...args: unknown[]): void;
80
+ error?(...args: unknown[]): void;
81
+ debug?(...args: unknown[]): void;
82
+ }
83
+
84
+ // ── Runtime ─────────────────────────────────────────────────────────────
85
+
86
+ export interface PluginRuntime {
87
+ agent?: {
88
+ runEmbeddedPiAgent?(params: Record<string, unknown>): Promise<unknown>;
89
+ };
90
+ modelAuth?: {
91
+ resolveApiKeyForProvider(params: {
92
+ provider: string;
93
+ cfg: Record<string, unknown>;
94
+ }): Promise<string | null>;
95
+ };
96
+ }
97
+
98
+ // ── Main Plugin API ─────────────────────────────────────────────────────
99
+
100
+ export interface OpenClawPluginApi {
101
+ registerTool(definition: ToolDefinition, options?: ToolOptions): void;
102
+ registerCommand(command: CommandDefinition): void;
103
+ registerService(service: ServiceDefinition): void;
104
+ registerContextEngine?(id: string, engine: ContextEngine): void;
105
+ on(hook: HookName | string, handler: HookHandler): void;
106
+ getConfig(pluginId: string): Record<string, unknown> | undefined;
107
+ logger: PluginLogger;
108
+ runtime: PluginRuntime;
109
+ config: Record<string, unknown>;
110
+ workspace?: { dir: string; agentId?: string } | string;
111
+ }
112
+
113
+ // ── Plugin Entry ────────────────────────────────────────────────────────
114
+
115
+ export interface OpenClawPluginEntry {
116
+ id: string;
117
+ name: string;
118
+ register(api: OpenClawPluginApi): void | Promise<void>;
119
+ }