Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions sdks/typescript/src/providers/ai-sdk-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ const NOT_INSTALLED = new Set(['ERR_MODULE_NOT_FOUND', 'MODULE_NOT_FOUND']);
* not-installed case keeps the original as `cause` either way.
*/
function adapterImportError(error: unknown, vendor: string, pkg: string): unknown {
// Walked, not read off the top: bundlers and test loaders wrap an import failure in their
// own error and keep the real one as `cause`, so the resolution code is often one level down.
// Structured signal only, per SPEC §6.5: wording is not a contract, and matching on it
// would reclassify an adapter that failed to load for some other reason. Walked rather
// than read off the top, because bundlers and test loaders wrap an import failure in their
// own error and keep the real one as `cause` — sometimes through more than one layer, hence
// walking the chain rather than checking a fixed depth.
const missing = (function isMissing(e: unknown, depth = 0): boolean {
if (e === null || typeof e !== 'object' || depth > 4) return false;
const { code, message, cause } = e as { code?: unknown; message?: unknown; cause?: unknown };
const { code, cause } = e as { code?: unknown; cause?: unknown };
if (typeof code === 'string' && NOT_INSTALLED.has(code)) return true;
if (typeof message === 'string' && /cannot find (module|package)/i.test(message)) return true;
return isMissing(cause, depth + 1);
})(error);

Expand Down
Loading