@friendlyrobot/discord-pi-agent 0.2.0 → 0.3.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.
@@ -1,4 +1,4 @@
1
- import type { AgentStatus, ResolvedDiscordPiBridgeConfig } from "./types";
1
+ import type { AgentStatus, ResolvedDiscordPiBridgeConfig, ThinkingLevel } from "./types";
2
2
  export declare class AgentService {
3
3
  private readonly config;
4
4
  private readonly authStorage;
@@ -16,5 +16,12 @@ export declare class AgentService {
16
16
  private createOrResumeSession;
17
17
  private ensureConfiguredModel;
18
18
  private requireSession;
19
+ private applyConfiguredThinkingLevel;
20
+ getThinkingLevel(): {
21
+ current: ThinkingLevel;
22
+ available: ThinkingLevel[];
23
+ supported: boolean;
24
+ };
25
+ setThinkingLevel(level: ThinkingLevel): string;
19
26
  private getSessionDir;
20
27
  }
package/dist/index.js CHANGED
@@ -127,7 +127,8 @@ class AgentService {
127
127
  agentDir: this.config.agentDir,
128
128
  sessionDir: this.getSessionDir(),
129
129
  modelProvider: this.config.modelProvider,
130
- modelId: this.config.modelId
130
+ modelId: this.config.modelId,
131
+ thinkingLevel: this.config.thinkingLevel
131
132
  });
132
133
  await this.resourceLoader.reload();
