@mariozechner/pi-agent-core 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.
@@ -20,7 +20,7 @@ export interface ProviderTransportOptions {
20
20
  export declare class ProviderTransport implements AgentTransport {
21
21
  private options;
22
22
  constructor(options?: ProviderTransportOptions);
23
- private getModelAndKey;
23
+ private getModel;
24
24
  private buildContext;
25
25
  private buildLoopConfig;
26
26
  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/transports/ProviderTransport.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,KAAK,OAAO,EAEZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjE,MAAM,WAAW,wBAAwB;IACxC;;;OAGG;IACH,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,GAAG,MAAM,GAAG,SAAS,CAAC;IAEnF;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;GAGG;AACH,qBAAa,iBAAkB,YAAW,cAAc;IACvD,OAAO,CAAC,OAAO,CAA2B;IAE1C,YAAY,OAAO,GAAE,wBAA6B,EAEjD;YAEa,cAAc;IAoB5B,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,2EAQ9F;IAEM,QAAQ,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,cAAc,EAAE,MAAM,CAAC,EAAE,WAAW,2EAQ7E;CACD","sourcesContent":["import {\n\ttype AgentContext,\n\ttype AgentLoopConfig,\n\tagentLoop,\n\tagentLoopContinue,\n\ttype Message,\n\ttype UserMessage,\n} from \"@mariozechner/pi-ai\";\nimport type { AgentRunConfig, AgentTransport } from \"./types.js\";\n\nexport interface ProviderTransportOptions {\n\t/**\n\t * Function to retrieve API key for a given provider.\n\t * If not provided, transport will try to use environment variables.\n\t */\n\tgetApiKey?: (provider: string) => Promise<string | undefined> | string | undefined;\n\n\t/**\n\t * Optional CORS proxy URL for browser environments.\n\t * If provided, all requests will be routed through this proxy.\n\t * Format: \"https://proxy.example.com\"\n\t */\n\tcorsProxyUrl?: string;\n}\n\n/**\n * Transport that calls LLM providers directly.\n * Optionally routes calls through a CORS proxy if configured.\n */\nexport class ProviderTransport implements AgentTransport {\n\tprivate options: ProviderTransportOptions;\n\n\tconstructor(options: ProviderTransportOptions = {}) {\n\t\tthis.options = options;\n\t}\n\n\tprivate async getModelAndKey(cfg: AgentRunConfig) {\n\t\tlet apiKey: string | undefined;\n\t\tif (this.options.getApiKey) {\n\t\t\tapiKey = await this.options.getApiKey(cfg.model.provider);\n\t\t}\n\t\tif (!apiKey) {\n\t\t\tthrow new Error(`No API key found for provider: ${cfg.model.provider}`);\n\t\t}\n\n\t\tlet model = cfg.model;\n\t\tif (this.options.corsProxyUrl && cfg.model.baseUrl) {\n\t\t\tmodel = {\n\t\t\t\t...cfg.model,\n\t\t\t\tbaseUrl: `${this.options.corsProxyUrl}/?url=${encodeURIComponent(cfg.model.baseUrl)}`,\n\t\t\t};\n\t\t}\n\n\t\treturn { model, apiKey };\n\t}\n\n\tprivate buildContext(messages: Message[], cfg: AgentRunConfig): AgentContext {\n\t\treturn {\n\t\t\tsystemPrompt: cfg.systemPrompt,\n\t\t\tmessages,\n\t\t\ttools: cfg.tools,\n\t\t};\n\t}\n\n\tprivate buildLoopConfig(model: typeof cfg.model, apiKey: string, cfg: AgentRunConfig): AgentLoopConfig {\n\t\treturn {\n\t\t\tmodel,\n\t\t\treasoning: cfg.reasoning,\n\t\t\tapiKey,\n\t\t\tgetQueuedMessages: cfg.getQueuedMessages,\n\t\t};\n\t}\n\n\tasync *run(messages: Message[], userMessage: Message, cfg: AgentRunConfig, signal?: AbortSignal) {\n\t\tconst { model, apiKey } = await this.getModelAndKey(cfg);\n\t\tconst context = this.buildContext(messages, cfg);\n\t\tconst pc = this.buildLoopConfig(model, apiKey, cfg);\n\n\t\tfor await (const ev of agentLoop(userMessage as unknown as UserMessage, context, pc, signal)) {\n\t\t\tyield ev;\n\t\t}\n\t}\n\n\tasync *continue(messages: Message[], cfg: AgentRunConfig, signal?: AbortSignal) {\n\t\tconst { model, apiKey } = await this.getModelAndKey(cfg);\n\t\tconst context = this.buildContext(messages, cfg);\n\t\tconst pc = this.buildLoopConfig(model, apiKey, cfg);\n\n\t\tfor await (const ev of agentLoopContinue(context, pc, signal)) {\n\t\t\tyield ev;\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"ProviderTransport.d.ts","sourceRoot":"","sources":["../../src/transports/ProviderTransport.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,KAAK,OAAO,EAEZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjE,MAAM,WAAW,wBAAwB;IACxC;;;OAGG;IACH,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,GAAG,MAAM,GAAG,SAAS,CAAC;IAEnF;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;GAGG;AACH,qBAAa,iBAAkB,YAAW,cAAc;IACvD,OAAO,CAAC,OAAO,CAA2B;IAE1C,YAAY,OAAO,GAAE,wBAA6B,EAEjD;IAED,OAAO,CAAC,QAAQ;IAWhB,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,eAAe;IAUhB,GAAG,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,EAAE,cAAc,EAAE,MAAM,CAAC,EAAE,WAAW,2EAQ9F;IAEM,QAAQ,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,cAAc,EAAE,MAAM,CAAC,EAAE,WAAW,2EAQ7E;CACD","sourcesContent":["import {\n\ttype AgentContext,\n\ttype AgentLoopConfig,\n\tagentLoop,\n\tagentLoopContinue,\n\ttype Message,\n\ttype UserMessage,\n} from \"@mariozechner/pi-ai\";\nimport type { AgentRunConfig, AgentTransport } from \"./types.js\";\n\nexport interface ProviderTransportOptions {\n\t/**\n\t * Function to retrieve API key for a given provider.\n\t * If not provided, transport will try to use environment variables.\n\t */\n\tgetApiKey?: (provider: string) => Promise<string | undefined> | string | undefined;\n\n\t/**\n\t * Optional CORS proxy URL for browser environments.\n\t * If provided, all requests will be routed through this proxy.\n\t * Format: \"https://proxy.example.com\"\n\t */\n\tcorsProxyUrl?: string;\n}\n\n/**\n * Transport that calls LLM providers directly.\n * Optionally routes calls through a CORS proxy if configured.\n */\nexport class ProviderTransport implements AgentTransport {\n\tprivate options: ProviderTransportOptions;\n\n\tconstructor(options: ProviderTransportOptions = {}) {\n\t\tthis.options = options;\n\t}\n\n\tprivate getModel(cfg: AgentRunConfig) {\n\t\tlet model = cfg.model;\n\t\tif (this.options.corsProxyUrl && cfg.model.baseUrl) {\n\t\t\tmodel = {\n\t\t\t\t...cfg.model,\n\t\t\t\tbaseUrl: `${this.options.corsProxyUrl}/?url=${encodeURIComponent(cfg.model.baseUrl)}`,\n\t\t\t};\n\t\t}\n\t\treturn model;\n\t}\n\n\tprivate buildContext(messages: Message[], cfg: AgentRunConfig): AgentContext {\n\t\treturn {\n\t\t\tsystemPrompt: cfg.systemPrompt,\n\t\t\tmessages,\n\t\t\ttools: cfg.tools,\n\t\t};\n\t}\n\n\tprivate buildLoopConfig(model: AgentRunConfig[\"model\"], cfg: AgentRunConfig): AgentLoopConfig {\n\t\treturn {\n\t\t\tmodel,\n\t\t\treasoning: cfg.reasoning,\n\t\t\t// Resolve API key per assistant response (important for expiring OAuth tokens)\n\t\t\tgetApiKey: this.options.getApiKey,\n\t\t\tgetQueuedMessages: cfg.getQueuedMessages,\n\t\t};\n\t}\n\n\tasync *run(messages: Message[], userMessage: Message, cfg: AgentRunConfig, signal?: AbortSignal) {\n\t\tconst model = this.getModel(cfg);\n\t\tconst context = this.buildContext(messages, cfg);\n\t\tconst pc = this.buildLoopConfig(model, cfg);\n\n\t\tfor await (const ev of agentLoop(userMessage as unknown as UserMessage, context, pc, signal)) {\n\t\t\tyield ev;\n\t\t}\n\t}\n\n\tasync *continue(messages: Message[], cfg: AgentRunConfig, signal?: AbortSignal) {\n\t\tconst model = this.getModel(cfg);\n\t\tconst context = this.buildContext(messages, cfg);\n\t\tconst pc = this.buildLoopConfig(model, cfg);\n\n\t\tfor await (const ev of agentLoopContinue(context, pc, signal)) {\n\t\t\tyield ev;\n\t\t}\n\t}\n}\n"]}
