Files
dsh-telegram-channel/lib/apiproxy.js
T
owoandCursor 5dbe833205 fix: resolve apiProxy via ctx.get for /model (v0.3.2)
Cordis throws on ctx.apiProxy without inject; use ctx.get and declare apiProxy inject so catalog and model APIs work under dsh web.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-14 20:20:55 +08:00

28 lines
769 B
JavaScript

/**
* Resolve host apiProxy without requiring Cordis inject.
* Direct `ctx.apiProxy` throws "cannot get property without inject" on real fibers.
*/
export function resolveApiProxy(ctx) {
const c = ctx;
if (typeof c.get === 'function') {
try {
const viaGet = c.get('apiProxy');
if (viaGet)
return viaGet;
}
catch {
// ignore and try own-property fallback (tests / plain mocks)
}
}
try {
// Own property on plain mocks only — Cordis proxy throws without inject.
if (Object.prototype.hasOwnProperty.call(c, 'apiProxy') && c.apiProxy) {
return c.apiProxy;
}
}
catch {
return undefined;
}
return undefined;
}