@zhexin/pi-deepseek 0.0.1 → 0.0.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +27 -15
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zhexin/pi-deepseek",
3
3
  "description": "DeepSeek Enhancement for Pi",
4
- "version": "0.0.1",
4
+ "version": "0.0.2",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "keywords": [
package/src/index.ts CHANGED
@@ -1,10 +1,30 @@
1
- import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
1
+ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
2
2
  import type { Static } from "typebox";
3
3
 
4
4
  import { fetchInput, fetchOutput, searchInput, searchOutput } from "./schema.ts";
5
5
 
6
6
  const unauthorized = new Error("Unauthorized. Run `/login deepseek` to authenticate.");
7
7
 
8
+ async function resolveDeepSeekRequest(ctx: ExtensionContext, path: string) {
9
+ const authResult = await ctx.modelRegistry.getProviderAuth("deepseek");
10
+ const apiKey = authResult?.auth.apiKey;
11
+ if (apiKey === undefined) throw unauthorized;
12
+
13
+ const baseUrl =
14
+ authResult?.auth.baseUrl ??
15
+ ctx.modelRegistry.getProvider("deepseek")?.baseUrl ??
16
+ "https://api.deepseek.com";
17
+
18
+ return {
19
+ url: new URL(path, baseUrl),
20
+ headers: {
21
+ ...authResult?.auth.headers,
22
+ Authorization: `Bearer ${apiKey}`,
23
+ "Content-Type": "application/json",
24
+ },
25
+ };
26
+ }
27
+
8
28
  export default function (pi: ExtensionAPI): void {
9
29
  pi.registerTool({
10
30
  name: "web-search",
@@ -13,15 +33,11 @@ export default function (pi: ExtensionAPI): void {
13
33
  parameters: searchInput,
14
34
  outputSchema: searchOutput,
15
35
  async execute(_toolCallId, params, signal, _onUpdate, ctx) {
16
- const apiKey = await ctx.modelRegistry.getApiKeyForProvider("deepseek");
17
- if (apiKey === undefined) throw unauthorized;
36
+ const { url, headers } = await resolveDeepSeekRequest(ctx, "/v1/tools/search");
18
37
 
19
- const response = await fetch("https://api.deepseek.com/v1/tools/search", {
38
+ const response = await fetch(url, {
20
39
  method: "POST",
21
- headers: {
22
- Authorization: `Bearer ${apiKey}`,
23
- "Content-Type": "application/json",
24
- },
40
+ headers,
25
41
  body: JSON.stringify(params),
26
42
  signal: signal ?? null,
27
43
  });
@@ -63,15 +79,11 @@ export default function (pi: ExtensionAPI): void {
63
79
  parameters: fetchInput,
64
80
  outputSchema: fetchOutput,
65
81
  async execute(_toolCallId, params, signal, _onUpdate, ctx) {
66
- const apiKey = await ctx.modelRegistry.getApiKeyForProvider("deepseek");
67
- if (apiKey === undefined) throw unauthorized;
82
+ const { url, headers } = await resolveDeepSeekRequest(ctx, "/v1/tools/fetch");
68
83
 
69
- const response = await fetch("https://api.deepseek.com/v1/tools/fetch", {
84
+ const response = await fetch(url, {
70
85
  method: "POST",
71
- headers: {
72
- Authorization: `Bearer ${apiKey}`,
73
- "Content-Type": "application/json",
74
- },
86
+ headers,
75
87
  body: JSON.stringify(params),
76
88
  signal: signal ?? null,
77
89
  });