@gfrmin/credence-pi-openclaw 0.1.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.
@@ -0,0 +1,158 @@
1
+ // openclaw-types.ts — minimal local declarations of the OpenClaw plugin
2
+ // API surface this body consumes.
3
+ //
4
+ // Sourced from OpenClaw (HEAD 36a596aa9f, 2026-06-02):
5
+ // - src/plugins/types.ts (OpenClawPluginApi, api.on)
6
+ // - src/plugins/hook-types.ts (before_tool_call / after_tool_call /
7
+ // llm_output events + results)
8
+ //
9
+ // We declare ONLY what we consume so the plugin builds standalone with no
10
+ // @openclaw/openclaw dependency — mirroring the dependency-free pattern of
11
+ // apps/openclaw-plugin/ (which used `api: any`). At runtime OpenClaw calls
12
+ // register(api) with the real, fully-typed api; these declarations are our
13
+ // compile-time view. If the host surface drifts, the runtime still works;
14
+ // only this file needs occasional resync. Keep it narrow.
15
+
16
+ export type PluginApprovalResolution =
17
+ | "allow-once"
18
+ | "allow-always"
19
+ | "deny"
20
+ | "timeout"
21
+ | "cancelled";
22
+
23
+ export interface RequireApprovalPayload {
24
+ title: string;
25
+ description: string;
26
+ severity?: "info" | "warning" | "critical";
27
+ timeoutMs?: number;
28
+ timeoutBehavior?: "allow" | "deny";
29
+ allowedDecisions?: Array<"allow-once" | "allow-always" | "deny">;
30
+ pluginId?: string;
31
+ onResolution?: (decision: PluginApprovalResolution) => Promise<void> | void;
32
+ }
33
+
34
+ export interface BeforeToolCallEvent {
35
+ toolName: string;
36
+ params: Record<string, unknown>;
37
+ toolKind?: string;
38
+ toolInputKind?: string;
39
+ runId?: string;
40
+ toolCallId?: string;
41
+ derivedPaths?: readonly string[];
42
+ }
43
+
44
+ export interface BeforeToolCallResult {
45
+ params?: Record<string, unknown>;
46
+ block?: boolean;
47
+ blockReason?: string;
48
+ requireApproval?: RequireApprovalPayload;
49
+ }
50
+
51
+ export interface AfterToolCallEvent {
52
+ toolName: string;
53
+ params: Record<string, unknown>;
54
+ runId?: string;
55
+ toolCallId?: string;
56
+ result?: unknown;
57
+ error?: string;
58
+ durationMs?: number;
59
+ }
60
+
61
+ export interface LlmUsage {
62
+ input?: number;
63
+ output?: number;
64
+ cacheRead?: number;
65
+ cacheWrite?: number;
66
+ total?: number;
67
+ }
68
+
69
+ export interface LlmOutputEvent {
70
+ runId?: string;
71
+ sessionId?: string;
72
+ provider?: string;
73
+ model?: string;
74
+ resolvedRef?: string;
75
+ usage?: LlmUsage;
76
+ }
77
+
78
+ export interface ToolContext {
79
+ agentId?: string;
80
+ sessionKey?: string;
81
+ sessionId?: string;
82
+ runId?: string;
83
+ toolName?: string;
84
+ toolCallId?: string;
85
+ channelId?: string;
86
+ workspaceDir?: string;
87
+ }
88
+
89
+ export interface PluginLogger {
90
+ info?: (msg: string) => void;
91
+ warn?: (msg: string) => void;
92
+ error?: (msg: string) => void;
93
+ }
94
+
95
+ export type HookHandler<E, R = void> = (
96
+ event: E,
97
+ ctx: ToolContext,
98
+ ) => Promise<R | void> | R | void;
99
+
100
+ export interface HookOpts {
101
+ priority?: number;
102
+ timeoutMs?: number;
103
+ }
104
+
105
+ export interface OpenClawPluginApi {
106
+ id?: string;
107
+ logger?: PluginLogger;
108
+ // This plugin's resolved config (validated against openclaw.plugin.json).
109
+ pluginConfig?: Record<string, unknown>;
110
+
111
+ // Cleanup hooks run on reset/delete/reload paths
112
+ // (OpenClaw src/plugins/host-hooks.ts PluginRuntimeLifecycleRegistration).
113
+ // Optional so the plugin still loads on hosts that predate it.
114
+ lifecycle?: {
115
+ registerRuntimeLifecycle: (registration: {
116
+ id: string;
117
+ description?: string;
118
+ cleanup?: (ctx: {
119
+ reason?: string;
120
+ sessionKey?: string;
121
+ runId?: string;
122
+ }) => void | Promise<void>;
123
+ }) => void;
124
+ };
125
+
126
+ on(
127
+ hook: "before_tool_call",
128
+ handler: HookHandler<BeforeToolCallEvent, BeforeToolCallResult>,
129
+ opts?: HookOpts,
130
+ ): void;
131
+ on(
132
+ hook: "after_tool_call",
133
+ handler: HookHandler<AfterToolCallEvent, void>,
134
+ opts?: HookOpts,
135
+ ): void;
136
+ on(
137
+ hook: "llm_output",
138
+ handler: HookHandler<LlmOutputEvent, void>,
139
+ opts?: HookOpts,
140
+ ): void;
141
+ // Catch-all for hooks we register opportunistically (e.g. agent_end);
142
+ // typed loosely on purpose.
143
+ on(
144
+ hook: string,
145
+ handler: (...args: unknown[]) => unknown,
146
+ opts?: HookOpts,
147
+ ): void;
148
+ }
149
+
150
+ // The default export shape OpenClaw loads. apps/openclaw-plugin/ exported a
151
+ // bare object literal of this shape (works via compat); we do the same to
152
+ // stay dependency-free (no `definePluginEntry` import from the host).
153
+ export interface PluginEntry {
154
+ id: string;
155
+ name: string;
156
+ description?: string;
157
+ register: (api: OpenClawPluginApi) => void | Promise<void>;
158
+ }