@awiki/dsh-plugin 0.2.5 → 0.3.0-rc.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 (124) hide show
  1. package/README.md +69 -28
  2. package/README.zh.md +60 -21
  3. package/THIRD_PARTY_NOTICES.md +1 -1
  4. package/cordis.patch.yml +0 -8
  5. package/lib/client.js +6755 -2022
  6. package/lib/client.js.map +1 -1
  7. package/lib/index.js +1321 -72
  8. package/lib/model-proxy-contract.js +8 -1
  9. package/lib/provider.js +3 -1
  10. package/lib/{sdk-adapter-DKgkyApB.mjs → sdk-adapter-BIbsJmRj.mjs} +245 -4
  11. package/lib/typert.host.js +944 -57
  12. package/lib/typert.remote-client.d.ts +37 -1
  13. package/lib/typert.remote-client.d.ts.map +1 -1
  14. package/lib/typert.remote-client.js +944 -57
  15. package/lib/types/client/AwikiGroupAccessNotice.d.ts +12 -0
  16. package/lib/types/client/AwikiGroupAccessNotice.d.ts.map +1 -0
  17. package/lib/types/client/AwikiGroupAccessNotice.js +31 -0
  18. package/lib/types/client/AwikiGroupAccessNotice.js.map +1 -0
  19. package/lib/types/client/AwikiGroupDetails.d.ts +23 -0
  20. package/lib/types/client/AwikiGroupDetails.d.ts.map +1 -0
  21. package/lib/types/client/AwikiGroupDetails.js +144 -0
  22. package/lib/types/client/AwikiGroupDetails.js.map +1 -0
  23. package/lib/types/client/AwikiIdentityAccess.d.ts +22 -0
  24. package/lib/types/client/AwikiIdentityAccess.d.ts.map +1 -0
  25. package/lib/types/client/AwikiIdentityAccess.js +156 -0
  26. package/lib/types/client/AwikiIdentityAccess.js.map +1 -0
  27. package/lib/types/client/AwikiIdentityPage.d.ts +11 -0
  28. package/lib/types/client/AwikiIdentityPage.d.ts.map +1 -0
  29. package/lib/types/client/AwikiIdentityPage.js +8 -0
  30. package/lib/types/client/AwikiIdentityPage.js.map +1 -0
  31. package/lib/types/client/AwikiMail.d.ts +2 -1
  32. package/lib/types/client/AwikiMail.d.ts.map +1 -1
  33. package/lib/types/client/AwikiMail.js +157 -33
  34. package/lib/types/client/AwikiMail.js.map +1 -1
  35. package/lib/types/client/AwikiOnboarding.d.ts.map +1 -1
  36. package/lib/types/client/AwikiOnboarding.js +29 -9
  37. package/lib/types/client/AwikiOnboarding.js.map +1 -1
  38. package/lib/types/client/AwikiOverlay.d.ts +0 -5
  39. package/lib/types/client/AwikiOverlay.d.ts.map +1 -1
  40. package/lib/types/client/AwikiOverlay.js +202 -129
  41. package/lib/types/client/AwikiOverlay.js.map +1 -1
  42. package/lib/types/client/AwikiProfileCard.d.ts +9 -0
  43. package/lib/types/client/AwikiProfileCard.d.ts.map +1 -0
  44. package/lib/types/client/AwikiProfileCard.js +90 -0
  45. package/lib/types/client/AwikiProfileCard.js.map +1 -0
  46. package/lib/types/client/AwikiRecoveryForm.d.ts +27 -0
  47. package/lib/types/client/AwikiRecoveryForm.d.ts.map +1 -0
  48. package/lib/types/client/AwikiRecoveryForm.js +152 -0
  49. package/lib/types/client/AwikiRecoveryForm.js.map +1 -0
  50. package/lib/types/client/AwikiSettingsSection.d.ts +0 -2
  51. package/lib/types/client/AwikiSettingsSection.d.ts.map +1 -1
  52. package/lib/types/client/AwikiSettingsSection.js +18 -16
  53. package/lib/types/client/AwikiSettingsSection.js.map +1 -1
  54. package/lib/types/client/MentionText.d.ts +7 -0
  55. package/lib/types/client/MentionText.d.ts.map +1 -0
  56. package/lib/types/client/MentionText.js +10 -0
  57. package/lib/types/client/MentionText.js.map +1 -0
  58. package/lib/types/client/controller.d.ts +131 -3
  59. package/lib/types/client/controller.d.ts.map +1 -1
  60. package/lib/types/client/controller.js +908 -29
  61. package/lib/types/client/controller.js.map +1 -1
  62. package/lib/types/client/index.d.ts.map +1 -1
  63. package/lib/types/client/index.js +24 -4
  64. package/lib/types/client/index.js.map +1 -1
  65. package/lib/types/client/mail-list-cache.d.ts +15 -0
  66. package/lib/types/client/mail-list-cache.d.ts.map +1 -0
  67. package/lib/types/client/mail-list-cache.js +212 -0
  68. package/lib/types/client/mail-list-cache.js.map +1 -0
  69. package/lib/types/client/mentions.d.ts +51 -0
  70. package/lib/types/client/mentions.d.ts.map +1 -0
  71. package/lib/types/client/mentions.js +165 -0
  72. package/lib/types/client/mentions.js.map +1 -0
  73. package/lib/types/client/model-proxy-controller.d.ts +4 -0
  74. package/lib/types/client/model-proxy-controller.d.ts.map +1 -1
  75. package/lib/types/client/model-proxy-controller.js +68 -3
  76. package/lib/types/client/model-proxy-controller.js.map +1 -1
  77. package/lib/types/client/recharge-availability.d.ts +1 -1
  78. package/lib/types/client/recharge-availability.d.ts.map +1 -1
  79. package/lib/types/client/recharge-availability.js +1 -1
  80. package/lib/types/client/recharge-availability.js.map +1 -1
  81. package/lib/types/client/settings-locales.d.ts +1 -1
  82. package/lib/types/client/settings-locales.d.ts.map +1 -1
  83. package/lib/types/client/settings-locales.js +14 -8
  84. package/lib/types/client/settings-locales.js.map +1 -1
  85. package/lib/types/client/slots.d.ts +27 -2
  86. package/lib/types/client/slots.d.ts.map +1 -1
  87. package/lib/types/conversation-preferences.d.ts +20 -0
  88. package/lib/types/conversation-preferences.d.ts.map +1 -0
  89. package/lib/types/conversation-preferences.js +294 -0
  90. package/lib/types/conversation-preferences.js.map +1 -0
  91. package/lib/types/index.d.ts +45 -6
  92. package/lib/types/index.d.ts.map +1 -1
  93. package/lib/types/index.js +562 -23
  94. package/lib/types/index.js.map +1 -1
  95. package/lib/types/model-proxy-contract.d.ts +6 -0
  96. package/lib/types/model-proxy-contract.d.ts.map +1 -1
  97. package/lib/types/model-proxy-contract.js +6 -0
  98. package/lib/types/model-proxy-contract.js.map +1 -1
  99. package/lib/types/provider-api.d.ts +29 -1
  100. package/lib/types/provider-api.d.ts.map +1 -1
  101. package/lib/types/provider.d.ts.map +1 -1
  102. package/lib/types/provider.js +2 -0
  103. package/lib/types/provider.js.map +1 -1
  104. package/lib/types/sdk-adapter.d.ts +18 -1
  105. package/lib/types/sdk-adapter.d.ts.map +1 -1
  106. package/lib/types/sdk-adapter.js +277 -4
  107. package/lib/types/sdk-adapter.js.map +1 -1
  108. package/lib/types/sent-mail-store.d.ts +22 -0
  109. package/lib/types/sent-mail-store.d.ts.map +1 -0
  110. package/lib/types/sent-mail-store.js +246 -0
  111. package/lib/types/sent-mail-store.js.map +1 -0
  112. package/lib/types/types.d.ts +183 -2
  113. package/lib/types/types.d.ts.map +1 -1
  114. package/lib/types/types.js.map +1 -1
  115. package/package.json +15 -26
  116. package/lib/model-proxy.js +0 -383
  117. package/lib/types/client/model-account-settings-availability.d.ts +0 -4
  118. package/lib/types/client/model-account-settings-availability.d.ts.map +0 -1
  119. package/lib/types/client/model-account-settings-availability.js +0 -4
  120. package/lib/types/client/model-account-settings-availability.js.map +0 -1
  121. package/lib/types/model-proxy.d.ts +0 -14
  122. package/lib/types/model-proxy.d.ts.map +0 -1
  123. package/lib/types/model-proxy.js +0 -371
  124. package/lib/types/model-proxy.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awiki/dsh-plugin",
