@yeaft/webchat-agent 0.1.580 → 0.1.582

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yeaft/webchat-agent",
3
- "version": "0.1.580",
3
+ "version": "0.1.582",
4
4
  "description": "Remote agent for Yeaft WebChat — connects worker machines to the central server",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -90,6 +90,30 @@ export class AdapterRouter extends LLMAdapter {
90
90
  }
91
91
  }
92
92
 
93
+ /**
94
+ * Resolve the effective wire protocol for a (provider, model) pair.
95
+ *
96
+ * The provider's declared protocol is the default, but Anthropic-style
97
+ * model IDs (e.g. "claude-opus-4.7") cannot be served by the OpenAI
98
+ * Responses API even when the provider sits in front of both. Detect
99
+ * that mismatch and downgrade to chat-completions, which proxies like
100
+ * GitHub Copilot DO support for Claude models.
101
+ *
102
+ * @param {object} provider — Provider config
103
+ * @param {string} modelId
104
+ * @returns {'anthropic' | 'openai-responses' | 'openai'}
105
+ */
106
+ #effectiveProtocol(provider, modelId) {
107
+ const declared = provider.protocol || 'openai';
108
+ // Anthropic models — only 'anthropic' or 'openai' (chat-completions) make sense.
109
+ // Responses API does not support Claude → fall back to chat-completions.
110
+ if (typeof modelId === 'string' && modelId.startsWith('claude-')) {
111
+ if (declared === 'openai-responses') return 'openai';
112
+ return declared; // anthropic / openai both fine
113
+ }
114
+ return declared;
115
+ }
116
+
93
117
  /**
94
118
  * Resolve a model ID to its provider's adapter (lazy-created, cached).
95
119
  *
@@ -106,12 +130,14 @@ export class AdapterRouter extends LLMAdapter {
106
130
  );
107
131
  }
108
132
 
109
- // Check cache
110
- const cached = this.#adapterCache.get(provider.name);
133
+ // Compute the effective protocol per model — a single provider may need
134
+ // two adapters (e.g. copilot proxy: openai-responses for gpt-5*,
135
+ // chat-completions for claude-*). Cache key includes the protocol.
136
+ const protocol = this.#effectiveProtocol(provider, modelId);
137
+ const cacheKey = `${provider.name}::${protocol}`;
138
+ const cached = this.#adapterCache.get(cacheKey);
111
139
  if (cached) return cached;
112
140
 
113
- // Create adapter based on protocol
114
- const protocol = provider.protocol || 'openai';
115
141
  let adapter;
116
142
 
117
143
  if (protocol === 'anthropic') {
@@ -136,7 +162,7 @@ export class AdapterRouter extends LLMAdapter {
136
162
  });
137
163
  }
138
164
 
139
- this.#adapterCache.set(provider.name, adapter);
165
+ this.#adapterCache.set(cacheKey, adapter);
140
166
  return adapter;
141
167
  }
142
168