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

Function connectionCheckHealth

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

2814 });
2815
2816 const connectionCheckHealth = (
2817 ref: ConnectionRef,
2818 options?: {
2819 /** Skip the probe and return the persisted verdict when it is younger
2820 * than this. The server owns the freshness decision so N open tabs
2821 * revalidating on load cannot stampede an upstream. Omit = always
2822 * probe (the manual "Check now"). */
2823 readonly ifStaleMs?: number;
2824 },
2825 ): Effect.Effect<
2826 HealthCheckResult,
2827 ConnectionNotFoundError | IntegrationNotFoundError | StorageFailure
2828 > =>
2829 Effect.gen(function* () {
2830 const connectionRow = yield* findConnectionRow(ref);
2831 if (!connectionRow) {
2832 return yield* new ConnectionNotFoundError({
2833 owner: ref.owner,
2834 integration: ref.integration,
2835 name: ref.name,
2836 });
2837 }
2838 if (options?.ifStaleMs !== undefined) {
2839 const cached = Option.getOrNull(decodeLastHealth(connectionRow.last_health));
2840 if (cached && Date.now() - cached.checkedAt < options.ifStaleMs) return cached;
2841 }
2842 const integrationRow = yield* findIntegrationRow(ref.integration);
2843 if (!integrationRow) {
2844 return yield* new IntegrationNotFoundError({ slug: ref.integration });
2845 }
2846 const runtime = runtimes.get(integrationRow.plugin_id);
2847 const check = runtime?.plugin.checkHealth;
2848 if (!runtime || !check) return unknownHealth();
2849 const spec = describeHealthCheckForRow(integrationRow) ?? undefined;
2850 if (spec === undefined && connectionRow.oauth_client != null) {
2851 const result = yield* oauthCredentialHealthWithoutProbe(connectionRow);
2852 yield* persistHealthResult(ref, result);
2853 return result;
2854 }
2855
2856 const result = yield* Effect.gen(function* () {
2857 const values = yield* resolveConnectionValues(connectionRow);
2858 const record = rowToIntegrationRecord(
2859 integrationRow,
2860 describeAuthMethodsForRow(integrationRow),
2861 );
2862 const grantedScopes = grantedScopesFromRow(connectionRow);
2863 const credential: ToolInvocationCredential = {
2864 owner: connectionRow.owner as Owner,
2865 integration: ref.integration,
2866 connection: ConnectionName.make(connectionRow.name),
2867 template: AuthTemplateSlug.make(connectionRow.template),
2868 value: values[PRIMARY_INPUT_VARIABLE] ?? null,
2869 values,
2870 config: record.config,
2871 ...(grantedScopes ? { grantedScopes } : {}),
2872 };
2873 // 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