@@ -8,14 +8,7 @@ export class ProviderTransport {
8
8
  constructor(options = {}) {
9
9
  this.options = options;
10
10
  }
11
- async getModelAndKey(cfg) {
12
- let apiKey;
13
- if (this.options.getApiKey) {
14
- apiKey = await this.options.getApiKey(cfg.model.provider);
15
- }
16
- if (!apiKey) {
17
- throw new Error(`No API key found for provider: ${cfg.model.provider}`);
18
- }
11
+ getModel(cfg) {
19
12
  let model = cfg.model;
20
13
  if (this.options.corsProxyUrl && cfg.model.baseUrl) {
21
14
  model = {
@@ -23,7 +16,7 @@ export class ProviderTransport {
23
16
  baseUrl: `${this.options.corsProxyUrl}/?url=${encodeURIComponent(cfg.model.baseUrl)}`,
24
17
  };
25
18
  }
26
- return { model, apiKey };
19
+ return model;
27
20
  }
28
21
  buildContext(messages, cfg) {
29
22
  return {
@@ -32,26 +25,27 @@ export class ProviderTransport {
32
25
  tools: cfg.tools,
33
26
  };
34
27
  }
35
- buildLoopConfig(model, apiKey, cfg) {
28
+ buildLoopConfig(model, cfg) {
36
29
  return {
37
30
  model,
38
31
  reasoning: cfg.reasoning,
39
- apiKey,
32
+ // Resolve API key per assistant response (important for expiring OAuth tokens)
33
+ getApiKey: this.options.getApiKey,
40
34
  getQueuedMessages: cfg.getQueuedMessages,
41
35
  };
42
36
  }
43
37
  async *run(messages, userMessage, cfg, signal) {
44
- const { model, apiKey } = await this.getModelAndKey(cfg);
38
+ const model = this.getModel(cfg);
45
39
  const context = this.buildContext(messages, cfg);
46
- const pc = this.buildLoopConfig(model, apiKey, cfg);
40
+ const pc = this.buildLoopConfig(model, cfg);
47
41
  for await (const ev of agentLoop(userMessage, context, pc, signal)) {
48
42
  yield ev;
49
43
  }
50
44
  }
51
45
  async *continue(messages, cfg, signal) {
52
- const { model, apiKey } = await this.getModelAndKey(cfg);
46
+ const model = this.getModel(cfg);
53
47
  const context = this.buildContext(messages, cfg);
54
- const pc = this.buildLoopConfig(model, apiKey, cfg);
48
+ const pc = this.buildLoopConfig(model, cfg);
55
49
  for await (const ev of agentLoopContinue(context, pc, signal)) {
56
50
  yield ev;
57
51
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ProviderTransport.js","sourceRoot":"","sources":["../../src/transports/ProviderTransport.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,SAAS,EACT,iBAAiB,GAGjB,MAAM,qBAAqB,CAAC;AAkB7B;;;GAGG;AACH,MAAM,OAAO,iBAAiB;IACrB,OAAO,CAA2B;IAE1C,YAAY,OAAO,GAA6B,EAAE,EAAE;QACnD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAAA,CACvB;IAEO,KAAK,CAAC,cAAc,CAAC,GAAmB,EAAE;QACjD,IAAI,MAA0B,CAAC;QAC/B,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;YAC5B,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC3D,CAAC;QACD,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,kCAAkC,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;QACzE,CAAC;QAED,IAAI,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC;QACtB,IAAI,IAAI,CAAC,OAAO,CAAC,YAAY,IAAI,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;YACpD,KAAK,GAAG;gBACP,GAAG,GAAG,CAAC,KAAK;gBACZ,OAAO,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,SAAS,kBAAkB,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE;aACrF,CAAC;QACH,CAAC;QAED,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAAA,CACzB;IAEO,YAAY,CAAC,QAAmB,EAAE,GAAmB,EAAgB;QAC5E,OAAO;YACN,YAAY,EAAE,GAAG,CAAC,YAAY;YAC9B,QAAQ;YACR,KAAK,EAAE,GAAG,CAAC,KAAK;SAChB,CAAC;IAAA,CACF;IAEO,eAAe,CAAC,KAAuB,EAAE,MAAc,EAAE,GAAmB,EAAmB;QACtG,OAAO;YACN,KAAK;YACL,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,MAAM;YACN,iBAAiB,EAAE,GAAG,CAAC,iBAAiB;SACxC,CAAC;IAAA,CACF;IAED,KAAK,CAAC,CAAC,GAAG,CAAC,QAAmB,EAAE,WAAoB,EAAE,GAAmB,EAAE,MAAoB,EAAE;QAChG,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;QACzD,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QACjD,MAAM,EAAE,GAAG,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;QAEpD,IAAI,KAAK,EAAE,MAAM,EAAE,IAAI,SAAS,CAAC,WAAqC,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,CAAC;YAC9F,MAAM,EAAE,CAAC;QACV,CAAC;IAAA,CACD;IAED,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAmB,EAAE,GAAmB,EAAE,MAAoB,EAAE;QAC/E,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;QACzD,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QACjD,MAAM,EAAE,GAAG,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;QAEpD,IAAI,KAAK,EAAE,MAAM,EAAE,IAAI,iBAAiB,CAAC,OAAO,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,CAAC;YAC/D,MAAM,EAAE,CAAC;QACV,CAAC;IAAA,CACD;CACD","sourcesContent":["import {\n\ttype AgentContext,\n\ttype AgentLoopConfig,\n\tagentLoop,\n\tagentLoopContinue,\n\ttype Message,\n\ttype UserMessage,\n} from \"@mariozechner/pi-ai\";\nimport type { AgentRunConfig, AgentTransport } from \"./types.js\";\n\nexport interface ProviderTransportOptions {\n\t/**\n\t * Function to retrieve API key for a given provider.\n\t * If not provided, transport will try to use environment variables.\n\t */\n\tgetApiKey?: (provider: string) => Promise<string | undefined> | string | undefined;\n\n\t/**\n\t * Optional CORS proxy URL for browser environments.\n\t * If provided, all requests will be routed through this proxy.\n\t * Format: \"https://proxy.example.com\"\n\t */\n\tcorsProxyUrl?: string;\n}\n\n/**\n * Transport that calls LLM providers directly.\n * Optionally routes calls through a CORS proxy if configured.\n */\nexport class ProviderTransport implements AgentTransport {\n\tprivate options: ProviderTransportOptions;\n\n\tconstructor(options: ProviderTransportOptions = {}) {\n\t\tthis.options = options;\n\t}\n\n\tprivate async getModelAndKey(cfg: AgentRunConfig) {\n\t\tlet apiKey: string | undefined;\n\t\tif (this.options.getApiKey) {\n\t\t\tapiKey = await this.options.getApiKey(cfg.model.provider);\n\t\t}\n\t\tif (!apiKey) {\n\t\t\tthrow new Error(`No API key found for provider: ${cfg.model.provider}`);\n\t\t}\n\n\t\tlet model = cfg.model;\n\t\tif (this.options.corsProxyUrl && cfg.model.baseUrl) {\n\t\t\tmodel = {\n\t\t\t\t...cfg.model,\n\t\t\t\tbaseUrl: `${this.options.corsProxyUrl}/?url=${encodeURIComponent(cfg.model.baseUrl)}`,\n\t\t\t};\n\t\t}\n\n\t\treturn { model, apiKey };\n\t}\n\n\tprivate buildContext(messages: Message[], cfg: AgentRunConfig): AgentContext {\n\t\treturn {\n\t\t\tsystemPrompt: cfg.systemPrompt,\n\t\t\tmessages,\n\t\t\ttools: cfg.tools,\n\t\t};\n\t}\n\n\tprivate buildLoopConfig(model: typeof cfg.model, apiKey: string, cfg: AgentRunConfig): AgentLoopConfig {\n\t\treturn {\n\t\t\tmodel,\n\t\t\treasoning: cfg.reasoning,\n\t\t\tapiKey,\n\t\t\tgetQueuedMessages: cfg.getQueuedMessages,\n\t\t};\n\t}\n\n\tasync *run(messages: Message[], userMessage: Message, cfg: AgentRunConfig, signal?: AbortSignal) {\n\t\tconst { model, apiKey } = await this.getModelAndKey(cfg);\n\t\tconst context = this.buildContext(messages, cfg);\n\t\tconst pc = this.buildLoopConfig(model, apiKey, cfg);\n\n\t\tfor await (const ev of agentLoop(userMessage as unknown as UserMessage, context, pc, signal)) {\n\t\t\tyield ev;\n\t\t}\n\t}\n\n\tasync *continue(messages: Message[], cfg: AgentRunConfig, signal?: AbortSignal) {\n\t\tconst { model, apiKey } = await this.getModelAndKey(cfg);\n\t\tconst context = this.buildContext(messages, cfg);\n\t\tconst pc = this.buildLoopConfig(model, apiKey, cfg);\n\n\t\tfor await (const ev of agentLoopContinue(context, pc, signal)) {\n\t\t\tyield ev;\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"ProviderTransport.js","sourceRoot":"","sources":["../../src/transports/ProviderTransport.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,SAAS,EACT,iBAAiB,GAGjB,MAAM,qBAAqB,CAAC;AAkB7B;;;GAGG;AACH,MAAM,OAAO,iBAAiB;IACrB,OAAO,CAA2B;IAE1C,YAAY,OAAO,GAA6B,EAAE,EAAE;QACnD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAAA,CACvB;IAEO,QAAQ,CAAC,GAAmB,EAAE;QACrC,IAAI,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC;QACtB,IAAI,IAAI,CAAC,OAAO,CAAC,YAAY,IAAI,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;YACpD,KAAK,GAAG;gBACP,GAAG,GAAG,CAAC,KAAK;gBACZ,OAAO,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,SAAS,kBAAkB,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE;aACrF,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC;IAAA,CACb;IAEO,YAAY,CAAC,QAAmB,EAAE,GAAmB,EAAgB;QAC5E,OAAO;YACN,YAAY,EAAE,GAAG,CAAC,YAAY;YAC9B,QAAQ;YACR,KAAK,EAAE,GAAG,CAAC,KAAK;SAChB,CAAC;IAAA,CACF;IAEO,eAAe,CAAC,KAA8B,EAAE,GAAmB,EAAmB;QAC7F,OAAO;YACN,KAAK;YACL,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,+EAA+E;YAC/E,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS;YACjC,iBAAiB,EAAE,GAAG,CAAC,iBAAiB;SACxC,CAAC;IAAA,CACF;IAED,KAAK,CAAC,CAAC,GAAG,CAAC,QAAmB,EAAE,WAAoB,EAAE,GAAmB,EAAE,MAAoB,EAAE;QAChG,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QACjC,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QACjD,MAAM,EAAE,GAAG,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAE5C,IAAI,KAAK,EAAE,MAAM,EAAE,IAAI,SAAS,CAAC,WAAqC,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,CAAC;YAC9F,MAAM,EAAE,CAAC;QACV,CAAC;IAAA,CACD;IAED,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAmB,EAAE,GAAmB,EAAE,MAAoB,EAAE;QAC/E,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QACjC,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QACjD,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;IAAA,CACD;CACD","sourcesContent":["import {\n\ttype AgentContext,\n\ttype AgentLoopConfig,\n\tagentLoop,\n\tagentLoopContinue,\n\ttype Message,\n\ttype UserMessage,\n} from \"@mariozechner/pi-ai\";\nimport type { AgentRunConfig, AgentTransport } from \"./types.js\";\n\nexport interface ProviderTransportOptions {\n\t/**\n\t * Function to retrieve API key for a given provider.\n\t * If not provided, transport will try to use environment variables.\n\t */\n\tgetApiKey?: (provider: string) => Promise<string | undefined> | string | undefined;\n\n\t/**\n\t * Optional CORS proxy URL for browser environments.\n\t * If provided, all requests will be routed through this proxy.\n\t * Format: \"https://proxy.example.com\"\n\t */\n\tcorsProxyUrl?: string;\n}\n\n/**\n * Transport that calls LLM providers directly.\n * Optionally routes calls through a CORS proxy if configured.\n */\nexport class ProviderTransport implements AgentTransport {\n\tprivate options: ProviderTransportOptions;\n\n\tconstructor(options: ProviderTransportOptions = {}) {\n\t\tthis.options = options;\n\t}\n\n\tprivate getModel(cfg: AgentRunConfig) {\n\t\tlet model = cfg.model;\n\t\tif (this.options.corsProxyUrl && cfg.model.baseUrl) {\n\t\t\tmodel = {\n\t\t\t\t...cfg.model,\n\t\t\t\tbaseUrl: `${this.options.corsProxyUrl}/?url=${encodeURIComponent(cfg.model.baseUrl)}`,\n\t\t\t};\n\t\t}\n\t\treturn model;\n\t}\n\n\tprivate buildContext(messages: Message[], cfg: AgentRunConfig): AgentContext {\n\t\treturn {\n\t\t\tsystemPrompt: cfg.systemPrompt,\n\t\t\tmessages,\n\t\t\ttools: cfg.tools,\n\t\t};\n\t}\n\n\tprivate buildLoopConfig(model: AgentRunConfig[\"model\"], cfg: AgentRunConfig): AgentLoopConfig {\n\t\treturn {\n\t\t\tmodel,\n\t\t\treasoning: cfg.reasoning,\n\t\t\t// Resolve API key per assistant response (important for expiring OAuth tokens)\n\t\t\tgetApiKey: this.options.getApiKey,\n\t\t\tgetQueuedMessages: cfg.getQueuedMessages,\n\t\t};\n\t}\n\n\tasync *run(messages: Message[], userMessage: Message, cfg: AgentRunConfig, signal?: AbortSignal) {\n\t\tconst model = this.getModel(cfg);\n\t\tconst context = this.buildContext(messages, cfg);\n\t\tconst pc = this.buildLoopConfig(model, cfg);\n\n\t\tfor await (const ev of agentLoop(userMessage as unknown as UserMessage, context, pc, signal)) {\n\t\t\tyield ev;\n\t\t}\n\t}\n\n\tasync *continue(messages: Message[], cfg: AgentRunConfig, signal?: AbortSignal) {\n\t\tconst model = this.getModel(cfg);\n\t\tconst context = this.buildContext(messages, cfg);\n\t\tconst pc = this.buildLoopConfig(model, cfg);\n\n\t\tfor await (const ev of agentLoopContinue(context, pc, signal)) {\n\t\t\tyield ev;\n\t\t}\n\t}\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mariozechner/pi-agent-core",
3
- "version": "0.23.4",
3
+ "version": "0.23.5",
4
4
  "description": "General-purpose agent with transport abstraction, state management, and attachment support",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -18,8 +18,8 @@
18
18
  "prepublishOnly": "npm run clean && npm run build"
19
19
  },
20
20
  "dependencies": {
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
  },
24
24
  "keywords": [
25
25
  "ai",