chrome-openclaw-sider 1.0.2 → 1.0.26
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/README.md +11 -1
- package/README.zh_CN.md +8 -6
- package/dist/index.d.ts +12 -0
- package/{index.ts → dist/index.js} +24 -17
- package/dist/setup-entry.d.ts +18 -0
- package/dist/setup-entry.js +8 -0
- package/dist/src/account.d.ts +54 -0
- package/{src/account.ts → dist/src/account.js} +70 -160
- package/dist/src/auth.d.ts +30 -0
- package/{src/auth.ts → dist/src/auth.js} +61 -128
- package/dist/src/auto-title.d.ts +20 -0
- package/dist/src/auto-title.js +22 -0
- package/dist/src/channel-auto-title.d.ts +23 -0
- package/dist/src/channel-auto-title.js +77 -0
- package/dist/src/channel-builders.d.ts +105 -0
- package/dist/src/channel-builders.js +238 -0
- package/dist/src/channel-hooks.d.ts +30 -0
- package/dist/src/channel-hooks.js +331 -0
- package/dist/src/channel-monitor.d.ts +34 -0
- package/dist/src/channel-monitor.js +341 -0
- package/dist/src/channel-relay.d.ts +117 -0
- package/dist/src/channel-relay.js +573 -0
- package/dist/src/channel-runtime.d.ts +32 -0
- package/dist/src/channel-runtime.js +85 -0
- package/dist/src/channel-send-result.d.ts +19 -0
- package/dist/src/channel-send-result.js +126 -0
- package/dist/src/channel-session-model.d.ts +19 -0
- package/dist/src/channel-session-model.js +244 -0
- package/dist/src/channel-state.d.ts +92 -0
- package/dist/src/channel-state.js +471 -0
- package/dist/src/channel-streaming.d.ts +117 -0
- package/dist/src/channel-streaming.js +645 -0
- package/dist/src/channel-types.d.ts +207 -0
- package/dist/src/channel-types.js +40 -0
- package/dist/src/channel-typing.d.ts +17 -0
- package/dist/src/channel-typing.js +79 -0
- package/dist/src/channel-util.d.ts +78 -0
- package/dist/src/channel-util.js +524 -0
- package/dist/src/channel.d.ts +14 -0
- package/dist/src/channel.js +1023 -0
- package/dist/src/config.d.ts +18 -0
- package/dist/src/config.js +38 -0
- package/dist/src/inbound-media.d.ts +37 -0
- package/{src/inbound-media.ts → dist/src/inbound-media.js} +33 -81
- package/dist/src/media-upload.d.ts +86 -0
- package/dist/src/media-upload.js +1222 -0
- package/dist/src/setup-core.d.ts +72 -0
- package/{src/setup-core.ts → dist/src/setup-core.js} +106 -194
- package/dist/src/user-agent.d.ts +4 -0
- package/dist/src/user-agent.js +6 -0
- package/openclaw.plugin.json +86 -0
- package/package.json +9 -13
- package/setup-entry.ts +0 -6
- package/src/channel.ts +0 -3862
- package/src/config.ts +0 -29
- package/src/media-upload.ts +0 -983
- package/src/remote-browser-support.ts +0 -64
- package/src/user-agent.ts +0 -17
|
@@ -1,70 +1,36 @@
|
|
|
1
|
-
import { type OpenClawConfig, type PluginRuntime } from "openclaw/plugin-sdk";
|
|
2
1
|
import { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk/account-id";
|
|
3
|
-
import { type OpenClawPluginService } from "openclaw/plugin-sdk/plugin-entry";
|
|
4
2
|
import {
|
|
5
3
|
SIDER_CHANNEL_ID,
|
|
6
4
|
SIDER_DEFAULT_BASE_URL,
|
|
5
|
+
SIDER_SERVICE_ID,
|
|
7
6
|
readDefaultSiderSetupTokenEnv,
|
|
8
|
-
readSiderBaseUrlEnv
|
|
7
|
+
readSiderBaseUrlEnv
|
|
9
8
|
} from "./config.js";
|
|
10
9
|
import { SIDER_USER_AGENT } from "./user-agent.js";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
setupToken?: string;
|
|
16
|
-
token?: string;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
type SiderRegisterResponse = {
|
|
20
|
-
claw_id: string;
|
|
21
|
-
token: string;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
type SiderResolvedCredentials = {
|
|
25
|
-
token: string;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
type SiderAuthSetupServiceParams = {
|
|
29
|
-
listAccountIds: (cfg: OpenClawConfig) => string[];
|
|
30
|
-
getAccountSetupConfig: (
|
|
31
|
-
cfg: OpenClawConfig,
|
|
32
|
-
accountId: string,
|
|
33
|
-
) => SiderSetupConfigSnapshot;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
let runtimeRef: PluginRuntime | null = null;
|
|
37
|
-
const pendingAccountOperations = new Map<string, Promise<OpenClawConfig>>();
|
|
38
|
-
|
|
39
|
-
function getSiderAuthRuntime(): PluginRuntime {
|
|
10
|
+
const SIDER_AUTH_EXCHANGE_API_PATH = "/v1/claws/register";
|
|
11
|
+
let runtimeRef = null;
|
|
12
|
+
const pendingAccountOperations = /* @__PURE__ */ new Map();
|
|
13
|
+
function getSiderAuthRuntime() {
|
|
40
14
|
if (!runtimeRef) {
|
|
41
15
|
throw new Error("sider auth runtime not initialized");
|
|
42
16
|
}
|
|
43
17
|
return runtimeRef;
|
|
44
18
|
}
|
|
45
|
-
|
|
46
|
-
function trimMaybe(value: string | undefined): string | undefined {
|
|
19
|
+
function trimMaybe(value) {
|
|
47
20
|
const trimmed = value?.trim();
|
|
48
|
-
return trimmed ||
|
|
21
|
+
return trimmed || void 0;
|
|
49
22
|
}
|
|
50
|
-
|
|
51
|
-
function normalizeGatewayUrl(raw?: string): string | undefined {
|
|
23
|
+
function normalizeGatewayUrl(raw) {
|
|
52
24
|
const trimmed = trimMaybe(raw);
|
|
53
|
-
return trimmed ? trimmed.replace(/\/+$/, "") :
|
|
25
|
+
return trimmed ? trimmed.replace(/\/+$/, "") : void 0;
|
|
54
26
|
}
|
|
55
|
-
|
|
56
|
-
export function resolveSiderBaseUrl(): string {
|
|
27
|
+
function resolveSiderBaseUrl() {
|
|
57
28
|
return normalizeGatewayUrl(readSiderBaseUrlEnv()) ?? SIDER_DEFAULT_BASE_URL;
|
|
58
29
|
}
|
|
59
|
-
|
|
60
|
-
function getPendingOperation(accountId: string): Promise<OpenClawConfig> | undefined {
|
|
30
|
+
function getPendingOperation(accountId) {
|
|
61
31
|
return pendingAccountOperations.get(accountId);
|
|
62
32
|
}
|
|
63
|
-
|
|
64
|
-
async function withPendingOperation(
|
|
65
|
-
accountId: string,
|
|
66
|
-
run: () => Promise<OpenClawConfig>,
|
|
67
|
-
): Promise<OpenClawConfig> {
|
|
33
|
+
async function withPendingOperation(accountId, run) {
|
|
68
34
|
const existing = getPendingOperation(accountId);
|
|
69
35
|
if (existing) {
|
|
70
36
|
return await existing;
|
|
@@ -79,8 +45,7 @@ async function withPendingOperation(
|
|
|
79
45
|
pendingAccountOperations.set(accountId, pending);
|
|
80
46
|
return await pending;
|
|
81
47
|
}
|
|
82
|
-
|
|
83
|
-
function buildSiderApiUrl(pathname: string): string {
|
|
48
|
+
function buildSiderApiUrl(pathname) {
|
|
84
49
|
const url = new URL(resolveSiderBaseUrl());
|
|
85
50
|
const basePath = url.pathname.replace(/\/+$/, "");
|
|
86
51
|
const suffix = pathname.startsWith("/") ? pathname : `/${pathname}`;
|
|
@@ -89,20 +54,17 @@ function buildSiderApiUrl(pathname: string): string {
|
|
|
89
54
|
url.hash = "";
|
|
90
55
|
return url.toString();
|
|
91
56
|
}
|
|
92
|
-
|
|
93
|
-
export function resolveSiderApiUrl(pathname: string): string {
|
|
57
|
+
function resolveSiderApiUrl(pathname) {
|
|
94
58
|
return buildSiderApiUrl(pathname);
|
|
95
59
|
}
|
|
96
|
-
|
|
97
|
-
export function formatAuthorizationHeader(token: string): string {
|
|
60
|
+
function formatAuthorizationHeader(token) {
|
|
98
61
|
const trimmed = token.trim();
|
|
99
62
|
if (!trimmed) {
|
|
100
63
|
return trimmed;
|
|
101
64
|
}
|
|
102
65
|
return /^Bearer\s+/i.test(trimmed) ? trimmed : `Bearer ${trimmed}`;
|
|
103
66
|
}
|
|
104
|
-
|
|
105
|
-
export function appendTokenQuery(url: string, token?: string): string {
|
|
67
|
+
function appendTokenQuery(url, token) {
|
|
106
68
|
const trimmed = token?.trim();
|
|
107
69
|
if (!trimmed) {
|
|
108
70
|
return url;
|
|
@@ -111,41 +73,32 @@ export function appendTokenQuery(url: string, token?: string): string {
|
|
|
111
73
|
next.searchParams.set("token", trimmed);
|
|
112
74
|
return next.toString();
|
|
113
75
|
}
|
|
114
|
-
|
|
115
|
-
function parseRegisterResponse(payload: unknown): SiderRegisterResponse {
|
|
76
|
+
function parseRegisterResponse(payload) {
|
|
116
77
|
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
117
78
|
throw new Error("selfclaw register response is not a JSON object");
|
|
118
79
|
}
|
|
119
80
|
const clawId = trimMaybe(
|
|
120
|
-
typeof
|
|
121
|
-
? ((payload as Record<string, unknown>).claw_id as string)
|
|
122
|
-
: undefined,
|
|
81
|
+
typeof payload.claw_id === "string" ? payload.claw_id : void 0
|
|
123
82
|
);
|
|
124
83
|
const token = trimMaybe(
|
|
125
|
-
typeof
|
|
126
|
-
? ((payload as Record<string, unknown>).token as string)
|
|
127
|
-
: undefined,
|
|
84
|
+
typeof payload.token === "string" ? payload.token : void 0
|
|
128
85
|
);
|
|
129
86
|
if (!clawId || !token) {
|
|
130
87
|
throw new Error("selfclaw register response missing claw_id/token");
|
|
131
88
|
}
|
|
132
89
|
return {
|
|
133
90
|
claw_id: clawId,
|
|
134
|
-
token
|
|
91
|
+
token
|
|
135
92
|
};
|
|
136
93
|
}
|
|
137
|
-
|
|
138
|
-
async function exchangeSetupToken(params: {
|
|
139
|
-
pathname: string;
|
|
140
|
-
authorization: string;
|
|
141
|
-
}): Promise<SiderResolvedCredentials> {
|
|
94
|
+
async function exchangeSetupToken(params) {
|
|
142
95
|
const url = buildSiderApiUrl(params.pathname);
|
|
143
96
|
const response = await fetch(url, {
|
|
144
97
|
method: "POST",
|
|
145
98
|
headers: {
|
|
146
99
|
Authorization: formatAuthorizationHeader(params.authorization),
|
|
147
|
-
"User-Agent": SIDER_USER_AGENT
|
|
148
|
-
}
|
|
100
|
+
"User-Agent": SIDER_USER_AGENT
|
|
101
|
+
}
|
|
149
102
|
});
|
|
150
103
|
if (!response.ok) {
|
|
151
104
|
let detail = "";
|
|
@@ -155,11 +108,10 @@ async function exchangeSetupToken(params: {
|
|
|
155
108
|
detail = `: ${text}`;
|
|
156
109
|
}
|
|
157
110
|
} catch {
|
|
158
|
-
// Ignore body read failures and keep the status-only error.
|
|
159
111
|
}
|
|
160
112
|
throw new Error(`selfclaw request failed (${response.status} ${response.statusText})${detail}`);
|
|
161
113
|
}
|
|
162
|
-
let payload
|
|
114
|
+
let payload = null;
|
|
163
115
|
try {
|
|
164
116
|
payload = await response.json();
|
|
165
117
|
} catch {
|
|
@@ -168,86 +120,56 @@ async function exchangeSetupToken(params: {
|
|
|
168
120
|
const parsed = parseRegisterResponse(payload);
|
|
169
121
|
return { token: parsed.token };
|
|
170
122
|
}
|
|
171
|
-
|
|
172
|
-
export function cloneOpenClawConfig(cfg: OpenClawConfig): OpenClawConfig {
|
|
123
|
+
function cloneOpenClawConfig(cfg) {
|
|
173
124
|
return structuredClone(cfg);
|
|
174
125
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
const next = cfg as OpenClawConfig & {
|
|
178
|
-
channels?: Record<string, Record<string, unknown>>;
|
|
179
|
-
};
|
|
126
|
+
function ensureChannelConfig(cfg) {
|
|
127
|
+
const next = cfg;
|
|
180
128
|
next.channels ??= {};
|
|
181
129
|
next.channels[SIDER_CHANNEL_ID] ??= {};
|
|
182
|
-
return next.channels[SIDER_CHANNEL_ID]
|
|
130
|
+
return next.channels[SIDER_CHANNEL_ID];
|
|
183
131
|
}
|
|
184
|
-
|
|
185
|
-
export function resolveWritableSiderAccountConfig(
|
|
186
|
-
cfg: OpenClawConfig,
|
|
187
|
-
accountId: string,
|
|
188
|
-
): Record<string, unknown> {
|
|
132
|
+
function resolveWritableSiderAccountConfig(cfg, accountId) {
|
|
189
133
|
const channelCfg = ensureChannelConfig(cfg);
|
|
190
134
|
if (accountId === DEFAULT_ACCOUNT_ID) {
|
|
191
135
|
return channelCfg;
|
|
192
136
|
}
|
|
193
|
-
const accounts =
|
|
194
|
-
typeof channelCfg.accounts === "object" && channelCfg.accounts && !Array.isArray(channelCfg.accounts)
|
|
195
|
-
? (channelCfg.accounts as Record<string, Record<string, unknown>>)
|
|
196
|
-
: ((channelCfg.accounts = {}) as Record<string, Record<string, unknown>>);
|
|
137
|
+
const accounts = typeof channelCfg.accounts === "object" && channelCfg.accounts && !Array.isArray(channelCfg.accounts) ? channelCfg.accounts : channelCfg.accounts = {};
|
|
197
138
|
accounts[accountId] ??= {};
|
|
198
|
-
return accounts[accountId]
|
|
139
|
+
return accounts[accountId];
|
|
199
140
|
}
|
|
200
|
-
|
|
201
|
-
async function persistSiderCredentials(params: {
|
|
202
|
-
accountId: string;
|
|
203
|
-
credentials: SiderResolvedCredentials;
|
|
204
|
-
}): Promise<OpenClawConfig> {
|
|
141
|
+
async function persistSiderCredentials(params) {
|
|
205
142
|
const runtime = getSiderAuthRuntime();
|
|
206
143
|
const latestCfg = cloneOpenClawConfig(runtime.config.loadConfig());
|
|
207
144
|
const accountCfg = resolveWritableSiderAccountConfig(latestCfg, params.accountId);
|
|
208
145
|
accountCfg.token = params.credentials.token;
|
|
209
146
|
delete accountCfg.setupToken;
|
|
210
|
-
if (accountCfg.enabled ===
|
|
147
|
+
if (accountCfg.enabled === void 0) {
|
|
211
148
|
accountCfg.enabled = true;
|
|
212
149
|
}
|
|
213
150
|
await runtime.config.writeConfigFile(latestCfg);
|
|
214
151
|
return latestCfg;
|
|
215
152
|
}
|
|
216
|
-
|
|
217
|
-
function resolveConfiguredSetupToken(snapshot: SiderSetupConfigSnapshot): string | undefined {
|
|
153
|
+
function resolveConfiguredSetupToken(snapshot) {
|
|
218
154
|
return trimMaybe(snapshot.setupToken);
|
|
219
155
|
}
|
|
220
|
-
|
|
221
|
-
export function setSiderAuthRuntime(runtime: PluginRuntime): void {
|
|
156
|
+
function setSiderAuthRuntime(runtime) {
|
|
222
157
|
runtimeRef = runtime;
|
|
223
158
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
accountId: string,
|
|
227
|
-
snapshot?: SiderSetupConfigSnapshot,
|
|
228
|
-
): string | undefined {
|
|
229
|
-
const configuredToken = snapshot ? resolveConfiguredSetupToken(snapshot) : undefined;
|
|
159
|
+
function resolveSiderSetupToken(accountId, snapshot) {
|
|
160
|
+
const configuredToken = snapshot ? resolveConfiguredSetupToken(snapshot) : void 0;
|
|
230
161
|
if (configuredToken) {
|
|
231
162
|
return configuredToken;
|
|
232
163
|
}
|
|
233
164
|
if (accountId === DEFAULT_ACCOUNT_ID) {
|
|
234
165
|
return trimMaybe(readDefaultSiderSetupTokenEnv());
|
|
235
166
|
}
|
|
236
|
-
return
|
|
167
|
+
return void 0;
|
|
237
168
|
}
|
|
238
|
-
|
|
239
|
-
export function isSiderAccountSetupPending(accountId: string): boolean {
|
|
169
|
+
function isSiderAccountSetupPending(accountId) {
|
|
240
170
|
return pendingAccountOperations.has(accountId);
|
|
241
171
|
}
|
|
242
|
-
|
|
243
|
-
export async function ensureSiderAccountSetup(params: {
|
|
244
|
-
cfg: OpenClawConfig;
|
|
245
|
-
accountId: string;
|
|
246
|
-
getAccountSetupConfig: (
|
|
247
|
-
cfg: OpenClawConfig,
|
|
248
|
-
accountId: string,
|
|
249
|
-
) => SiderSetupConfigSnapshot;
|
|
250
|
-
}): Promise<OpenClawConfig> {
|
|
172
|
+
async function ensureSiderAccountSetup(params) {
|
|
251
173
|
const snapshot = params.getAccountSetupConfig(params.cfg, params.accountId);
|
|
252
174
|
if (snapshot.enabled === false) {
|
|
253
175
|
return params.cfg;
|
|
@@ -259,20 +181,17 @@ export async function ensureSiderAccountSetup(params: {
|
|
|
259
181
|
return await withPendingOperation(params.accountId, async () => {
|
|
260
182
|
const credentials = await exchangeSetupToken({
|
|
261
183
|
pathname: SIDER_AUTH_EXCHANGE_API_PATH,
|
|
262
|
-
authorization: setupToken
|
|
184
|
+
authorization: setupToken
|
|
263
185
|
});
|
|
264
186
|
return await persistSiderCredentials({
|
|
265
187
|
accountId: params.accountId,
|
|
266
|
-
credentials
|
|
188
|
+
credentials
|
|
267
189
|
});
|
|
268
190
|
});
|
|
269
191
|
}
|
|
270
|
-
|
|
271
|
-
export function createSiderAuthSetupService(
|
|
272
|
-
params: SiderAuthSetupServiceParams,
|
|
273
|
-
): OpenClawPluginService {
|
|
192
|
+
function createSiderAuthSetupService(params) {
|
|
274
193
|
return {
|
|
275
|
-
id:
|
|
194
|
+
id: SIDER_SERVICE_ID,
|
|
276
195
|
start: async (ctx) => {
|
|
277
196
|
const accountIds = params.listAccountIds(ctx.config);
|
|
278
197
|
for (const accountId of accountIds) {
|
|
@@ -280,13 +199,27 @@ export function createSiderAuthSetupService(
|
|
|
280
199
|
await ensureSiderAccountSetup({
|
|
281
200
|
cfg: ctx.config,
|
|
282
201
|
accountId,
|
|
283
|
-
getAccountSetupConfig: params.getAccountSetupConfig
|
|
202
|
+
getAccountSetupConfig: params.getAccountSetupConfig
|
|
284
203
|
});
|
|
285
204
|
} catch (error) {
|
|
286
205
|
const message = error instanceof Error ? error.message : String(error);
|
|
287
206
|
ctx.logger.warn(`sider setup failed for "${accountId}": ${message}`);
|
|
288
207
|
}
|
|
289
208
|
}
|
|
290
|
-
}
|
|
209
|
+
}
|
|
291
210
|
};
|
|
292
211
|
}
|
|
212
|
+
export {
|
|
213
|
+
SIDER_AUTH_EXCHANGE_API_PATH,
|
|
214
|
+
appendTokenQuery,
|
|
215
|
+
cloneOpenClawConfig,
|
|
216
|
+
createSiderAuthSetupService,
|
|
217
|
+
ensureSiderAccountSetup,
|
|
218
|
+
formatAuthorizationHeader,
|
|
219
|
+
isSiderAccountSetupPending,
|
|
220
|
+
resolveSiderApiUrl,
|
|
221
|
+
resolveSiderBaseUrl,
|
|
222
|
+
resolveSiderSetupToken,
|
|
223
|
+
resolveWritableSiderAccountConfig,
|
|
224
|
+
setSiderAuthRuntime
|
|
225
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { OpenClawConfig } from 'openclaw/plugin-sdk';
|
|
2
|
+
|
|
3
|
+
type SiderAutoTitleConfig = boolean | {
|
|
4
|
+
enabled?: boolean;
|
|
5
|
+
prompt?: string;
|
|
6
|
+
};
|
|
7
|
+
declare const AUTO_SIDER_TITLE_DEFAULT_PROMPT = "Generate a very short chat title (2-4 words, max 25 chars) for a conversation based on the user's first message below. No emoji. Use the same language as the message. Be concise and descriptive. Return ONLY the title, nothing else.";
|
|
8
|
+
declare function resolveAutoTitleConfig(config?: SiderAutoTitleConfig): {
|
|
9
|
+
enabled: true;
|
|
10
|
+
prompt: string;
|
|
11
|
+
} | null;
|
|
12
|
+
declare function generateSiderSessionTitle(params: {
|
|
13
|
+
userMessage: string;
|
|
14
|
+
prompt: string;
|
|
15
|
+
cfg: OpenClawConfig;
|
|
16
|
+
agentId?: string;
|
|
17
|
+
agentDir?: string;
|
|
18
|
+
}): Promise<string | null>;
|
|
19
|
+
|
|
20
|
+
export { AUTO_SIDER_TITLE_DEFAULT_PROMPT, type SiderAutoTitleConfig, generateSiderSessionTitle, resolveAutoTitleConfig };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { generateTopicLabel } from "openclaw/plugin-sdk/reply-runtime";
|
|
2
|
+
const AUTO_SIDER_TITLE_DEFAULT_PROMPT = "Generate a very short chat title (2-4 words, max 25 chars) for a conversation based on the user's first message below. No emoji. Use the same language as the message. Be concise and descriptive. Return ONLY the title, nothing else.";
|
|
3
|
+
function resolveAutoTitleConfig(config) {
|
|
4
|
+
if (config === void 0 || config === true) {
|
|
5
|
+
return { enabled: true, prompt: AUTO_SIDER_TITLE_DEFAULT_PROMPT };
|
|
6
|
+
}
|
|
7
|
+
if (config === false || config.enabled === false) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
return {
|
|
11
|
+
enabled: true,
|
|
12
|
+
prompt: config.prompt?.trim() || AUTO_SIDER_TITLE_DEFAULT_PROMPT
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
async function generateSiderSessionTitle(params) {
|
|
16
|
+
return await generateTopicLabel(params);
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
AUTO_SIDER_TITLE_DEFAULT_PROMPT,
|
|
20
|
+
generateSiderSessionTitle,
|
|
21
|
+
resolveAutoTitleConfig
|
|
22
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { OpenClawConfig } from 'openclaw/plugin-sdk/config-runtime';
|
|
2
|
+
import { ResolvedSiderAccount } from './account.js';
|
|
3
|
+
import 'openclaw/plugin-sdk/setup';
|
|
4
|
+
import './auth.js';
|
|
5
|
+
import 'openclaw/plugin-sdk';
|
|
6
|
+
import 'openclaw/plugin-sdk/plugin-entry';
|
|
7
|
+
import './auto-title.js';
|
|
8
|
+
|
|
9
|
+
declare function isFirstTurnInSiderSession(params: {
|
|
10
|
+
cfg: OpenClawConfig;
|
|
11
|
+
agentId: string;
|
|
12
|
+
sessionKey?: string;
|
|
13
|
+
}): boolean;
|
|
14
|
+
declare function scheduleSiderAutoTitleUpdate(params: {
|
|
15
|
+
cfg: OpenClawConfig;
|
|
16
|
+
account: ResolvedSiderAccount;
|
|
17
|
+
sessionId: string;
|
|
18
|
+
userMessage: string;
|
|
19
|
+
prompt: string;
|
|
20
|
+
agentId: string;
|
|
21
|
+
}): void;
|
|
22
|
+
|
|
23
|
+
export { isFirstTurnInSiderSession, scheduleSiderAutoTitleUpdate };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import {
|
|
2
|
+
loadSessionStore,
|
|
3
|
+
resolveSessionStoreEntry
|
|
4
|
+
} from "openclaw/plugin-sdk/config-runtime";
|
|
5
|
+
import { resolveAgentDir } from "openclaw/plugin-sdk/agent-runtime";
|
|
6
|
+
import { generateSiderSessionTitle } from "./auto-title.js";
|
|
7
|
+
import { getSiderRuntime, logDebug, logWarn } from "./channel-runtime.js";
|
|
8
|
+
import { updateSiderSessionTitle } from "./channel-util.js";
|
|
9
|
+
function isFirstTurnInSiderSession(params) {
|
|
10
|
+
if (!params.sessionKey) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
const storePath = getSiderRuntime().channel.session.resolveStorePath(params.cfg.session?.store, {
|
|
14
|
+
agentId: params.agentId
|
|
15
|
+
});
|
|
16
|
+
const store = loadSessionStore(storePath, {
|
|
17
|
+
skipCache: true
|
|
18
|
+
});
|
|
19
|
+
const entry = resolveSessionStoreEntry({
|
|
20
|
+
store,
|
|
21
|
+
sessionKey: params.sessionKey
|
|
22
|
+
}).existing;
|
|
23
|
+
return !entry?.systemSent;
|
|
24
|
+
}
|
|
25
|
+
function scheduleSiderAutoTitleUpdate(params) {
|
|
26
|
+
const userMessage = params.userMessage.trim();
|
|
27
|
+
if (!userMessage) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const authorization = params.account.token?.trim();
|
|
31
|
+
if (!authorization) {
|
|
32
|
+
logWarn("sider auto-title skipped: missing auth token", {
|
|
33
|
+
accountId: params.account.accountId,
|
|
34
|
+
sessionId: params.sessionId
|
|
35
|
+
});
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const agentDir = resolveAgentDir(params.cfg, params.agentId);
|
|
39
|
+
void (async () => {
|
|
40
|
+
try {
|
|
41
|
+
const title = await generateSiderSessionTitle({
|
|
42
|
+
userMessage,
|
|
43
|
+
prompt: params.prompt,
|
|
44
|
+
cfg: params.cfg,
|
|
45
|
+
agentId: params.agentId,
|
|
46
|
+
agentDir
|
|
47
|
+
});
|
|
48
|
+
if (!title) {
|
|
49
|
+
logDebug("sider auto-title generator returned empty title", {
|
|
50
|
+
accountId: params.account.accountId,
|
|
51
|
+
sessionId: params.sessionId
|
|
52
|
+
});
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
await updateSiderSessionTitle({
|
|
56
|
+
sessionId: params.sessionId,
|
|
57
|
+
title,
|
|
58
|
+
authorization
|
|
59
|
+
});
|
|
60
|
+
logDebug("sider auto-title updated session title", {
|
|
61
|
+
accountId: params.account.accountId,
|
|
62
|
+
sessionId: params.sessionId,
|
|
63
|
+
titleLength: title.length
|
|
64
|
+
});
|
|
65
|
+
} catch (error) {
|
|
66
|
+
logWarn("sider auto-title update failed", {
|
|
67
|
+
accountId: params.account.accountId,
|
|
68
|
+
sessionId: params.sessionId,
|
|
69
|
+
error: String(error)
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
})();
|
|
73
|
+
}
|
|
74
|
+
export {
|
|
75
|
+
isFirstTurnInSiderSession,
|
|
76
|
+
scheduleSiderAutoTitleUpdate
|
|
77
|
+
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { SiderSampleEvent, SiderPart } from './channel-types.js';
|
|
2
|
+
import 'openclaw/plugin-sdk';
|
|
3
|
+
import './account.js';
|
|
4
|
+
import 'openclaw/plugin-sdk/setup';
|
|
5
|
+
import './auth.js';
|
|
6
|
+
import 'openclaw/plugin-sdk/plugin-entry';
|
|
7
|
+
import './auto-title.js';
|
|
8
|
+
import 'ws';
|
|
9
|
+
|
|
10
|
+
declare function isPathLikeSource(value: string): boolean;
|
|
11
|
+
declare function buildSourceFields(source?: string): Record<string, unknown>;
|
|
12
|
+
declare function buildThinkingPart(text: string): SiderPart;
|
|
13
|
+
declare function buildTextPart(text: string): SiderPart;
|
|
14
|
+
declare function buildToolCallPart(params: {
|
|
15
|
+
callId: string;
|
|
16
|
+
toolName?: string;
|
|
17
|
+
toolCallId?: string;
|
|
18
|
+
runId?: string;
|
|
19
|
+
toolArgs?: unknown;
|
|
20
|
+
}): SiderPart;
|
|
21
|
+
declare function buildToolResultPart(params: {
|
|
22
|
+
callId: string;
|
|
23
|
+
toolName?: string;
|
|
24
|
+
toolCallId?: string;
|
|
25
|
+
runId?: string;
|
|
26
|
+
toolArgs?: unknown;
|
|
27
|
+
result?: unknown;
|
|
28
|
+
error?: string;
|
|
29
|
+
durationMs?: number;
|
|
30
|
+
}): SiderPart;
|
|
31
|
+
declare function buildTypingEvent(params: {
|
|
32
|
+
state: "typing" | "idle";
|
|
33
|
+
sessionId: string;
|
|
34
|
+
accountId: string;
|
|
35
|
+
}): SiderSampleEvent;
|
|
36
|
+
declare function buildStreamingStartEvent(params: {
|
|
37
|
+
sessionId: string;
|
|
38
|
+
streamId: string;
|
|
39
|
+
accountId: string;
|
|
40
|
+
}): SiderSampleEvent;
|
|
41
|
+
declare function buildStreamingDeltaEvent(params: {
|
|
42
|
+
sessionId: string;
|
|
43
|
+
streamId: string;
|
|
44
|
+
seq: number;
|
|
45
|
+
delta: string;
|
|
46
|
+
text: string;
|
|
47
|
+
accountId: string;
|
|
48
|
+
}): SiderSampleEvent;
|
|
49
|
+
declare function buildStreamingDoneEvent(params: {
|
|
50
|
+
sessionId: string;
|
|
51
|
+
streamId: string;
|
|
52
|
+
seq: number;
|
|
53
|
+
accountId: string;
|
|
54
|
+
reason: "final" | "interrupted";
|
|
55
|
+
}): SiderSampleEvent;
|
|
56
|
+
declare function buildReasoningStartEvent(params: {
|
|
57
|
+
sessionId: string;
|
|
58
|
+
streamId: string;
|
|
59
|
+
accountId: string;
|
|
60
|
+
}): SiderSampleEvent;
|
|
61
|
+
declare function buildReasoningDeltaEvent(params: {
|
|
62
|
+
sessionId: string;
|
|
63
|
+
streamId: string;
|
|
64
|
+
seq: number;
|
|
65
|
+
delta: string;
|
|
66
|
+
text: string;
|
|
67
|
+
accountId: string;
|
|
68
|
+
}): SiderSampleEvent;
|
|
69
|
+
declare function buildReasoningDoneEvent(params: {
|
|
70
|
+
sessionId: string;
|
|
71
|
+
streamId: string;
|
|
72
|
+
seq: number;
|
|
73
|
+
accountId: string;
|
|
74
|
+
reason: "final" | "interrupted";
|
|
75
|
+
}): SiderSampleEvent;
|
|
76
|
+
declare function buildToolCallEvent(params: {
|
|
77
|
+
sessionId: string;
|
|
78
|
+
accountId: string;
|
|
79
|
+
seq: number;
|
|
80
|
+
callId: string;
|
|
81
|
+
phase: "start";
|
|
82
|
+
toolName?: string;
|
|
83
|
+
toolCallId?: string;
|
|
84
|
+
runId?: string;
|
|
85
|
+
sessionKey?: string;
|
|
86
|
+
toolArgs?: Record<string, unknown>;
|
|
87
|
+
error?: string;
|
|
88
|
+
durationMs?: number;
|
|
89
|
+
}): SiderSampleEvent;
|
|
90
|
+
declare function buildToolResultEvent(params: {
|
|
91
|
+
sessionId: string;
|
|
92
|
+
accountId: string;
|
|
93
|
+
seq: number;
|
|
94
|
+
callId: string;
|
|
95
|
+
toolName?: string;
|
|
96
|
+
toolCallId?: string;
|
|
97
|
+
runId?: string;
|
|
98
|
+
sessionKey?: string;
|
|
99
|
+
toolArgs?: Record<string, unknown>;
|
|
100
|
+
result?: unknown;
|
|
101
|
+
error?: string;
|
|
102
|
+
durationMs?: number;
|
|
103
|
+
}): SiderSampleEvent;
|
|
104
|
+
|
|
105
|
+
export { buildReasoningDeltaEvent, buildReasoningDoneEvent, buildReasoningStartEvent, buildSourceFields, buildStreamingDeltaEvent, buildStreamingDoneEvent, buildStreamingStartEvent, buildTextPart, buildThinkingPart, buildToolCallEvent, buildToolCallPart, buildToolResultEvent, buildToolResultPart, buildTypingEvent, isPathLikeSource };
|