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

Function connectionCheckHealth

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

2897 });
2898
2899 const connectionCheckHealth = (
2900 ref: ConnectionRef,
2901 options?: {
2902 /** Skip the probe and return the persisted verdict when it is younger
2903 * than this. The server owns the freshness decision so N open tabs
2904 * revalidating on load cannot stampede an upstream. Omit = always
2905 * probe (the manual "Check now"). */
2906 readonly ifStaleMs?: number;
2907 },
2908 ): Effect.Effect<
2909 HealthCheckResult,
2910 ConnectionNotFoundError | IntegrationNotFoundError | StorageFailure
2911 > =>
2912 Effect.gen(function* () {
2913 const connectionRow = yield* findConnectionRow(ref);
2914 if (!connectionRow) {
2915 return yield* new ConnectionNotFoundError({
2916 owner: ref.owner,
2917 integration: ref.integration,
2918 name: ref.name,
2919 });
2920 }
2921 if (options?.ifStaleMs !== undefined) {
2922 const cached = Option.getOrNull(decodeLastHealth(connectionRow.last_health));
2923 if (cached && Date.now() - cached.checkedAt < options.ifStaleMs) return cached;
2924 }
2925 const integrationRow = yield* findIntegrationRow(ref.integration);
2926 if (!integrationRow) {
2927 return yield* new IntegrationNotFoundError({ slug: ref.integration });
2928 }
2929 const runtime = runtimes.get(integrationRow.plugin_id);
2930 const check = runtime?.plugin.checkHealth;
2931 if (!runtime || !check) return unknownHealth();
2932 const spec = describeHealthCheckForRow(integrationRow) ?? undefined;
2933 if (spec === undefined && connectionRow.oauth_client != null) {
2934 const result = yield* oauthCredentialHealthWithoutProbe(connectionRow);
2935 yield* persistHealthResult(ref, result);
2936 return result;
2937 }
2938
2939 const result = yield* Effect.gen(function* () {
2940 const values = yield* resolveConnectionValues(connectionRow);
2941 const record = rowToIntegrationRecord(
2942 integrationRow,
2943 describeAuthMethodsForRow(integrationRow),
2944 );
2945 const grantedScopes = grantedScopesFromRow(connectionRow);
2946 const credential: ToolInvocationCredential = {
2947 owner: connectionRow.owner as Owner,
2948 integration: ref.integration,
2949 connection: ConnectionName.make(connectionRow.name),
2950 template: AuthTemplateSlug.make(connectionRow.template),
2951 value: values[PRIMARY_INPUT_VARIABLE] ?? null,
2952 values,
2953 config: record.config,
2954 ...(grantedScopes ? { grantedScopes } : {}),
2955 };
2956 // Core resolves the declared spec (its own column) and hands it to the

Callers

nothing calls this directly

Calls 13

findConnectionRowFunction · 0.85
findIntegrationRowFunction · 0.85
unknownHealthFunction · 0.85
persistHealthResultFunction · 0.85
resolveConnectionValuesFunction · 0.85
rowToIntegrationRecordFunction · 0.85
grantedScopesFromRowFunction · 0.85
foldPluginFailureFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected