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

Function healPersistedHealthOnUse

packages/core/sdk/src/executor.ts:4966–5007  ·  view source on GitHub ↗
(
      row: ConnectionRow,
      result: unknown,
      values: Record<string, string | null>,
    )

Source from the content-addressed store, hash-verified

4964 * stamp and the heal is a silent no-op. Any newer write is newer
4965 * evidence than this invocation. */
4966 const healPersistedHealthOnUse = (
4967 row: ConnectionRow,
4968 result: unknown,
4969 values: Record<string, string | null>,
4970 ): Effect.Effect<void> =>
4971 Effect.suspend(() => {
4972 if (isToolResult(result) && !result.ok) return Effect.void;
4973 if (Object.values(values).some((value) => value == null)) return Effect.void;
4974 const observed = Option.getOrNull(decodeLastHealth(row.last_health));
4975 if (observed === null || observed.status === "healthy" || observed.status === "unknown") {
4976 return Effect.void;
4977 }
4978 if (isToolSyncHealth(observed)) return Effect.void;
4979 if (oauthReauthRequiredFromProviderState(row.provider_state) !== null) return Effect.void;
4980 const ref: ConnectionRef = {
4981 owner: row.owner as Owner,
4982 integration: IntegrationSlug.make(row.integration),
4983 name: ConnectionName.make(row.name),
4984 };
4985 return findConnectionRow(ref).pipe(
4986 Effect.flatMap((fresh) => {
4987 if (fresh === null) return Effect.void;
4988 if (oauthReauthRequiredFromProviderState(fresh.provider_state) !== null) {
4989 return Effect.void;
4990 }
4991 const current = Option.getOrNull(decodeLastHealth(fresh.last_health));
4992 if (
4993 current === null ||
4994 current.status !== observed.status ||
4995 current.checkedAt !== observed.checkedAt
4996 ) {
4997 return Effect.void;
4998 }
4999 return persistHealthResult(ref, fresh, {
5000 status: "healthy",
5001 checkedAt: Date.now(),
5002 detail: "Tool invocation succeeded.",
5003 });
5004 }),
5005 Effect.ignore,
5006 );
5007 });
5008
5009 const healthFromCredentialResolutionFailure = (
5010 failure: CredentialResolutionError,

Callers 1

executeFunction · 0.85

Calls 6

isToolResultFunction · 0.90
isToolSyncHealthFunction · 0.90
findConnectionRowFunction · 0.85
persistHealthResultFunction · 0.85
valuesMethod · 0.80

Tested by

no test coverage detected