refactor(v2): drop @chat-adapter/shared dep — duck-type NetworkError
The only use was channel-registry.ts checking `err instanceof NetworkError` to retry transient setup failures. Switched to a duck-type predicate (`err.name === 'NetworkError'`) so the dep is no longer needed at trunk level. Channel skills bring it in transitively when they install their Chat SDK adapter package. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,15 +1,21 @@
|
||||
/**
|
||||
* v2 Channel adapter registry.
|
||||
* Channel adapter registry.
|
||||
*
|
||||
* Channels self-register on import. The host calls initChannelAdapters() at startup
|
||||
* to instantiate and set up all registered adapters.
|
||||
*/
|
||||
import { NetworkError } from '@chat-adapter/shared';
|
||||
import type { ChannelAdapter, ChannelRegistration, ChannelSetup } from './adapter.js';
|
||||
import { log } from '../log.js';
|
||||
|
||||
const SETUP_RETRY_DELAYS_MS = [2000, 5000, 10000];
|
||||
|
||||
/** Duck-type check — adapters that throw an Error with `name === 'NetworkError'`
|
||||
* (Chat SDK's `@chat-adapter/shared.NetworkError` and similar) get a retry on
|
||||
* setup. Avoids depending on `@chat-adapter/shared` at trunk level. */
|
||||
function isNetworkError(err: unknown): err is Error {
|
||||
return err instanceof Error && err.name === 'NetworkError';
|
||||
}
|
||||
|
||||
const sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms));
|
||||
|
||||
const registry = new Map<string, ChannelRegistration>();
|
||||
@@ -64,7 +70,7 @@ export async function initChannelAdapters(setupFn: (adapter: ChannelAdapter) =>
|
||||
await adapter.setup(setup);
|
||||
break;
|
||||
} catch (err) {
|
||||
if (err instanceof NetworkError && attempt < SETUP_RETRY_DELAYS_MS.length) {
|
||||
if (isNetworkError(err) && attempt < SETUP_RETRY_DELAYS_MS.length) {
|
||||
const delay = SETUP_RETRY_DELAYS_MS[attempt]!;
|
||||
log.warn('Channel adapter setup failed with network error, retrying', {
|
||||
channel: name,
|
||||
|
||||
Reference in New Issue
Block a user