@joshualelon/clawdbot-skill-flow 0.2.0 → 0.2.2
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/clawdbot.plugin.json +1 -1
- package/index.ts +108 -1
- package/package.json +1 -1
package/clawdbot.plugin.json
CHANGED
package/index.ts
CHANGED
|
@@ -4,12 +4,16 @@
|
|
|
4
4
|
|
|
5
5
|
import type { ClawdbotPluginApi } from "clawdbot/plugin-sdk";
|
|
6
6
|
import { parseSkillFlowConfig } from "./src/config.js";
|
|
7
|
-
import { initSessionStore } from "./src/state/session-store.js";
|
|
7
|
+
import { initSessionStore, createSession, getSessionKey } from "./src/state/session-store.js";
|
|
8
8
|
import { createFlowStartCommand } from "./src/commands/flow-start.js";
|
|
9
9
|
import { createFlowStepCommand } from "./src/commands/flow-step.js";
|
|
10
10
|
import { createFlowCreateCommand } from "./src/commands/flow-create.js";
|
|
11
11
|
import { createFlowListCommand } from "./src/commands/flow-list.js";
|
|
12
12
|
import { createFlowDeleteCommand } from "./src/commands/flow-delete.js";
|
|
13
|
+
import { saveFlow, loadFlow, listFlows } from "./src/state/flow-store.js";
|
|
14
|
+
import { startFlow } from "./src/engine/executor.js";
|
|
15
|
+
import { FlowMetadataSchema } from "./src/validation.js";
|
|
16
|
+
import type { FlowMetadata } from "./src/types.js";
|
|
13
17
|
|
|
14
18
|
const plugin = {
|
|
15
19
|
id: "skill-flow",
|
|
@@ -66,6 +70,109 @@ const plugin = {
|
|
|
66
70
|
handler: createFlowDeleteCommand(api),
|
|
67
71
|
});
|
|
68
72
|
|
|
73
|
+
// Register gateway methods for programmatic access
|
|
74
|
+
// @ts-expect-error - registerGatewayMethod exists at runtime, types will be available in future clawdbot release
|
|
75
|
+
api.registerGatewayMethod("skill-flow.create", async ({ params, respond }) => {
|
|
76
|
+
try {
|
|
77
|
+
const flow: FlowMetadata = FlowMetadataSchema.parse(params);
|
|
78
|
+
await saveFlow(api, flow);
|
|
79
|
+
api.logger.info(`Created flow "${flow.name}" via gateway method`);
|
|
80
|
+
respond(true, {
|
|
81
|
+
success: true,
|
|
82
|
+
flowName: flow.name,
|
|
83
|
+
message: `Flow "${flow.name}" created successfully`,
|
|
84
|
+
});
|
|
85
|
+
} catch (error) {
|
|
86
|
+
api.logger.error("Gateway method skill-flow.create failed:", error);
|
|
87
|
+
respond(false, {
|
|
88
|
+
error: error instanceof Error ? error.message : "Failed to create flow",
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// @ts-expect-error - registerGatewayMethod exists at runtime, types will be available in future clawdbot release
|
|
94
|
+
api.registerGatewayMethod("skill-flow.list", async ({ respond }) => {
|
|
95
|
+
try {
|
|
96
|
+
const flows = await listFlows(api);
|
|
97
|
+
respond(true, {
|
|
98
|
+
flows: flows.map((f) => ({
|
|
99
|
+
name: f.name,
|
|
100
|
+
description: f.description,
|
|
101
|
+
version: f.version,
|
|
102
|
+
author: f.author,
|
|
103
|
+
})),
|
|
104
|
+
});
|
|
105
|
+
} catch (error) {
|
|
106
|
+
api.logger.error("Gateway method skill-flow.list failed:", error);
|
|
107
|
+
respond(false, {
|
|
108
|
+
error: error instanceof Error ? error.message : "Failed to list flows",
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// @ts-expect-error - registerGatewayMethod exists at runtime, types will be available in future clawdbot release
|
|
114
|
+
api.registerGatewayMethod("skill-flow.start", async ({ params, respond }) => {
|
|
115
|
+
try {
|
|
116
|
+
const { flowName, senderId, channel } = params as {
|
|
117
|
+
flowName: string;
|
|
118
|
+
senderId: string;
|
|
119
|
+
channel: string;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
if (!flowName || !senderId || !channel) {
|
|
123
|
+
respond(false, {
|
|
124
|
+
error: "Missing required parameters: flowName, senderId, channel",
|
|
125
|
+
});
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Load flow
|
|
130
|
+
const flow = await loadFlow(api, flowName);
|
|
131
|
+
if (!flow) {
|
|
132
|
+
respond(false, {
|
|
133
|
+
error: `Flow "${flowName}" not found`,
|
|
134
|
+
});
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Verify flow has steps
|
|
139
|
+
if (!flow.steps || flow.steps.length === 0) {
|
|
140
|
+
respond(false, {
|
|
141
|
+
error: `Flow "${flowName}" has no steps`,
|
|
142
|
+
});
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Create session
|
|
147
|
+
const session = createSession({
|
|
148
|
+
flowName: flow.name,
|
|
149
|
+
currentStepId: flow.steps[0]!.id,
|
|
150
|
+
senderId,
|
|
151
|
+
channel,
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
api.logger.info(
|
|
155
|
+
`Started flow "${flowName}" for user ${senderId} via gateway method (session: ${getSessionKey(senderId, flowName)})`
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
// Get the first step response
|
|
159
|
+
const response = startFlow(api, flow, session);
|
|
160
|
+
|
|
161
|
+
respond(true, {
|
|
162
|
+
success: true,
|
|
163
|
+
sessionId: getSessionKey(senderId, flowName),
|
|
164
|
+
flowName: flow.name,
|
|
165
|
+
message: `Flow "${flowName}" started`,
|
|
166
|
+
response,
|
|
167
|
+
});
|
|
168
|
+
} catch (error) {
|
|
169
|
+
api.logger.error("Gateway method skill-flow.start failed:", error);
|
|
170
|
+
respond(false, {
|
|
171
|
+
error: error instanceof Error ? error.message : "Failed to start flow",
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
|
|
69
176
|
api.logger.info("Skill Flow plugin registered successfully", {
|
|
70
177
|
sessionTimeoutMinutes: config.sessionTimeoutMinutes,
|
|
71
178
|
enableBuiltinHistory: config.enableBuiltinHistory,
|