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

Function connectionCheckHealth

packages/core/sdk/src/executor.ts:3915–4012  ·  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

3913 });
3914
3915 const connectionCheckHealth = (
3916 ref: ConnectionRef,
3917 options?: {
3918 /** Skip the probe and return the persisted verdict when it is younger
3919 * than this. The server owns the freshness decision so N open tabs
3920 * revalidating on load cannot stampede an upstream. Omit = always
3921 * probe (the manual "Check now"). */
3922 readonly ifStaleMs?: number;
3923 },
3924 ): Effect.Effect<
3925 HealthCheckResult,
3926 ConnectionNotFoundError | IntegrationNotFoundError | StorageFailure
3927 > =>
3928 Effect.gen(function* () {
3929 const connectionRow = yield* findConnectionRow(ref);
3930 if (!connectionRow) {
3931 return yield* new ConnectionNotFoundError({
3932 owner: ref.owner,
3933 integration: ref.integration,
3934 name: ref.name,
3935 });
3936 }
3937 if (options?.ifStaleMs !== undefined) {
3938 const cached = Option.getOrNull(decodeLastHealth(connectionRow.last_health));
3939 if (cached && Date.now() - cached.checkedAt < options.ifStaleMs) {
3940 yield* annotateHealthVerdict("cache", cached);
3941 return cached;
3942 }
3943 }
3944 const integrationRow = yield* findIntegrationRow(ref.integration);
3945 if (!integrationRow) {
3946 return yield* new IntegrationNotFoundError({ slug: ref.integration });
3947 }
3948 const runtime = runtimes.get(integrationRow.plugin_id);
3949 const check = runtime?.plugin.checkHealth;
3950 if (!runtime || !check) {
3951 const result = unknownHealth();
3952 yield* annotateHealthVerdict("no_capability", result);
3953 return result;
3954 }
3955 const spec = describeHealthCheckForRow(integrationRow) ?? undefined;
3956 if (spec === undefined && connectionRow.oauth_client != null) {
3957 // No probe operation is declared, so "healthy" here means only "the
3958 // credential resolved (refreshing if due)" — a refresh failure is
3959 // the one real signal this path can produce, and it must not hide
3960 // inside a green span.
3961 const result = yield* oauthCredentialHealthWithoutProbe(connectionRow);
3962 yield* annotateHealthVerdict("credential_only", result);
3963 yield* persistHealthResult(ref, result);
3964 return result;
3965 }
3966
3967 const result = yield* foldCredentialResolutionIntoVerdict(
3968 Effect.gen(function* () {
3969 const values = yield* resolveConnectionValues(connectionRow);
3970 const record = rowToIntegrationRecord(
3971 integrationRow,
3972 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