@theokit/sdk 4.16.0 → 4.16.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.
package/dist/index.js CHANGED
@@ -6016,6 +6016,44 @@ var init_router = __esm({
6016
6016
  }
6017
6017
  });
6018
6018
 
6019
+ // src/internal/local-agent/real-local-run-provider.ts
6020
+ var real_local_run_provider_exports = {};
6021
+ __export(real_local_run_provider_exports, {
6022
+ detectPrimaryProvider: () => detectPrimaryProvider,
6023
+ inferProviderFromApiKey: () => inferProviderFromApiKey
6024
+ });
6025
+ function inferProviderFromApiKey(apiKey) {
6026
+ if (apiKey === void 0 || apiKey.length === 0) return void 0;
6027
+ const byPrefix = [
6028
+ { provider: "openrouter", prefix: "sk-or-" },
6029
+ { provider: "anthropic", prefix: "sk-ant-" },
6030
+ { provider: "openai", prefix: "sk-" }
6031
+ ];
6032
+ for (const { provider, prefix } of byPrefix) {
6033
+ if (apiKey.startsWith(prefix) && getProviderProfile(provider) !== void 0) {
6034
+ return provider;
6035
+ }
6036
+ }
6037
+ return void 0;
6038
+ }
6039
+ function detectPrimaryProvider() {
6040
+ if (process.env.ANTHROPIC_API_KEY !== void 0 && process.env.ANTHROPIC_API_KEY.length > 0) {
6041
+ return "anthropic";
6042
+ }
6043
+ if (process.env.OPENAI_API_KEY !== void 0 && process.env.OPENAI_API_KEY.length > 0) {
6044
+ return "openai";
6045
+ }
6046
+ if (process.env.OPENROUTER_API_KEY !== void 0 && process.env.OPENROUTER_API_KEY.length > 0) {
6047
+ return "openrouter";
6048
+ }
6049
+ return "openai";
6050
+ }
6051
+ var init_real_local_run_provider = __esm({
6052
+ "src/internal/local-agent/real-local-run-provider.ts"() {
6053
+ init_providers();
6054
+ }
6055
+ });
6056
+
6019
6057
  // src/internal/session/compact-session.ts
6020
6058
  var compact_session_exports = {};
6021
6059
  __export(compact_session_exports, {
@@ -6078,13 +6116,20 @@ function buildDefaultSummarizer(opts) {
6078
6116
  const { compressConversationWindow: compressConversationWindow2 } = await Promise.resolve().then(() => (init_compression_summarizer(), compression_summarizer_exports));
6079
6117
  const { resolveCompressionModel: resolveCompressionModel2 } = await Promise.resolve().then(() => (init_compression_model_registry(), compression_model_registry_exports));
6080
6118
  const { resolveProviderChain: resolveProviderChain2 } = await Promise.resolve().then(() => (init_router(), router_exports));
6119
+ const { inferProviderFromApiKey: inferProviderFromApiKey2, detectPrimaryProvider: detectPrimaryProvider2 } = await Promise.resolve().then(() => (init_real_local_run_provider(), real_local_run_provider_exports));
6120
+ const keyProvider = inferProviderFromApiKey2(opts.apiKey);
6121
+ const modelPrefix = opts.agentModel.includes("/") ? opts.agentModel.slice(0, opts.agentModel.indexOf("/")) : void 0;
6122
+ const provider = keyProvider ?? modelPrefix ?? detectPrimaryProvider2();
6081
6123
  let model;
6082
- try {
6083
- model = resolveCompressionModel2(opts.agentModel);
6084
- } catch {
6124
+ if (keyProvider !== void 0 && keyProvider !== modelPrefix) {
6085
6125
  model = opts.agentModel;
6126
+ } else {
6127
+ try {
6128
+ model = resolveCompressionModel2(opts.agentModel);
6129
+ } catch {
6130
+ model = opts.agentModel;
6131
+ }
6086
6132
  }
6087
- const provider = model.includes("/") ? model.slice(0, model.indexOf("/")) : "openai";
6088
6133
  const callLlm = async (m, system, user) => {
6089
6134
  const chain = resolveProviderChain2({
6090
6135
  primary: provider,
@@ -18130,35 +18175,7 @@ function registerPluginProviderProfiles(entries) {
18130
18175
 
18131
18176
  // src/internal/local-agent/real-local-run.ts
18132
18177
  init_async_local_storage();
18133
-
18134
- // src/internal/local-agent/real-local-run-provider.ts
18135
- init_providers();
18136
- function inferProviderFromApiKey(apiKey) {
18137
- if (apiKey === void 0 || apiKey.length === 0) return void 0;
18138
- const byPrefix = [
18139
- { provider: "openrouter", prefix: "sk-or-" },
18140
- { provider: "anthropic", prefix: "sk-ant-" },
18141
- { provider: "openai", prefix: "sk-" }
18142
- ];
18143
- for (const { provider, prefix } of byPrefix) {
18144
- if (apiKey.startsWith(prefix) && getProviderProfile(provider) !== void 0) {
18145
- return provider;
18146
- }
18147
- }
18148
- return void 0;
18149
- }
18150
- function detectPrimaryProvider() {
18151
- if (process.env.ANTHROPIC_API_KEY !== void 0 && process.env.ANTHROPIC_API_KEY.length > 0) {
18152
- return "anthropic";
18153
- }
18154
- if (process.env.OPENAI_API_KEY !== void 0 && process.env.OPENAI_API_KEY.length > 0) {
18155
- return "openai";
18156
- }
18157
- if (process.env.OPENROUTER_API_KEY !== void 0 && process.env.OPENROUTER_API_KEY.length > 0) {
18158
- return "openrouter";
18159
- }
18160
- return "openai";
18161
- }
18178
+ init_real_local_run_provider();
18162
18179
 
18163
18180
  // src/a2a/subagent.ts
18164
18181
  init_agent_factory_registry();
@@ -21481,7 +21498,11 @@ var Agent = class _Agent {
21481
21498
  * @public
21482
21499
  */
21483
21500
  static async compact(agentId, options = {}) {
21484
- const reg = getRegisteredAgent(agentId);
21501
+ let reg = getRegisteredAgent(agentId);
21502
+ if (reg === void 0) {
21503
+ await hydrateRegistryFromDisk(process.cwd());
21504
+ reg = getRegisteredAgent(agentId);
21505
+ }
21485
21506
  if (reg === void 0 || reg.runtime !== "local") {
21486
21507
  throw new UnknownAgentError(`No local agent "${agentId}" registered \u2014 compact targets local sessions.`);
21487
21508
  }