MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / connectionCheckHealth

Function connectionCheckHealth

packages/core/sdk/src/executor.ts:3698–3795  ·  view source on GitHub ↗
(
      ref: ConnectionRef,
      options?: {
        /** Skip the probe and return the persisted verdict when it is younger
         *  than this. The server owns the freshness decision so N open tabs
         *  revalidating on load cannot stampede an upstream. Omit = always
         *  probe (the manual "Check now"). */
        readonly ifStaleMs?: number;
      },
    )

Source from the content-addressed store, hash-verified

3696 });
3697
3698 const connectionCheckHealth = (
3699 ref: ConnectionRef,
3700 options?: {
3701 /** Skip the probe and return the persisted verdict when it is younger
3702 * than this. The server owns the freshness decision so N open tabs
3703 * revalidating on load cannot stampede an upstream. Omit = always
3704 * probe (the manual "Check now"). */
3705 readonly ifStaleMs?: number;
3706 },
3707 ): Effect.Effect<
3708 HealthCheckResult,
3709 ConnectionNotFoundError | IntegrationNotFoundError | StorageFailure
3710 > =>
3711 Effect.gen(function* () {
3712 const connectionRow = yield* findConnectionRow(ref);
3713 if (!connectionRow) {
3714 return yield* new ConnectionNotFoundError({
3715 owner: ref.owner,
3716 integration: ref.integration,
3717 name: ref.name,
3718 });
3719 }
3720 if (options?.ifStaleMs !== undefined) {
3721 const cached = Option.getOrNull(decodeLastHealth(connectionRow.last_health));
3722 if (cached && Date.now() - cached.checkedAt < options.ifStaleMs) {
3723 yield* annotateHealthVerdict("cache", cached);
3724 return cached;
3725 }
3726 }
3727 const integrationRow = yield* findIntegrationRow(ref.integration);
3728 if (!integrationRow) {
3729 return yield* new IntegrationNotFoundError({ slug: ref.integration });
3730 }
3731 const runtime = runtimes.get(integrationRow.plugin_id);
3732 const check = runtime?.plugin.checkHealth;
3733 if (!runtime || !check) {
3734 const result = unknownHealth();
3735 yield* annotateHealthVerdict("no_capability", result);
3736 return result;
3737 }
3738 const spec = describeHealthCheckForRow(integrationRow) ?? undefined;
3739 if (spec === undefined && connectionRow.oauth_client != null) {
3740 // No probe operation is declared, so "healthy" here means only "the
3741 // credential resolved (refreshing if due)" — a refresh failure is
3742 // the one real signal this path can produce, and it must not hide
3743 // inside a green span.
3744 const result = yield* oauthCredentialHealthWithoutProbe(connectionRow);
3745 yield* annotateHealthVerdict("credential_only", result);
3746 yield* persistHealthResult(ref, result);
3747 return result;
3748 }
3749
3750 const result = yield* foldCredentialResolutionIntoVerdict(
3751 Effect.gen(function* () {
3752 const values = yield* resolveConnectionValues(connectionRow);
3753 const record = rowToIntegrationRecord(
3754 integrationRow,
3755 describeAuthMethodsForRow(integrationRow),

Callers

nothing calls this directly

Calls 15

findConnectionRowFunction · 0.85
annotateHealthVerdictFunction · 0.85
findIntegrationRowFunction · 0.85
unknownHealthFunction · 0.85
persistHealthResultFunction · 0.85
resolveConnectionValuesFunction · 0.85
rowToIntegrationRecordFunction · 0.85
grantedScopesFromRowFunction · 0.85

Tested by

no test coverage detected