@agentskit/adapters 0.13.0 → 0.13.3

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
@@ -1,6 +1,6 @@
1
1
  export { createAdapter } from './chunk-6FPLWOVE.js';
2
- import { createStreamSource, parseAnthropicStream, parseGeminiStream, parseOllamaStream, toProviderMessages, parseOpenAIStream, openai } from './chunk-726IKNNR.js';
3
- export { chunkText, fetchWithRetry, openai, simulateStream } from './chunk-726IKNNR.js';
2
+ import { createStreamSource, parseAnthropicStream, parseGeminiStream, parseOllamaStream, toProviderMessages, parseOpenAIStream, openai } from './chunk-77QS3QRT.js';
3
+ export { chunkText, fetchWithRetry, openai, simulateStream } from './chunk-77QS3QRT.js';
4
4
  import { ConfigError, ErrorCodes, AdapterError } from '@agentskit/core';
5
5
 
6
6
  // src/generic.ts
@@ -1162,26 +1162,36 @@ function createFallbackAdapter(candidates, options = {}) {
1162
1162
  }
1163
1163
  active = source;
1164
1164
  const iter = source.stream()[Symbol.asyncIterator]();
1165
- let first;
1165
+ let firstReal;
1166
+ let branchError;
1166
1167
  try {
1167
- first = await iter.next();
1168
+ while (true) {
1169
+ const r = await iter.next();
1170
+ if (r.done) {
1171
+ branchError = new Error(`candidate ${candidate.id} emitted no chunks`);
1172
+ break;
1173
+ }
1174
+ if (r.value.type === "error") {
1175
+ branchError = new Error(
1176
+ `candidate ${candidate.id}: ${r.value.content ?? "stream error"}`
1177
+ );
1178
+ break;
1179
+ }
1180
+ firstReal = r.value;
1181
+ break;
1182
+ }
1168
1183
  } catch (err) {
1169
- const error = err instanceof Error ? err : new Error(String(err));
1170
- errors.push({ id: candidate.id, error });
1171
- options.onFallback?.({ id: candidate.id, index: i, error });
1172
- if (options.shouldRetry && !options.shouldRetry(error, i)) throw error;
1173
- active = void 0;
1174
- continue;
1184
+ branchError = err instanceof Error ? err : new Error(String(err));
1175
1185
  }
1176
- if (first.done) {
1177
- const error = new Error(`candidate ${candidate.id} emitted no chunks`);
1186
+ if (branchError || !firstReal) {
1187
+ const error = branchError ?? new Error(`candidate ${candidate.id} emitted no chunks`);
1178
1188
  errors.push({ id: candidate.id, error });
1179
1189
  options.onFallback?.({ id: candidate.id, index: i, error });
1180
1190
  if (options.shouldRetry && !options.shouldRetry(error, i)) throw error;
1181
1191
  active = void 0;
1182
1192
  continue;
1183
1193
  }
1184
- yield first.value;
1194
+ yield firstReal;
1185
1195
  while (true) {
1186
1196
  const next = await iter.next();
1187
1197
  if (next.done) return;