3
- "version": "0.2.5",
3
+ "version": "0.3.0-rc.2",
4
4
  "description": "AWiki identity and messaging plugin for DeepSeek Harness",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -18,10 +18,6 @@
18
18
  "types": "./lib/types/provider-api.d.ts",
19
19
  "default": "./lib/types/provider-api.js"
20
20
  },
21
- "./model-proxy": {
22
- "types": "./lib/types/model-proxy.d.ts",
23
- "default": "./lib/model-proxy.js"
24
- },
25
21
  "./model-proxy-contract": {
26
22
  "types": "./lib/types/model-proxy-contract.d.ts",
27
23
  "default": "./lib/types/model-proxy-contract.js"
@@ -69,18 +65,6 @@
69
65
  "THIRD_PARTY_NOTICES.md",
70
66
  "LICENSE"
71
67
  ],
72
- "scripts": {
73
- "build:types": "tsc -p tsconfig.host.json && tsc -p tsconfig.client.json",
74
- "build:typert": "node scripts/generate-typert.mjs",
75
- "build:bundle": "pnpm run build:typert && tsdown && node scripts/normalize-built.mjs",
76
- "build": "pnpm run build:types && pnpm run build:bundle",
77
- "typecheck": "tsc -p tsconfig.host.json --noEmit && tsc -p tsconfig.client.json --noEmit",
78
- "test": "vitest run",
79
- "check:generated": "node scripts/check-generated.mjs",
80
- "check:public": "node scripts/check-public.mjs",
81
- "verify": "pnpm run check:public && pnpm run build && pnpm run typecheck && pnpm run check:generated && pnpm run test",
82
- "prepack": "pnpm run verify"
83
- },
84
68
  "keywords": [
85
69
  "awiki",
86
70
  "deepseek",
@@ -119,7 +103,7 @@
119
103
  }
120
104
  },
121
105
  "dependencies": {
122
- "@awiki/im-core-node": "0.1.5",
106
+ "@awiki/im-core-node": "0.1.6",
123
107
  "@deepseek-ai/schemastery": "^3.18.1",
124
108
  "zod": "^4.4.3"
125
109
  },
@@ -127,7 +111,6 @@
127
111
  "@deepseek-ai/cordis": "^4.0.1",
128
112
  "@deepseek-ai/dsh-agent": "0.1.0-rc.7",
129
113
  "@deepseek-ai/dsh-agent-default-model": "0.1.0-rc.7",
130
- "@deepseek-ai/dsh-anonymous-user-id": "0.1.0-rc.7",
131
114
  "@deepseek-ai/dsh-api-remotes": "0.1.0-rc.7",
132
115
  "@deepseek-ai/dsh-brand": "0.1.0-rc.7",
133
116
  "@deepseek-ai/dsh-client-connection": "0.1.0-rc.7",
@@ -137,10 +120,8 @@
137
120
  "@deepseek-ai/dsh-client-ui-primitives": "0.1.0-rc.7",
138
121
  "@deepseek-ai/dsh-client-ui-settings": "0.1.0-rc.7",
139
122
  "@deepseek-ai/dsh-client-ui-slots": "0.1.0-rc.7",
140
- "@deepseek-ai/dsh-credentials": "0.1.0-rc.7",
141
123
  "@deepseek-ai/dsh-invariants": "0.1.0-rc.7",
142
124
  "@deepseek-ai/dsh-llm": "0.1.0-rc.7",
143
- "@deepseek-ai/dsh-llm-deepseek": "0.1.0-rc.7",
144
125
  "@deepseek-ai/dsh-session": "0.1.0-rc.7",
145
126
  "@deepseek-ai/dsh-settings": "0.1.0-rc.7",
146
127
  "@deepseek-ai/dsh-tools": "0.1.0-rc.7",
@@ -160,7 +141,6 @@
160
141
  "@deepseek-ai/dsh": "0.1.0-rc.7",
161
142
  "@deepseek-ai/dsh-agent": "0.1.0-rc.7",
162
143
  "@deepseek-ai/dsh-agent-default-model": "0.1.0-rc.7",
163
- "@deepseek-ai/dsh-anonymous-user-id": "0.1.0-rc.7",
164
144
  "@deepseek-ai/dsh-api-remotes": "0.1.0-rc.7",
165
145
  "@deepseek-ai/dsh-brand": "0.1.0-rc.7",
166
146
  "@deepseek-ai/dsh-client-connection": "0.1.0-rc.7",
