@meetopenbot/claude-code 0.1.15 → 0.1.16
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/dist/index.js +83 -41
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -29,13 +29,12 @@ var resolveClaudeConfig = (context) => {
|
|
|
29
29
|
import { execSync } from "node:child_process";
|
|
30
30
|
import { existsSync } from "node:fs";
|
|
31
31
|
import { join } from "node:path";
|
|
32
|
-
import { query } from "@anthropic-ai/claude-agent-sdk";
|
|
33
32
|
import {
|
|
34
|
-
creditsErrorMessage,
|
|
35
33
|
llmAuthNotConfiguredMessage,
|
|
36
34
|
resolveByokApiKey,
|
|
37
35
|
resolveCreditsAuthConfig as resolveCreditsAuthConfig2,
|
|
38
|
-
isCloudMode
|
|
36
|
+
isCloudMode,
|
|
37
|
+
textReply as textReply2
|
|
39
38
|
} from "@meetopenbot/plugin-sdk";
|
|
40
39
|
|
|
41
40
|
// src/credits.ts
|
|
@@ -62,6 +61,73 @@ var buildCreditsAnthropicEnv = () => {
|
|
|
62
61
|
import { threadSession } from "@meetopenbot/plugin-sdk";
|
|
63
62
|
var claudeSession = threadSession("claudeSessionId");
|
|
64
63
|
|
|
64
|
+
// src/stream.ts
|
|
65
|
+
import { query } from "@anthropic-ai/claude-agent-sdk";
|
|
66
|
+
import {
|
|
67
|
+
createTextReplyBuffer,
|
|
68
|
+
creditsErrorMessage,
|
|
69
|
+
textReply
|
|
70
|
+
} from "@meetopenbot/plugin-sdk";
|
|
71
|
+
var extractText = (content) => {
|
|
72
|
+
if (typeof content === "string") return content;
|
|
73
|
+
if (!Array.isArray(content)) return "";
|
|
74
|
+
const parts = [];
|
|
75
|
+
for (const block of content) {
|
|
76
|
+
if (block && typeof block === "object" && block.type === "text") {
|
|
77
|
+
const text = block.text;
|
|
78
|
+
if (typeof text === "string" && text) parts.push(text);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return parts.join("\n");
|
|
82
|
+
};
|
|
83
|
+
var streamEventText = (event) => {
|
|
84
|
+
if (!event || typeof event !== "object") return "";
|
|
85
|
+
const delta = event.delta;
|
|
86
|
+
if (delta?.type === "text_delta" && typeof delta.text === "string") return delta.text;
|
|
87
|
+
return "";
|
|
88
|
+
};
|
|
89
|
+
var classifyClaudeEvent = (message) => {
|
|
90
|
+
if (message.type === "assistant") {
|
|
91
|
+
const text = extractText(message.message?.content);
|
|
92
|
+
return text ? { type: "text", text } : { type: "skip" };
|
|
93
|
+
}
|
|
94
|
+
if (message.type === "stream_event") {
|
|
95
|
+
const text = streamEventText(message.event);
|
|
96
|
+
return text ? { type: "delta", text } : { type: "skip" };
|
|
97
|
+
}
|
|
98
|
+
return { type: "skip" };
|
|
99
|
+
};
|
|
100
|
+
async function* runClaudeQuery(args) {
|
|
101
|
+
const { prompt, sdkOptions, resumeId, state, storage } = args;
|
|
102
|
+
const replies = createTextReplyBuffer();
|
|
103
|
+
let lastSessionId = resumeId;
|
|
104
|
+
try {
|
|
105
|
+
for await (const message of query({ prompt, options: sdkOptions })) {
|
|
106
|
+
if ("session_id" in message && typeof message.session_id === "string") {
|
|
107
|
+
lastSessionId = message.session_id;
|
|
108
|
+
}
|
|
109
|
+
if (message.type === "result" && message.subtype !== "success") {
|
|
110
|
+
yield* replies.end();
|
|
111
|
+
const resultText = "result" in message && typeof message.result === "string" ? message.result : message.subtype;
|
|
112
|
+
yield textReply(
|
|
113
|
+
creditsErrorMessage(resultText, {
|
|
114
|
+
agentName: "Claude",
|
|
115
|
+
providerLabel: "Anthropic",
|
|
116
|
+
provider: "anthropic"
|
|
117
|
+
}) ?? resultText
|
|
118
|
+
);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
yield* replies.apply(classifyClaudeEvent(message));
|
|
122
|
+
}
|
|
123
|
+
yield* replies.end();
|
|
124
|
+
} finally {
|
|
125
|
+
if (lastSessionId && lastSessionId !== resumeId) {
|
|
126
|
+
await claudeSession.write(state, storage, lastSessionId);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
65
131
|
// src/system-prompt.ts
|
|
66
132
|
var CLAUDE_CODE_SYSTEM_PROMPT = `
|
|
67
133
|
You are Claude, an AI assistant powered by Anthropic's Claude Agent SDK (Claude Code).
|
|
@@ -83,23 +149,16 @@ var findClaudeExecutable = () => {
|
|
|
83
149
|
}
|
|
84
150
|
return void 0;
|
|
85
151
|
};
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (block && typeof block === "object" && block.type === "text") {
|
|
92
|
-
const text = block.text;
|
|
93
|
-
if (typeof text === "string" && text) parts.push(text);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return parts.join("\n");
|
|
97
|
-
};
|
|
98
|
-
async function runClaudeTurn({ prompt, handlerCtx, context }) {
|
|
152
|
+
async function* runClaudeTurn({
|
|
153
|
+
prompt,
|
|
154
|
+
handlerCtx,
|
|
155
|
+
context
|
|
156
|
+
}) {
|
|
99
157
|
const byok = resolveByokApiKey("anthropic");
|
|
100
158
|
const credits = !byok && isCloudMode() ? resolveCreditsAuthConfig2() : void 0;
|
|
101
159
|
if (!byok && !credits) {
|
|
102
|
-
|
|
160
|
+
yield textReply2(llmAuthNotConfiguredMessage("ANTHROPIC_API_KEY"));
|
|
161
|
+
return;
|
|
103
162
|
}
|
|
104
163
|
const config = resolveClaudeConfig(context);
|
|
105
164
|
const workingDir = handlerCtx.state.channelDetails?.cwd;
|
|
@@ -122,30 +181,13 @@ async function runClaudeTurn({ prompt, handlerCtx, context }) {
|
|
|
122
181
|
...workingDir ? { cwd: workingDir } : {},
|
|
123
182
|
...executablePath ? { pathToClaudeCodeExecutable: executablePath } : {}
|
|
124
183
|
};
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const next = extractText(message.message?.content);
|
|
133
|
-
if (next) text = text ? `${text}
|
|
134
|
-
${next}` : next;
|
|
135
|
-
}
|
|
136
|
-
if (message.type === "result" && message.subtype !== "success") {
|
|
137
|
-
const resultText = "result" in message && typeof message.result === "string" ? message.result : message.subtype;
|
|
138
|
-
return creditsErrorMessage(resultText, {
|
|
139
|
-
agentName: "Claude",
|
|
140
|
-
providerLabel: "Anthropic",
|
|
141
|
-
provider: "anthropic"
|
|
142
|
-
}) ?? resultText;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
if (lastSessionId && lastSessionId !== resumeId) {
|
|
146
|
-
await claudeSession.write(handlerCtx.state, context.storage, lastSessionId);
|
|
147
|
-
}
|
|
148
|
-
return text.trim();
|
|
184
|
+
yield* runClaudeQuery({
|
|
185
|
+
prompt,
|
|
186
|
+
sdkOptions,
|
|
187
|
+
resumeId,
|
|
188
|
+
state: handlerCtx.state,
|
|
189
|
+
storage: context.storage
|
|
190
|
+
});
|
|
149
191
|
}
|
|
150
192
|
|
|
151
193
|
// src/index.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meetopenbot/claude-code",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Claude Code plugin for OpenBot",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@anthropic-ai/claude-agent-sdk": "^0.2.138",
|
|
22
|
-
"@meetopenbot/plugin-sdk": "^0.
|
|
22
|
+
"@meetopenbot/plugin-sdk": "^0.4.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/node": "^20.10.1",
|