@mariozechner/pi-web-ui 0.23.4 → 0.23.5

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.
@@ -5,7 +5,7 @@ import type { AgentRunConfig, AgentTransport } from "./types.js";
5
5
  * Uses CORS proxy only for providers that require it (Anthropic OAuth, Z-AI).
6
6
  */
7
7
  export declare class ProviderTransport implements AgentTransport {
8
- private getModelAndKey;
8
+ private getModel;
9
9
  private buildContext;
10
10
  private buildLoopConfig;
11
11
  run(messages: Message[], userMessage: Message, cfg: AgentRunConfig, signal?: AbortSignal): AsyncGenerator<import("@mariozechner/pi-ai").AgentEvent, void, unknown>;
@@ -1 +1 @@
1
- {"version":3,"file":"ProviderTransport.d.ts","sourceRoot":"","sources":["../../../src/agent/transports/ProviderTransport.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,KAAK,OAAO,EAEZ,MAAM,qBAAqB,CAAC;AAG7B,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjE;;;GAGG;AACH,qBAAa,iBAAkB,YAAW,cAAc;YACzC,cAAc;IAa5B,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,eAAe;IAShB,GAAG,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,EAAE,cAAc,EAAE,MAAM,CAAC,EAAE,WAAW;IAUxF,QAAQ,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,cAAc,EAAE,MAAM,CAAC,EAAE,WAAW;CAS9E"}
1
+ {"version":3,"file":"ProviderTransport.d.ts","sourceRoot":"","sources":["../../../src/agent/transports/ProviderTransport.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,KAAK,OAAO,EAEZ,MAAM,qBAAqB,CAAC;AAG7B,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjE;;;GAGG;AACH,qBAAa,iBAAkB,YAAW,cAAc;YACzC,QAAQ;IAatB,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,eAAe;IAahB,GAAG,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,EAAE,cAAc,EAAE,MAAM,CAAC,EAAE,WAAW;IAUxF,QAAQ,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,cAAc,EAAE,MAAM,CAAC,EAAE,WAAW;CAS9E"}
@@ -6,7 +6,7 @@ import { applyProxyIfNeeded } from "../../utils/proxy-utils.js";
6
6
  * Uses CORS proxy only for providers that require it (Anthropic OAuth, Z-AI).
7
7
  */
8
8
  export class ProviderTransport {
9
- async getModelAndKey(cfg) {
9
+ async getModel(cfg) {
10
10
  const apiKey = await getAppStorage().providerKeys.get(cfg.model.provider);
11
11
  if (!apiKey) {
12
12
  throw new Error("no-api-key");
@@ -14,7 +14,7 @@ export class ProviderTransport {
14
14
  const proxyEnabled = await getAppStorage().settings.get("proxy.enabled");
15
15
  const proxyUrl = await getAppStorage().settings.get("proxy.url");
16
16
  const model = applyProxyIfNeeded(cfg.model, apiKey, proxyEnabled ? proxyUrl || undefined : undefined);
17
- return { model, apiKey };
17
+ return model;
18
18
  }
19
19
  buildContext(messages, cfg) {
20
20
  return {
@@ -23,26 +23,30 @@ export class ProviderTransport {
23
23
  tools: cfg.tools,
24
24
  };
25
25
  }
26
- buildLoopConfig(model, apiKey, cfg) {
26
+ buildLoopConfig(model, cfg) {
27
27
  return {
28
28
  model,
29
29
  reasoning: cfg.reasoning,
30
- apiKey,
30
+ // Resolve API key per assistant response (important for expiring OAuth tokens)
31
+ getApiKey: async (provider) => {
32
+ const key = await getAppStorage().providerKeys.get(provider);
33
+ return key ?? undefined; // Convert null to undefined for type compatibility
34
+ },
31
35
  getQueuedMessages: cfg.getQueuedMessages,
32
36
  };
33
37
  }
34
38
  async *run(messages, userMessage, cfg, signal) {
35
- const { model, apiKey } = await this.getModelAndKey(cfg);
39
+ const model = await this.getModel(cfg);
36
40
  const context = this.buildContext(messages, cfg);
37
- const pc = this.buildLoopConfig(model, apiKey, cfg);
41
+ const pc = this.buildLoopConfig(model, cfg);
38
42
  for await (const ev of agentLoop(userMessage, context, pc, signal)) {
39
43
  yield ev;
40
44
  }
41
45
  }
42
46
  async *continue(messages, cfg, signal) {
43
- const { model, apiKey } = await this.getModelAndKey(cfg);
47
+ const model = await this.getModel(cfg);
44
48
  const context = this.buildContext(messages, cfg);
45
- const pc = this.buildLoopConfig(model, apiKey, cfg);
49
+ const pc = this.buildLoopConfig(model, cfg);
46
50
  for await (const ev of agentLoopContinue(context, pc, signal)) {
47
51
  yield ev;
48
52
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ProviderTransport.js","sourceRoot":"","sources":["../../../src/agent/transports/ProviderTransport.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,SAAS,EACT,iBAAiB,GAGjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAGhE;;;GAGG;AACH,MAAM,OAAO,iBAAiB;IACrB,KAAK,CAAC,cAAc,CAAC,GAAmB;QAC/C,MAAM,MAAM,GAAG,MAAM,aAAa,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC1E,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;QAC/B,CAAC;QAED,MAAM,YAAY,GAAG,MAAM,aAAa,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAU,eAAe,CAAC,CAAC;QAClF,MAAM,QAAQ,GAAG,MAAM,aAAa,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAS,WAAW,CAAC,CAAC;QACzE,MAAM,KAAK,GAAG,kBAAkB,CAAC,GAAG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MAAM,EAAE,GAAG,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAE5C,IAAI,KAAK,EAAE,MAAM,EAAE,IAAI,iBAAiB,CAAC,OAAO,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,CAAC;YAC/D,MAAM,EAAE,CAAC;QACV,CAAC;IACF,CAAC;CACD"}
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-web-ui-example",
3
- "version": "1.11.4",
3
+ "version": "1.11.5",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "scripts": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mariozechner/pi-web-ui",
3
- "version": "0.23.4",
3
+ "version": "0.23.5",
4
4
  "description": "Reusable web UI components for AI chat interfaces powered by @mariozechner/pi-ai",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -18,8 +18,8 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@lmstudio/sdk": "^1.5.0",
21
- "@mariozechner/pi-ai": "^0.23.4",
22
- "@mariozechner/pi-tui": "^0.23.4",
21
+ "@mariozechner/pi-ai": "^0.23.5",
22
+ "@mariozechner/pi-tui": "^0.23.5",
23
23
  "docx-preview": "^0.3.7",
24
24
  "jszip": "^3.10.1",
25
25
  "lucide": "^0.544.0",
@@ -15,7 +15,7 @@ import type { AgentRunConfig, AgentTransport } from "./types.js";
15
15
  * Uses CORS proxy only for providers that require it (Anthropic OAuth, Z-AI).
16
16
  */
17
17
  export class ProviderTransport implements AgentTransport {
18
- private async getModelAndKey(cfg: AgentRunConfig) {
18
+ private async getModel(cfg: AgentRunConfig) {
19
19
  const apiKey = await getAppStorage().providerKeys.get(cfg.model.provider);
20
20
  if (!apiKey) {
21
21
  throw new Error("no-api-key");
@@ -25,7 +25,7 @@ export class ProviderTransport implements AgentTransport {
25
25
  const proxyUrl = await getAppStorage().settings.get<string>("proxy.url");
26
26
  const model = applyProxyIfNeeded(cfg.model, apiKey, proxyEnabled ? proxyUrl || undefined : undefined);
27
27
 
28
- return { model, apiKey };
28
+ return model;
29
29
  }
30
30
 
31
31
  private buildContext(messages: Message[], cfg: AgentRunConfig): AgentContext {
@@ -36,19 +36,23 @@ export class ProviderTransport implements AgentTransport {
36
36
  };
37
37
  }
38
38
 
39
- private buildLoopConfig(model: typeof cfg.model, apiKey: string, cfg: AgentRunConfig): AgentLoopConfig {
39
+ private buildLoopConfig(model: AgentRunConfig["model"], cfg: AgentRunConfig): AgentLoopConfig {
40
40
  return {
41
41
  model,
42
42
  reasoning: cfg.reasoning,
43
- apiKey,
43
+ // Resolve API key per assistant response (important for expiring OAuth tokens)
44
+ getApiKey: async (provider: string) => {
45
+ const key = await getAppStorage().providerKeys.get(provider);
46
+ return key ?? undefined; // Convert null to undefined for type compatibility
47
+ },
44
48
  getQueuedMessages: cfg.getQueuedMessages,
45
49
  };
46
50
  }
47
51
 
48
52
  async *run(messages: Message[], userMessage: Message, cfg: AgentRunConfig, signal?: AbortSignal) {
49
- const { model, apiKey } = await this.getModelAndKey(cfg);
53
+ const model = await this.getModel(cfg);
50
54
  const context = this.buildContext(messages, cfg);
51
- const pc = this.buildLoopConfig(model, apiKey, cfg);
55
+ const pc = this.buildLoopConfig(model, cfg);
52
56
 
53
57
  for await (const ev of agentLoop(userMessage as unknown as UserMessage, context, pc, signal)) {
54
58
  yield ev;
@@ -56,9 +60,9 @@ export class ProviderTransport implements AgentTransport {
56
60
  }
57
61
 
58
62
  async *continue(messages: Message[], cfg: AgentRunConfig, signal?: AbortSignal) {
59
- const { model, apiKey } = await this.getModelAndKey(cfg);
63
+ const model = await this.getModel(cfg);
60
64
  const context = this.buildContext(messages, cfg);
61
- const pc = this.buildLoopConfig(model, apiKey, cfg);
65
+ const pc = this.buildLoopConfig(model, cfg);
62
66
 
63
67
  for await (const ev of agentLoopContinue(context, pc, signal)) {
64
68
  yield ev;