133
134
  console.log("[agent] resources loaded", {
@@ -159,7 +160,8 @@ class AgentService {
159
160
  modelRegistry: this.modelRegistry,
160
161
  resourceLoader: this.resourceLoader,
161
162
  settingsManager: this.settingsManager,
162
- sessionManager: SessionManager.create(this.config.cwd, this.getSessionDir())
163
+ sessionManager: SessionManager.create(this.config.cwd, this.getSessionDir()),
164
+ thinkingLevel: this.config.thinkingLevel
163
165
  });
164
166
  this.session = session;
165
167
  await this.ensureConfiguredModel();
@@ -169,12 +171,14 @@ class AgentService {
169
171
  const session = this.requireSession();
170
172
  const model = session.model ? `${session.model.provider}/${session.model.id}` : "(no model selected)";
171
173
  const contextUsage = session.getContextUsage();
174
+ const thinkingInfo = session.supportsThinking() ? `thinking: ${session.thinkingLevel} (available: ${session.getAvailableThinkingLevels().join(", ")})` : "thinking: not supported";
172
175
  return {
173
176
  sessionId: session.sessionId,
174
177
  sessionFile: session.sessionFile,
175
178
  model,
176
179
  streaming: session.isStreaming,
177
- contextUsage
180
+ contextUsage,
181
+ thinkingInfo
178
182
  };
179
183
  }
180
184
  async shutdown() {
@@ -193,7 +197,8 @@ class AgentService {
193
197
  modelRegistry: this.modelRegistry,
194
198
  resourceLoader: this.resourceLoader,
195
199
  settingsManager: this.settingsManager,
196
- sessionManager: SessionManager.continueRecent(this.config.cwd, this.getSessionDir())
200
+ sessionManager: SessionManager.continueRecent(this.config.cwd, this.getSessionDir()),
201
+ thinkingLevel: this.config.thinkingLevel
197
202
  });
198
203
  this.session = session;
199
204
  console.log("[agent] session ready", {
@@ -226,6 +231,7 @@ class AgentService {
226
231
  to: `${desiredModel.provider}/${desiredModel.id}`
227
232
  });
228
233
  await session.setModel(desiredModel);
234
+ await this.applyConfiguredThinkingLevel();
229
235
  }
230
236
  requireSession() {
231
237
  if (!this.session) {
@@ -233,6 +239,44 @@ class AgentService {
233
239
  }
234
240
  return this.session;
235
241
  }
242
+ async applyConfiguredThinkingLevel() {
243
+ const session = this.requireSession();
244
+ if (session.supportsThinking()) {
245
+ const available = session.getAvailableThinkingLevels();
246
+ if (available.includes(this.config.thinkingLevel)) {
247
+ session.setThinkingLevel(this.config.thinkingLevel);
248
+ console.log("[agent] thinking level applied", { level: this.config.thinkingLevel });
249
+ } else {
250
+ console.log("[agent] thinking level not available for model", {
251
+ requested: this.config.thinkingLevel,
252
+ available
253
+ });
254
+ }
255
+ }
256
+ }
257
+ getThinkingLevel() {
258
+ const session = this.requireSession();
259
+ if (!session.supportsThinking()) {
260
+ return { current: "off", available: [], supported: false };
261
+ }
262
+ return {
263
+ current: session.thinkingLevel,
264
+ available: session.getAvailableThinkingLevels(),
265
+ supported: true
266
+ };
267
+ }
268
+ setThinkingLevel(level) {
269
+ const session = this.requireSession();
270
+ if (!session.supportsThinking()) {
271
+ return "Current model does not support reasoning/thinking.";
272
+ }
273
+ const available = session.getAvailableThinkingLevels();
274
+ if (!available.includes(level)) {
275
+ return `Invalid thinking level "${level}" for current model. Available: ${available.join(", ")}`;
276
+ }
277
+ session.setThinkingLevel(level);
278
+ return `Thinking level set to "${level}".`;
279
+ }
236
280
  getSessionDir() {
237
281
  return path.join(this.config.agentDir, "sessions");
238
282
  }
@@ -255,6 +299,7 @@ function resolveConfig(config) {
255
299
  agentDir: config.agentDir?.trim() || path2.join(config.cwd, ".pi-agent"),
256
300
  modelProvider: config.modelProvider?.trim() || "moonshot-cn",
257
301
  modelId: config.modelId?.trim() || "kimi-k2.5",
302
+ thinkingLevel: parseThinkingLevel(config.thinkingLevel) || "medium",
258
303
  promptTransform: config.promptTransform || identityPromptTransform,
259
304
  startupMessage: config.startupMessage === undefined ? "Bot is online and ready." : config.startupMessage,
260
305
  shutdownOnSignals: config.shutdownOnSignals ?? true
@@ -269,6 +314,7 @@ function loadDiscordPiBridgeConfigFromEnv(overrides = {}) {
269
314
  agentDir: overrides.agentDir || process.env.PI_AGENT_DIR,
270
315
  modelProvider: overrides.modelProvider || process.env.PI_MODEL_PROVIDER,
271
316
  modelId: overrides.modelId || process.env.PI_MODEL_ID,
317
+ thinkingLevel: parseThinkingLevel(overrides.thinkingLevel || process.env.PI_THINKING_LEVEL),
272
318
  promptTransform: overrides.promptTransform,
273
319
  startupMessage: overrides.startupMessage ?? readStartupMessageFromEnv(),
274
320
  shutdownOnSignals: overrides.shutdownOnSignals
@@ -292,6 +338,17 @@ function readStartupMessageFromEnv() {
292
338
  }
293
339
  return trimmedValue;
294
340
  }
341
+ function parseThinkingLevel(value) {
342
+ if (!value) {
343
+ return;
344
+ }
345
+ const trimmed = value.trim().toLowerCase();
346
+ const validLevels = ["off", "minimal", "low", "medium", "high", "xhigh"];
347
+ if (validLevels.includes(trimmed)) {
348
+ return trimmed;
349
+ }
350
+ return;
351
+ }
295
352
  function identityPromptTransform(input) {
296
353
  return input;
297
354
  }
@@ -318,6 +375,7 @@ async function handleCommand(input, agentService, promptQueue) {
318
375
  "Commands:",
319
376
  "!help - show this message",
320
377
  "!status - show current session status",
378
+ "!thinking - show or set thinking/reasoning level",
321
379
  "!compact - compact the persistent session",
322
380
  "!reset-session - start a fresh persistent session",
323
381
  "Any other DM text goes to the persistent agent session."
@@ -337,6 +395,7 @@ async function handleCommand(input, agentService, promptQueue) {
337
395
  `session-id: ${agentStatus.sessionId}`,
338
396
  `session-file: ${agentStatus.sessionFile ?? "(none)"}`,
339
397
  `streaming: ${agentStatus.streaming}`,
398
+ agentStatus.thinkingInfo,
340
399
  contextLine,
341
400
  `queue-pending: ${queueStatus.pending}`,
342
401
  `queue-busy: ${queueStatus.busy}`
@@ -344,6 +403,33 @@ async function handleCommand(input, agentService, promptQueue) {
344
403
  `)
345
404
  };
346
405
  }
406
+ if (trimmed === "!thinking" || trimmed.startsWith("!thinking ")) {
407
+ const parts = trimmed.split(" ");
408
+ if (parts.length === 1) {
409
+ const info = agentService.getThinkingLevel();
410
+ if (!info.supported) {
411
+ return {
412
+ handled: true,
413
+ response: "Current model does not support reasoning/thinking."
414
+ };
415
+ }
416
+ return {
417
+ handled: true,
418
+ response: [
419
+ `Current: ${info.current}`,
420
+ `Available: ${info.available.join(", ")}`,
421
+ `Usage: !thinking <level>`
422
+ ].join(`
423
+ `)
424
+ };
425
+ }
426
+ const requestedLevel = parts[1];
427
+ const result = agentService.setThinkingLevel(requestedLevel);
428
+ return {
429
+ handled: true,
430
+ response: result
431
+ };
432
+ }
347
433
  if (trimmed === "!compact") {
348
434
  return {
349
435
  handled: true,
package/dist/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { Client } from "discord.js";
2
2
  export type PromptTransform = (input: string) => string | Promise<string>;
3
+ export type ThinkingLevel = "off" | "minimal" | "low" | "medium" | "high" | "xhigh";
3
4
  export type DiscordPiBridgeConfig = {
4
5
  discordBotToken: string;
5
6
  discordAllowedUserId: string;
@@ -7,6 +8,7 @@ export type DiscordPiBridgeConfig = {
7
8
  agentDir?: string;
8
9
  modelProvider?: string;
9
10
  modelId?: string;
11
+ thinkingLevel?: ThinkingLevel;
10
12
  promptTransform?: PromptTransform;
11
13
  startupMessage?: string | false;
12
14
  shutdownOnSignals?: boolean;
@@ -18,6 +20,7 @@ export type ResolvedDiscordPiBridgeConfig = {
18
20
  agentDir: string;
19
21
  modelProvider: string;
20
22
  modelId: string;
23
+ thinkingLevel: ThinkingLevel;
21
24
  promptTransform: PromptTransform;
22
25
  startupMessage: string | false;
23
26
  shutdownOnSignals: boolean;
@@ -33,6 +36,7 @@ export type AgentStatus = {
33
36
  model: string;
34
37
  streaming: boolean;
35
38
  contextUsage: ContextUsageStatus | undefined;
39
+ thinkingInfo: string;
36
40
  };
37
41
  export type DiscordPiBridge = {
38
42
  client: Client;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@friendlyrobot/discord-pi-agent",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Reusable Discord gateway bridge for persistent pi agent sessions",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -16,6 +16,10 @@
16
16
  "dist",
17
17
  "README.md"
18
18
  ],
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/friendlyrobot/discord-pi-agent.git"
22
+ },
19
23
  "publishConfig": {
20
24
  "access": "public"
21
25
  },
@@ -24,8 +28,8 @@
24
28
  "typecheck": "tsc --noEmit -p tsconfig.json"
25
29
  },
26
30
  "dependencies": {
27
- "@mariozechner/pi-ai": "latest",
28
- "@mariozechner/pi-coding-agent": "latest",
31
+ "@mariozechner/pi-ai": "^0.69.0",
32
+ "@mariozechner/pi-coding-agent": "^0.69.0",
29
33
  "discord.js": "^14.19.3",
30
34
  "dotenv": "^16.6.1"
31
35
  },