@@ -171,10 +151,8 @@
171
151
  "@deepseek-ai/dsh-client-ui-primitives": "0.1.0-rc.7",
172
152
  "@deepseek-ai/dsh-client-ui-settings": "0.1.0-rc.7",
173
153
  "@deepseek-ai/dsh-client-ui-slots": "0.1.0-rc.7",
174
- "@deepseek-ai/dsh-credentials": "0.1.0-rc.7",
175
154
  "@deepseek-ai/dsh-invariants": "0.1.0-rc.7",
176
155
  "@deepseek-ai/dsh-llm": "0.1.0-rc.7",
177
- "@deepseek-ai/dsh-llm-deepseek": "0.1.0-rc.7",
178
156
  "@deepseek-ai/dsh-session": "0.1.0-rc.7",
179
157
  "@deepseek-ai/dsh-settings": "0.1.0-rc.7",
180
158
  "@deepseek-ai/dsh-system-prompt": "0.1.0-rc.7",
@@ -200,5 +178,16 @@
200
178
  "engines": {
201
179
  "node": "^22.19.0 || >=24.0.0"
202
180
  },
203
- "packageManager": "pnpm@11.7.0"
204
- }
181
+ "scripts": {
182
+ "build:types": "tsc -p tsconfig.host.json && tsc -p tsconfig.client.json",
183
+ "build:typert": "node scripts/generate-typert.mjs",
184
+ "build:bundle": "pnpm run build:typert && tsdown && node scripts/normalize-built.mjs",
185
+ "build": "pnpm run build:types && pnpm run build:bundle",
186
+ "typecheck": "tsc -p tsconfig.host.json --noEmit && tsc -p tsconfig.client.json --noEmit",
187
+ "test": "vitest run",
188
+ "check:generated": "node scripts/check-generated.mjs",
189
+ "check:public": "node scripts/check-public.mjs",
190
+ "verify": "pnpm run check:public && pnpm run build && pnpm run typecheck && pnpm run check:generated && pnpm run test",
191
+ "verify:workspace": "pnpm run verify && pnpm --filter @awiki/dsh-model-proxy run verify"
192
+ }
193
+ }
@@ -1,383 +0,0 @@
1
- import { AWIKI_MODEL_PROXY_RPC_CHANNEL, AWIKI_MODEL_PROXY_RPC_ENDPOINTS, decodeModelProxyStatus, decodeModelProxyUsage, decodeRechargeOrder } from "./model-proxy-contract.js";
2
- import z from "@deepseek-ai/schemastery";
3
- import { settingsNamespace } from "@deepseek-ai/dsh-settings";
4
- import { LlmError, resolveRetryPolicy } from "@deepseek-ai/dsh-llm";
5
- import { getOrCreateAnonymousUserId } from "@deepseek-ai/dsh-anonymous-user-id";
6
- import { credentialRef } from "@deepseek-ai/dsh-credentials";
7
- import { DeepSeekAdapter } from "@deepseek-ai/dsh-llm-deepseek";
8
- //#region lib/types/model-proxy.js
9
- /** Host-only AWiki-authenticated model-proxy provider and loopback account API. */
10
- const name = "awiki-model-proxy";
11
- const inject = [
12
- "awiki",
13
- "llm",
14
- "settings",
15
- "agentDefaultModel",
16
- "connection"
17
- ];
18
- const SETTINGS = settingsNamespace("awiki-model-proxy");
19
- const PROVIDER = "awiki-deepseek";
20
- const FLASH = "deepseek-v4-flash";
21
- const PRO = "deepseek-v4-pro";
22
- const MODELS = [FLASH, PRO];
23
- const PROVIDER_NAME = "AWiki-hosted DeepSeek";
24
- const SettingsSchema = z.object({
25
- enabled: z.boolean().default(false),
26
- previousProvider: z.string(),
27
- previousModel: z.string(),
28
- previousReasoningEffort: z.string()
29
- });
30
- const Config = z.object({
31
- baseURL: z.string().default("https://model.awiki.info"),
32
- contextWindow: z.number().step(1).min(1).default(1e6),
33
- maxTokens: z.number().step(1).min(1).default(8192),
34
- tokenRefreshSkewSeconds: z.number().step(1).min(0).default(60)
35
- });
36
- function apply(ctx, input = {}) {
37
- const config = resolveConfig(input);
38
- const settings = ctx.settings.register(SETTINGS, SettingsSchema, {
39
- base: { enabled: false },
40
- applies: "live"
41
- });
42
- const token = new ModelProxyToken(ctx, config);
43
- const adapter = new AwikiHostedDeepSeekAdapter({
44
- options: () => ({
45
- baseURL: new URL("/v1", config.baseURL).toString().replace(/\/$/, ""),
46
- apiKeyEnv: credentialRef("AWIKI_MODEL_PROXY_TOKEN"),
47
- defaults: {},
48
- maxTokens: config.maxTokens,
49
- defaultContextWindow: config.contextWindow,
50
- models: [{
51
- id: FLASH,
52
- name: "DeepSeek V4 Flash",
53
- contextWindow: config.contextWindow,
54
- maxTokens: config.maxTokens
55
- }, {
56
- id: PRO,
57
- name: "DeepSeek V4 Pro",
58
- contextWindow: config.contextWindow,
59
- maxTokens: config.maxTokens
60
- }],
61
- streamIdleTimeoutMs: 3e5,
62
- retryPolicy: resolveRetryPolicy(void 0, "awiki-model-proxy: retryPolicy")
63
- }),
64
- resolveApiKey: () => token.get(),
65
- resolveUserId: () => getOrCreateAnonymousUserId()
66
- });
67
- let route;
68
- let directory;
69
- let sessionStatus;
70
- let sessionRefresh;
71
- const sync = () => {
72
- const enabled = settings.get().enabled;
73
- if (enabled && sessionStatus === "active" && route === void 0) {
74
- directory = ctx.llm.registerConfigurableProviders([{
75
- provider: PROVIDER,
76
- displayName: PROVIDER_NAME,
77
- settingsNs: SETTINGS,
78
- settingsPath: []
79
- }]);
80
- route = ctx.llm.registerAdapter([PROVIDER], adapter);
81
- } else if ((!enabled || sessionStatus !== "active") && route !== void 0) {
82
- route();
83
- directory?.();
84
- route = void 0;
85
- directory = void 0;
86
- token.clear();
87
- }
88
- };
89
- const publishSession = (session) => {
90
- sessionStatus = session.status;
91
- token.clear();
92
- sync();
93
- };
94
- const refreshSession = () => {
95
- if (sessionStatus !== void 0) return Promise.resolve(sessionStatus);
96
- return sessionRefresh ??= ctx.awiki.getSession().then((result) => {
97
- if (!result.ok) return void 0;
98
- publishSession(result.value);
99
- return result.value.status;
100
- }).finally(() => {
101
- sessionRefresh = void 0;
102
- });
103
- };
104
- sync();
105
- refreshSession();
106
- ctx.on("awiki/session", (session) => {
107
- publishSession(session);
108
- });
109
- ctx.on("settings/updated", (namespace) => {
110
- if (namespace === SETTINGS) sync();
111
- });
112
- ctx.effect(() => () => {
113
- route?.();
114
- directory?.();
115
- token.clear();
116
- }, "awiki-model-proxy: release adapter and token");
117
- const handler = createRpcHandler(ctx, config, token, () => settings.get(), sync, async () => await refreshSession() === "active");
118
- ctx.connection.rpc.handle(AWIKI_MODEL_PROXY_RPC_CHANNEL, handler, { authority: "loopback" });
119
- }
120
- var ModelProxyToken = class {
121
- ctx;
122
- config;
123
- value;
124
- expiresAt = 0;
125
- pending;
126
- generation = 0;
127
- constructor(ctx, config) {
128
- this.ctx = ctx;
129
- this.config = config;
130
- }
131
- get() {
132
- if (this.value !== void 0 && Date.now() < this.expiresAt - this.config.tokenRefreshSkewMs) return Promise.resolve(this.value);
133
- if (this.pending !== void 0) return this.pending;
134
- const generation = this.generation;
135
- const pending = this.refresh(generation).finally(() => {
136
- if (this.pending === pending) this.pending = void 0;
137
- });
138
- this.pending = pending;
139
- return pending;
140
- }
141
- clear() {
142
- this.generation += 1;
143
- this.value = void 0;
144
- this.expiresAt = 0;
145
- this.pending = void 0;
146
- }
147
- invalidate(value) {
148
- if (this.value === value) this.clear();
149
- }
150
- async refresh(generation) {
151
- const response = await this.ctx.awiki.externalHttpAuth.dispatch(new Request(new URL("/api/token", this.config.baseURL), { method: "POST" }), (request) => fetch(request));
152
- if (!response.ok) throw await modelProxyError(response, "AWiki-hosted DeepSeek authentication failed");
153
- const value = await response.json();
154
- if (!isRecord(value) || typeof value.access_token !== "string" || value.access_token.length === 0 || !Number.isSafeInteger(value.expires_in) || value.expires_in <= 0) throw new LlmError("AWiki-hosted DeepSeek authentication returned an invalid response", "AUTH");
155
- const token = value;
156
- if (generation !== this.generation) throw new LlmError("AWiki-hosted DeepSeek authentication state changed", "AUTH");
157
- this.value = token.access_token;
158
- this.expiresAt = Date.now() + token.expires_in * 1e3;
159
- return token.access_token;
160
- }
161
- };
162
- var AwikiHostedDeepSeekAdapter = class extends DeepSeekAdapter {
163
- providerInfo(provider) {
164
- return {
165
- id: provider,
166
- name: PROVIDER_NAME
167
- };
168
- }
169
- };
170
- function createRpcHandler(ctx, config, token, currentSettings, sync, sessionActive) {
171
- return async (endpoint, payload, signal) => {
172
- try {
173
- if (signal.aborted) throw new Error("request cancelled");
174
- if (!await sessionActive()) throw new LlmError("Sign in to AWiki before using AWiki-hosted DeepSeek.", "AUTH");
175
- if (endpoint === AWIKI_MODEL_PROXY_RPC_ENDPOINTS.status) return {
176
- ok: true,
177
- value: await status(config, token, currentSettings().enabled, signal)
178
- };
179
- if (endpoint === AWIKI_MODEL_PROXY_RPC_ENDPOINTS.usage) {
180
- const value = await authenticatedJson(config, token, "/api/usage", { signal });
181
- const usage = decodeModelProxyUsage(value);
182
- if (usage === void 0) throw new Error("invalid usage response");
183
- return {
184
- ok: true,
185
- value: usage
186
- };
187
- }
188
- if (endpoint === AWIKI_MODEL_PROXY_RPC_ENDPOINTS.createRecharge) {
189
- if (!isRecord(payload) || !Number.isSafeInteger(payload.amount_cents)) return badRequest();
190
- const value = await authenticatedJson(config, token, "/api/recharge/orders", {
191
- method: "POST",
192
- headers: {
193
- "content-type": "application/json",
194
- "idempotency-key": globalThis.crypto.randomUUID()
195
- },
196
- body: JSON.stringify({ amount_cents: payload.amount_cents }),
197
- signal
198
- });
199
- const order = decodeRechargeOrder(value);
200
- if (order === void 0 || order.payment_action === void 0) throw new Error("invalid recharge response");
201
- return {
202
- ok: true,
203
- value: order
204
- };
205
- }
206
- if (endpoint === AWIKI_MODEL_PROXY_RPC_ENDPOINTS.rechargeStatus) {
207
- if (!isRecord(payload) || typeof payload.out_trade_no !== "string") return badRequest();
208
- const value = await authenticatedJson(config, token, `/api/recharge/orders/${encodeURIComponent(payload.out_trade_no)}`, { signal });
209
- const order = decodeRechargeOrder(value);
210
- if (order === void 0) throw new Error("invalid recharge status response");
211
- return {
212
- ok: true,
213
- value: order
214
- };
215
- }
216
- if (endpoint === AWIKI_MODEL_PROXY_RPC_ENDPOINTS.closeRecharge) {
217
- if (!isRecord(payload) || typeof payload.out_trade_no !== "string") return badRequest();
218
- if ((await authenticatedResponse(config, token, `/api/recharge/orders/${encodeURIComponent(payload.out_trade_no)}/close`, {
219
- method: "POST",
220
- signal
221
- })).status !== 204) throw new Error("invalid recharge close response");
222
- return {
223
- ok: true,
224
- value: { closed: true }
225
- };
226
- }
227
- if (endpoint === AWIKI_MODEL_PROXY_RPC_ENDPOINTS.setEnabled) {
228
- if (!isRecord(payload) || typeof payload.enabled !== "boolean") return badRequest();
229
- if (payload.enabled) {
230
- if (!(await status(config, token, false, signal)).account.model_access_available) return modelUnavailable("Account balance is required before enabling AWiki-hosted DeepSeek.");
231
- const previous = ctx.agentDefaultModel.currentSelection();
232
- await ctx.settings.update(SETTINGS, {
233
- enabled: true,
234
- previousProvider: previous.provider,
235
- previousModel: previous.model,
236
- ...previous.reasoningEffort === void 0 ? {} : { previousReasoningEffort: String(previous.reasoningEffort) }
237
- });
238
- sync();
239
- await ctx.agentDefaultModel.saveSelection({
240
- provider: PROVIDER,
241
- model: FLASH
242
- });
243
- } else {
244
- const stored = currentSettings();
245
- await ctx.settings.update(SETTINGS, { enabled: false });
246
- sync();
247
- if (ctx.agentDefaultModel.currentSelection().provider === PROVIDER) await ctx.agentDefaultModel.saveSelection({
248
- provider: stored.previousProvider ?? "deepseek-official",
249
- model: stored.previousModel ?? FLASH,
250
- ...stored.previousReasoningEffort === void 0 ? {} : { reasoningEffort: stored.previousReasoningEffort }
251
- });
252
- }
253
- return {
254
- ok: true,
255
- value: await status(config, token, payload.enabled, signal)
256
- };
257
- }
258
- return badRequest();
259
- } catch (error) {
260
- ctx.logger.warn("awiki-model-proxy: loopback request failed");
261
- ctx.logger.warn(error);
262
- return internal(displayMessage(error));
263
- }
264
- };
265
- }
266
- async function status(config, token, enabled, signal) {
267
- const [account, pendingRechargeOrder] = await Promise.all([authenticatedJson(config, token, "/api/account", { signal }), authenticatedJson(config, token, "/api/recharge/orders/pending", { signal })]);
268
- const decoded = decodeModelProxyStatus({
269
- enabled,
270
- account,
271
- pending_recharge_order: pendingRechargeOrder,
272
- recommended_model: FLASH,
273
- models: MODELS
274
- });
275
- if (decoded === void 0) throw new Error("invalid account response");
276
- return decoded;
277
- }
278
- async function authenticatedJson(config, token, path, init) {
279
- return (await authenticatedResponse(config, token, path, init)).json();
280
- }
281
- async function authenticatedResponse(config, token, path, init) {
282
- const send = async () => {
283
- const accessToken = await token.get();
284
- return {
285
- response: await fetch(new URL(path, config.baseURL), {
286
- ...init,
287
- headers: {
288
- ...headersRecord(init.headers),
289
- authorization: `Bearer ${accessToken}`
290
- }
291
- }),
292
- accessToken
293
- };
294
- };
295
- let result = await send();
296
- if (result.response.status === 401) {
297
- token.invalidate(result.accessToken);
298
- result = await send();
299
- }
300
- const { response } = result;
301
- if (!response.ok) throw await modelProxyError(response, `AWiki-hosted DeepSeek service returned HTTP ${response.status}`);
302
- return response;
303
- }
304
- async function modelProxyError(response, fallback) {
305
- let message = fallback;
306
- try {
307
- const body = await response.text();
308
- if (body !== "") try {
309
- const value = JSON.parse(body);
310
- if (isRecord(value) && isRecord(value.error) && typeof value.error.message === "string") message = value.error.message;
311
- } catch {
312
- message = body;
313
- }
314
- } catch {}
315
- return new LlmError(message, response.status === 401 || response.status === 403 ? "AUTH" : `HTTP_${response.status}`, { status: response.status });
316
- }
317
- function resolveConfig(input) {
318
- const baseURL = new URL(input.baseURL ?? "https://model.awiki.info");
319
- if (baseURL.username !== "" || baseURL.password !== "" || baseURL.search !== "" || baseURL.hash !== "") throw new Error("awiki-model-proxy: baseURL must not contain credentials, query, or fragment");
320
- if (baseURL.protocol !== "https:" && !(baseURL.protocol === "http:" && [
321
- "127.0.0.1",
322
- "localhost",
323
- "::1"
324
- ].includes(baseURL.hostname))) throw new Error("awiki-model-proxy: baseURL must use HTTPS or loopback HTTP");
325
- const contextWindow = positiveInteger(input.contextWindow ?? 1e6, "contextWindow");
326
- const maxTokens = positiveInteger(input.maxTokens ?? 8192, "maxTokens");
327
- const skew = input.tokenRefreshSkewSeconds ?? 60;
328
- if (!Number.isSafeInteger(skew) || skew < 0) throw new Error("awiki-model-proxy: tokenRefreshSkewSeconds must be a non-negative integer");
329
- return {
330
- baseURL,
331
- contextWindow,
332
- maxTokens,
333
- tokenRefreshSkewMs: skew * 1e3
334
- };
335
- }
336
- function positiveInteger(value, name) {
337
- if (!Number.isSafeInteger(value) || value <= 0) throw new Error(`awiki-model-proxy: ${name} must be a positive integer`);
338
- return value;
339
- }
340
- function headersRecord(headers) {
341
- return Object.fromEntries(new Headers(headers));
342
- }
343
- function isRecord(value) {
344
- return typeof value === "object" && value !== null && !Array.isArray(value);
345
- }
346
- function displayMessage(error) {
347
- return error instanceof Error && error.message !== "" ? error.message : "AWiki-hosted DeepSeek service is unavailable.";
348
- }
349
- function badRequest() {
350
- return {
351
- ok: false,
352
- error: {
353
- code: "bad-request",
354
- message: "The AWiki-hosted DeepSeek request is invalid.",
355
- details: { issues: [] }
356
- }
357
- };
358
- }
359
- function modelUnavailable(message) {
360
- return {
361
- ok: false,
362
- error: {
363
- code: "model-unavailable",
364
- message,
365
- details: {
366
- provider: PROVIDER,
367
- model: FLASH
368
- }
369
- }
370
- };
371
- }
372
- function internal(message) {
373
- return {
374
- ok: false,
375
- error: {
376
- code: "internal",
377
- message,
378
- details: {}
379
- }
380
- };
381
- }
382
- //#endregion
383
- export { Config, apply, inject, name };
@@ -1,4 +0,0 @@
1
- /** Client release gate for unfinished AWiki model account settings. */
2
- /** Enable only after account, recharge, and usage settings are ready to ship. */
3
- export declare const AWIKI_MODEL_ACCOUNT_SETTINGS_ENABLED = false;
4
- //# sourceMappingURL=model-account-settings-availability.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"model-account-settings-availability.d.ts","sourceRoot":"","sources":["../../../src/client/model-account-settings-availability.ts"],"names":[],"mappings":"AAAA,uEAAuE;AAEvE,iFAAiF;AACjF,eAAO,MAAM,oCAAoC,QAAQ,CAAA"}
@@ -1,4 +0,0 @@
1
- /** Client release gate for unfinished AWiki model account settings. */
2
- /** Enable only after account, recharge, and usage settings are ready to ship. */
3
- export const AWIKI_MODEL_ACCOUNT_SETTINGS_ENABLED = false;
4
- //# sourceMappingURL=model-account-settings-availability.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"model-account-settings-availability.js","sourceRoot":"","sources":["../../../src/client/model-account-settings-availability.ts"],"names":[],"mappings":"AAAA,uEAAuE;AAEvE,iFAAiF;AACjF,MAAM,CAAC,MAAM,oCAAoC,GAAG,KAAK,CAAA"}
@@ -1,14 +0,0 @@
1
- /** Host-only AWiki-authenticated model-proxy provider and loopback account API. */
2
- import type { Context } from '@deepseek-ai/cordis';
3
- import z from '@deepseek-ai/schemastery';
4
- export declare const name = "awiki-model-proxy";
5
- export declare const inject: string[];
6
- export interface Config {
7
- readonly baseURL?: string;
8
- readonly contextWindow?: number;
9
- readonly maxTokens?: number;
10
- readonly tokenRefreshSkewSeconds?: number;
11
- }
12
- export declare const Config: z<Config>;
13
- export declare function apply(ctx: Context, input?: Config): void;
14
- //# sourceMappingURL=model-proxy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"model-proxy.d.ts","sourceRoot":"","sources":["../../src/model-proxy.ts"],"names":[],"mappings":"AAAA,mFAAmF;AAEnF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,CAAC,MAAM,0BAA0B,CAAA;AAoBxC,eAAO,MAAM,IAAI,sBAAsB,CAAA;AACvC,eAAO,MAAM,MAAM,UAAkE,CAAA;AAuBrF,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAA;IAC/B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,uBAAuB,CAAC,EAAE,MAAM,CAAA;CAC1C;AAED,eAAO,MAAM,MAAM,EAAE,CAAC,CAAC,MAAM,CAK3B,CAAA;AAcF,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,GAAE,MAAW,GAAG,IAAI,CAiF5D"}