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

Function healPersistedHealthOnUse

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

Source from the content-addressed store, hash-verified

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