{"version":3,"file":"index.cjs","names":["n","e","n","e"],"sources":["../../../twenty-shared/dist/isDefined-Dtu5EYqP.mjs","../../../twenty-shared/dist/logic-function.mjs","../../src/sdk/logic-function/connections/errors/app-connection-auth-failed.error.ts","../../../twenty-shared/dist/application-runtime.mjs","../../src/sdk/logic-function/connections/utils/with-legacy-connection-visibility.util.ts","../../src/sdk/utils/get-application-access-token.ts","../../src/sdk/logic-function/utils/post-graphql-request.util.ts","../../src/sdk/logic-function/connections/get-connection.ts","../../../twenty-shared/dist/get-ai-model-tier-from-model-id.util-C26DZ9rM.mjs","../../../twenty-shared/dist/capitalize-DFPVt1IM.mjs","../../src/sdk/logic-function/connections/list-connections.ts","../../src/sdk/logic-function/connections/find-connection-for-request.ts","../../src/sdk/logic-function/connections/report-connection-auth-failure.ts","../../src/sdk/logic-function/messaging/message-channel-fields.constant.ts","../../src/sdk/logic-function/messaging/create-message-channel.ts","../../src/sdk/logic-function/messaging/list-message-channels.ts","../../src/sdk/logic-function/messaging/update-message-channel.ts","../../src/sdk/logic-function/messaging/delete-message-channel.ts","../../src/sdk/logic-function/messaging/ingest-messages.ts","../../src/sdk/logic-function/messaging/message-folder-fields.constant.ts","../../src/sdk/logic-function/messaging/list-message-folders.ts","../../src/sdk/logic-function/messaging/sync-message-folders.ts","../../src/sdk/logic-function/agents/run-agent.ts","../../src/sdk/inbox/send-inbox-message.ts","../../src/sdk/inbox/mentions/utils/sanitize-inbox-reference-label.util.ts","../../src/sdk/inbox/mentions/inbox-mention.ts","../../src/sdk/inbox/mentions/utils/compute-inbox-record-label.util.ts","../../src/sdk/inbox/mentions/utils/find-inbox-label-identifier-field.util.ts","../../src/sdk/inbox/mentions/utils/find-inbox-object-metadata-or-throw.util.ts","../../src/sdk/inbox/mentions/inbox-reference-record.ts","../../src/sdk/inbox/mentions/inbox-assistant-mention.ts","../../src/sdk/logic-function/jobs/enqueue-job.ts","../../src/sdk/logic-function/jobs/enqueue-jobs.ts","../../src/sdk/logic-function/jobs/get-jobs.ts","../../src/sdk/logic-function/timeline/create-timeline-activity.ts","../../src/sdk/logic-function/key-value/kv.ts","../../src/sdk/logic-function/response.ts"],"sourcesContent":["import { isNull as e, isUndefined as t } from \"@sniptt/guards\";\n//#region src/utils/validation/isDefined.ts\nvar n = (n) => !t(n) && !e(n);\n//#endregion\nexport { n as t };\n","import { t as e } from \"./isDefined-Dtu5EYqP.mjs\";\nimport { t } from \"./is-record-object-schema-CwzshFdt.mjs\";\nimport { isNonEmptyString as n, isObject as r } from \"@sniptt/guards\";\n//#region src/logic-function/build-tool-input-json-schema.ts\nvar i = (e, t) => {\n\tlet r = n(e) ? t?.(e) : void 0;\n\treturn `Id of the ${n(r) ? r : \"linked\"} record`;\n}, a = (n, o) => {\n\tif (t(n)) return {\n\t\ttype: \"string\",\n\t\tdescription: i(n.objectUniversalIdentifier, o)\n\t};\n\tif (n.type === \"records\") return {\n\t\ttype: \"array\",\n\t\titems: {\n\t\t\ttype: \"string\",\n\t\t\tdescription: i(n.objectUniversalIdentifier, o)\n\t\t}\n\t};\n\tlet { objectUniversalIdentifier: s, multiline: c, label: l, items: u, properties: d, additionalProperties: f, ...p } = n, m = { ...p };\n\treturn e(u) && (m.items = a(u, o)), e(d) && (m.properties = Object.fromEntries(Object.entries(d).map(([e, t]) => [e, a(t, o)]))), e(f) && (m.additionalProperties = r(f) ? a(f, o) : f), m;\n}, o = {\n\ttype: \"object\",\n\tproperties: {}\n}, s = (e) => {\n\tlet t = { type: \"unknown\" };\n\tswitch (e.type) {\n\t\tcase \"string\":\n\t\t\tt.type = \"string\";\n\t\t\tbreak;\n\t\tcase \"number\":\n\t\tcase \"integer\":\n\t\t\tt.type = \"number\";\n\t\t\tbreak;\n\t\tcase \"boolean\":\n\t\t\tt.type = \"boolean\";\n\t\t\tbreak;\n\t\tcase \"array\":\n\t\t\tt.type = \"array\", e.items && (t.items = s(e.items));\n\t\t\tbreak;\n\t\tcase \"object\":\n\t\t\tt.type = \"object\", e.properties && (t.properties = Object.fromEntries(Object.entries(e.properties).map(([e, t]) => [e, s(t)])));\n\t\t\tbreak;\n\t\tcase \"record\":\n\t\t\tt.type = \"record\";\n\t\t\tbreak;\n\t\tcase \"records\":\n\t\t\tt.type = \"records\";\n\t\t\tbreak;\n\t\tdefault: t.type = \"unknown\";\n\t}\n\treturn Array.isArray(e.enum) && (t.enum = e.enum.filter((e) => typeof e == \"string\")), e.multiline === !0 && (t.multiline = !0), n(e.label) && (t.label = e.label), n(e.objectUniversalIdentifier) && (t.objectUniversalIdentifier = e.objectUniversalIdentifier), t;\n}, c = (e) => [s(e)], l = { inputSchema: c({\n\ttype: \"object\",\n\tproperties: {\n\t\ta: { type: \"string\" },\n\t\tb: { type: \"number\" }\n\t}\n}) }, u = async (t) => {\n\tlet { getFunctionInputSchema: n } = await import(\"./get-function-input-schema-GNk3NRLJ.mjs\"), r = n(t)[0];\n\treturn r?.type === \"object\" && e(r.properties) ? {\n\t\ttype: \"object\",\n\t\tproperties: r.properties\n\t} : o;\n}, d = (t) => !e(t) || t === null ? \"unknown\" : typeof t == \"string\" ? \"string\" : typeof t == \"number\" ? \"number\" : typeof t == \"boolean\" ? \"boolean\" : Array.isArray(t) ? \"array\" : \"unknown\", f = (e) => e ? Object.entries(e).reduce((e, [t, n]) => (r(n) && !Array.isArray(n) ? e[t] = {\n\tisLeaf: !1,\n\ttype: \"object\",\n\tlabel: t,\n\tvalue: f(n)\n} : e[t] = {\n\tisLeaf: !0,\n\tvalue: n,\n\ttype: d(n),\n\tlabel: t\n}, e), {}) : {}, p = (e, t) => e ? `${e}.${t}` : t, m = (t, n, r = \"\") => {\n\tlet i = [];\n\tfor (let [a, o] of Object.entries(n)) {\n\t\tlet n = p(r, a), s = t[a];\n\t\tif (!e(s)) {\n\t\t\ti.push(`Missing key \"${n}\" in declared output schema.`);\n\t\t\tcontinue;\n\t\t}\n\t\tif (o.isLeaf !== s.isLeaf) {\n\t\t\ti.push(`Type mismatch at \"${n}\": expected ${o.isLeaf ? o.type : \"object\"} but declared ${s.isLeaf ? s.type : \"object\"}.`);\n\t\t\tcontinue;\n\t\t}\n\t\tif (!o.isLeaf && !s.isLeaf) {\n\t\t\ti.push(...m(s.value, o.value, n));\n\t\t\tcontinue;\n\t\t}\n\t\to.isLeaf && s.isLeaf && o.type !== \"unknown\" && s.type !== \"unknown\" && o.type !== s.type && i.push(`Type mismatch at \"${n}\": expected ${o.type} but declared ${s.type}.`);\n\t}\n\treturn i;\n}, h = [\n\t\"string\",\n\t\"number\",\n\t\"boolean\",\n\t\"array\",\n\t\"unknown\"\n], g = (e) => h.includes(e), _ = (e, t) => {\n\tlet n = t.label ?? e;\n\treturn t.type === \"record\" ? {\n\t\tisLeaf: !0,\n\t\ttype: \"string\",\n\t\tlabel: n,\n\t\tvalue: null\n\t} : t.type === \"records\" ? {\n\t\tisLeaf: !0,\n\t\ttype: \"array\",\n\t\tlabel: n,\n\t\tvalue: null\n\t} : t.type === \"object\" ? {\n\t\tisLeaf: !1,\n\t\ttype: \"object\",\n\t\tlabel: n,\n\t\tvalue: r(t.properties) ? v(t.properties) : {}\n\t} : {\n\t\tisLeaf: !0,\n\t\ttype: g(t.type) ? t.type : \"unknown\",\n\t\tlabel: n,\n\t\tvalue: null\n\t};\n}, v = (e) => Object.entries(e).reduce((e, [t, n]) => (e[t] = _(t, n), e), {}), y = (e) => {\n\tlet t = e[0];\n\treturn t?.type !== \"object\" || !r(t.properties) ? {} : v(t.properties);\n}, b = (e) => e?.type === \"records\" && n(e.objectUniversalIdentifier) || e?.type === \"array\" && t(e?.items), x = \"RetryableLogicFunctionError\", S = class extends Error {\n\tconstructor(e) {\n\t\tsuper(e), this.name = x;\n\t}\n};\n//#endregion\nexport { o as DEFAULT_TOOL_INPUT_SCHEMA, x as RETRYABLE_LOGIC_FUNCTION_ERROR_NAME, S as RetryableLogicFunctionError, l as SEED_WORKFLOW_ACTION_TRIGGER_SETTINGS, a as buildToolInputJsonSchema, u as getInputSchemaFromSourceCode, f as getOutputSchemaFromValue, m as getOutputSchemaMismatchIssues, y as inputSchemaToOutputSchema, b as isRecordArraySchema, t as isRecordObjectSchema, c as jsonSchemaToInputSchema };\n","// Thrown when the platform asks the SDK to operate on a connection whose\n// OAuth refresh failed permanently (`authFailedAt` is set). The end user\n// must reconnect from the app's settings tab — the app cannot recover on\n// its own.\n//\n// `listConnections` filters these out by default (the user can't act on\n// them anyway). `getConnection` throws this when the looked-up connection\n// is in this state, so a stored connection id can be safely retried until\n// it works again.\nexport class AppConnectionAuthFailedError extends Error {\n  readonly connectionId: string;\n\n  constructor(connectionId: string) {\n    super(\n      `App connection ${connectionId} requires the user to reconnect ` +\n        `(authFailedAt is set). Surface a \"Reconnect\" prompt in your UI.`,\n    );\n    this.name = 'AppConnectionAuthFailedError';\n    this.connectionId = connectionId;\n  }\n}\n","//#region src/application-runtime/constants/ConnectionScopeByLegacyVisibility.ts\nvar e = {\n\tuser: \"USER\",\n\tworkspace: \"WORKSPACE\"\n}, t = \"TWENTY_API_KEY\", n = \"TWENTY_API_URL\", r = \"TWENTY_APP_ACCESS_TOKEN\", i = \"TWENTY_APP_APPLICATION_ACCESS_TOKEN\", a = \"TWENTY_FUNCTIONS_URL\", o = {\n\tUSER: \"user\",\n\tWORKSPACE: \"workspace\"\n}, s = [\n\t\"workspace-suspended\",\n\t\"no-subscription\",\n\t\"no-credits\"\n];\n//#endregion\nexport { e as CONNECTION_SCOPE_BY_LEGACY_VISIBILITY, s as CREDIT_UNAVAILABLE_REASONS, t as DEFAULT_API_KEY_NAME, n as DEFAULT_API_URL_NAME, r as DEFAULT_APP_ACCESS_TOKEN_NAME, i as DEFAULT_APP_APPLICATION_ACCESS_TOKEN_NAME, a as DEFAULT_FUNCTIONS_URL_NAME, o as LEGACY_CONNECTION_VISIBILITY_BY_SCOPE };\n","import { LEGACY_CONNECTION_VISIBILITY_BY_SCOPE } from 'twenty-shared/application-runtime';\n\nimport { type AppConnection } from '@/sdk/logic-function/connections/types/app-connection.type';\n\ntype WithoutVisibility<TConnection> = TConnection extends unknown\n  ? Omit<TConnection, 'visibility'>\n  : never;\n\nexport type AppConnectionWithoutVisibility = WithoutVisibility<AppConnection>;\n\nexport const withLegacyConnectionVisibility = (\n  connection: AppConnectionWithoutVisibility,\n): AppConnection => ({\n  ...connection,\n  visibility: LEGACY_CONNECTION_VISIBILITY_BY_SCOPE[connection.scope],\n});\n","import {\n  DEFAULT_APP_ACCESS_TOKEN_NAME,\n  DEFAULT_APP_APPLICATION_ACCESS_TOKEN_NAME,\n} from 'twenty-shared/application-runtime';\n\n// These reach the application's own resources, so prefer the application token when the runtime injects one\nexport const getApplicationAccessToken = (): string | undefined =>\n  process.env[DEFAULT_APP_APPLICATION_ACCESS_TOKEN_NAME] ??\n  process.env[DEFAULT_APP_ACCESS_TOKEN_NAME];\n","import {\n  DEFAULT_API_URL_NAME,\n  DEFAULT_APP_APPLICATION_ACCESS_TOKEN_NAME,\n} from 'twenty-shared/application-runtime';\n\nimport { getApplicationAccessToken } from '@/sdk/utils/get-application-access-token';\n\nexport const postGraphqlRequest = async <TVariables, TData>({\n  query,\n  variables,\n  caller,\n}: {\n  query: string;\n  variables: TVariables;\n  caller: string;\n}): Promise<TData> => {\n  const apiUrl = process.env[DEFAULT_API_URL_NAME];\n  const accessToken = getApplicationAccessToken();\n\n  if (!apiUrl || !accessToken) {\n    throw new Error(\n      `${caller}() requires the app runtime env vars ` +\n        `${DEFAULT_API_URL_NAME} and ${DEFAULT_APP_APPLICATION_ACCESS_TOKEN_NAME}.`,\n    );\n  }\n\n  const response = await fetch(`${apiUrl}/metadata`, {\n    method: 'POST',\n    headers: {\n      'Content-Type': 'application/json',\n      Authorization: `Bearer ${accessToken}`,\n    },\n    body: JSON.stringify({ query, variables }),\n  });\n\n  if (!response.ok) {\n    throw new Error(\n      `${caller}() failed: HTTP ${response.status} ${response.statusText}`,\n    );\n  }\n\n  const body = (await response.json()) as {\n    data?: TData;\n    errors?: { message: string }[];\n  };\n\n  if (body.errors && body.errors.length > 0) {\n    throw new Error(\n      `${caller}() failed: ${body.errors.map((error) => error.message).join(', ')}`,\n    );\n  }\n\n  if (!body.data) {\n    throw new Error(`${caller}() failed: response contained no data.`);\n  }\n\n  return body.data;\n};\n","import { AppConnectionAuthFailedError } from '@/sdk/logic-function/connections/errors/app-connection-auth-failed.error';\nimport { type AppConnection } from '@/sdk/logic-function/connections/types/app-connection.type';\nimport {\n  type AppConnectionWithoutVisibility,\n  withLegacyConnectionVisibility,\n} from '@/sdk/logic-function/connections/utils/with-legacy-connection-visibility.util';\nimport { postGraphqlRequest } from '@/sdk/logic-function/utils/post-graphql-request.util';\n\nconst GET_APP_CONNECTION_QUERY = `\n  query GetAppConnection($id: ID!) {\n    appConnection(id: $id) {\n      id\n      providerName\n      name\n      handle\n      externalAccountId\n      scope\n      userWorkspaceId\n      workspaceMemberId\n      providerType\n      accessToken\n      scopes\n      authFailedAt\n      authFailedReason\n    }\n  }\n`;\n\nexport const getConnection = async (id: string): Promise<AppConnection> => {\n  const { appConnection } = await postGraphqlRequest<\n    { id: string },\n    { appConnection: AppConnectionWithoutVisibility }\n  >({\n    query: GET_APP_CONNECTION_QUERY,\n    variables: { id },\n    caller: 'getConnection',\n  });\n\n  if (appConnection.authFailedAt !== null) {\n    throw new AppConnectionAuthFailedError(appConnection.id);\n  }\n\n  return withLegacyConnectionVisibility(appConnection);\n};\n","//#region src/ai/constants/agent-chat-assistant-mention-object-name-singular.const.ts\nvar e = \"agentChatAssistant\", t = [\n\t\"extraFast\",\n\t\"fast\",\n\t\"balanced\",\n\t\"smart\",\n\t\"extraSmart\"\n], n = {\n\textraFast: \"default-extra-fast-model\",\n\tfast: \"default-fast-model\",\n\tbalanced: \"default-balanced-model\",\n\tsmart: \"default-smart-model\",\n\textraSmart: \"default-extra-smart-model\"\n}, r = \"workspace-default-model\", i = (e) => /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(e), a = ({ objectNameSingular: e, recordId: t, displayName: n }) => e === \"agentChatAssistant\" ? `@${n}` : `[[record:${e}:${t}:${n}]]`, o = ({ skillId: e, label: t }) => `[[skill:${e}:${t}]]`, s = (e) => t.find((t) => n[t] === e);\n//#endregion\nexport { r as a, e as c, i, o as n, n as o, a as r, t as s, s as t };\n","import { isNonEmptyString as e } from \"@sniptt/guards\";\n//#region src/i18n/do-not-translate.ts\nvar t = (e) => e, n = (t) => e(t) ? t.charAt(0).toUpperCase() + t.slice(1) : \"\";\n//#endregion\nexport { t as n, n as t };\n","import { CONNECTION_SCOPE_BY_LEGACY_VISIBILITY } from 'twenty-shared/application-runtime';\nimport { isDefined } from 'twenty-shared/utils';\n\nimport { type AppConnection } from '@/sdk/logic-function/connections/types/app-connection.type';\nimport {\n  type AppConnectionWithoutVisibility,\n  withLegacyConnectionVisibility,\n} from '@/sdk/logic-function/connections/utils/with-legacy-connection-visibility.util';\nimport { postGraphqlRequest } from '@/sdk/logic-function/utils/post-graphql-request.util';\n\nconst LIST_APP_CONNECTIONS_QUERY = `\n  query ListAppConnections($filter: ListAppConnectionsInput) {\n    appConnections(filter: $filter) {\n      id\n      providerName\n      name\n      handle\n      externalAccountId\n      scope\n      userWorkspaceId\n      workspaceMemberId\n      providerType\n      accessToken\n      scopes\n      authFailedAt\n      authFailedReason\n    }\n  }\n`;\n\nexport type ListConnectionsFilter = {\n  providerName?: string;\n  userWorkspaceId?: string;\n  scope?: AppConnection['scope'];\n  /** @deprecated Use `scope` instead. */\n  visibility?: AppConnection['visibility'];\n};\n\nexport const listConnections = async ({\n  visibility,\n  ...filter\n}: ListConnectionsFilter = {}): Promise<AppConnection[]> => {\n  const { appConnections } = await postGraphqlRequest<\n    { filter: Omit<ListConnectionsFilter, 'visibility'> },\n    { appConnections: AppConnectionWithoutVisibility[] }\n  >({\n    query: LIST_APP_CONNECTIONS_QUERY,\n    variables: {\n      filter: {\n        ...filter,\n        scope:\n          filter.scope ??\n          (isDefined(visibility)\n            ? CONNECTION_SCOPE_BY_LEGACY_VISIBILITY[visibility]\n            : undefined),\n      },\n    },\n    caller: 'listConnections',\n  });\n\n  return appConnections.map(withLegacyConnectionVisibility);\n};\n","import { type AppConnection } from '@/sdk/logic-function/connections/types/app-connection.type';\n\nexport const findConnectionForRequest = (\n  connections: AppConnection[],\n  event: { userWorkspaceId: string | null },\n): AppConnection | null => {\n  if (event.userWorkspaceId !== null) {\n    const personal = connections.find(\n      (connection) =>\n        connection.scope === 'USER' &&\n        connection.userWorkspaceId === event.userWorkspaceId,\n    );\n\n    if (personal) {\n      return personal;\n    }\n  }\n\n  const workspaceShared = connections.find(\n    (connection) => connection.scope === 'WORKSPACE',\n  );\n\n  return workspaceShared ?? null;\n};\n","import { postGraphqlRequest } from '@/sdk/logic-function/utils/post-graphql-request.util';\n\nconst REPORT_APP_CONNECTION_AUTH_FAILURE_MUTATION = `\n  mutation ReportAppConnectionAuthFailure($input: ReportAppConnectionAuthFailureInput!) {\n    reportAppConnectionAuthFailure(input: $input)\n  }\n`;\n\nexport const reportConnectionAuthFailure = async ({\n  connectionId,\n  reason,\n}: {\n  connectionId: string;\n  reason?: string;\n}): Promise<void> => {\n  await postGraphqlRequest<\n    { input: { id: string; reason?: string } },\n    { reportAppConnectionAuthFailure: boolean }\n  >({\n    query: REPORT_APP_CONNECTION_AUTH_FAILURE_MUTATION,\n    variables: { input: { id: connectionId, reason } },\n    caller: 'reportConnectionAuthFailure',\n  });\n};\n","// Shared by every helper, so channels returned by any of them are interchangeable\nexport const APP_MESSAGE_CHANNEL_SELECTION = `\n  id\n  handle\n  displayName\n  visibility\n  connectedAccountId\n  isSyncEnabled\n  participantHandleFieldUniversalIdentifier\n  messagingProviderUniversalIdentifier\n`;\n","import { type MessageChannelVisibility } from '@/sdk/define/common/types/loose-shared-types.type';\nimport { APP_MESSAGE_CHANNEL_SELECTION } from '@/sdk/logic-function/messaging/message-channel-fields.constant';\nimport { type AppMessageChannel } from '@/sdk/logic-function/messaging/types/app-message-channel.type';\nimport { postGraphqlRequest } from '@/sdk/logic-function/utils/post-graphql-request.util';\n\nconst CREATE_APP_MESSAGE_CHANNEL_MUTATION = `\n  mutation CreateAppMessageChannel($input: CreateAppMessageChannelInput!) {\n    createAppMessageChannel(input: $input) {\n      ${APP_MESSAGE_CHANNEL_SELECTION}\n    }\n  }\n`;\n\nexport type CreateMessageChannelInput = {\n  // An app connection id (from getConnection/listConnections); the channel speaks through it and inherits who may see it\n  connectedAccountId: string;\n  // The account's provider identity; inbound participants matching it are treated as the account itself\n  handle: string;\n  displayName?: string;\n  // Required: decides whether one member's conversations are readable by the whole workspace, and only the app\n  // knows how private its messages are ('METADATA' for personal inboxes, 'SHARE_EVERYTHING' for shared ones)\n  visibility: MessageChannelVisibility;\n  // Person field to match participant handles against (handles are then stored in its canonical form); set once\n  participantHandleFieldUniversalIdentifier?: string;\n  messagingProvider?: { universalIdentifier: string };\n};\n\nexport const createMessageChannel = async ({\n  messagingProvider,\n  ...input\n}: CreateMessageChannelInput): Promise<AppMessageChannel> => {\n  const { createAppMessageChannel } = await postGraphqlRequest<\n    {\n      input: Omit<CreateMessageChannelInput, 'messagingProvider'> & {\n        messagingProviderUniversalIdentifier?: string;\n      };\n    },\n    { createAppMessageChannel: AppMessageChannel }\n  >({\n    query: CREATE_APP_MESSAGE_CHANNEL_MUTATION,\n    variables: {\n      input: {\n        ...input,\n        messagingProviderUniversalIdentifier:\n          messagingProvider?.universalIdentifier,\n      },\n    },\n    caller: 'createMessageChannel',\n  });\n\n  return createAppMessageChannel;\n};\n","import { APP_MESSAGE_CHANNEL_SELECTION } from '@/sdk/logic-function/messaging/message-channel-fields.constant';\nimport { type AppMessageChannel } from '@/sdk/logic-function/messaging/types/app-message-channel.type';\nimport { postGraphqlRequest } from '@/sdk/logic-function/utils/post-graphql-request.util';\n\nconst LIST_APP_MESSAGE_CHANNELS_QUERY = `\n  query ListAppMessageChannels($filter: ListAppMessageChannelsInput) {\n    appMessageChannels(filter: $filter) {\n      ${APP_MESSAGE_CHANNEL_SELECTION}\n    }\n  }\n`;\n\nexport type ListMessageChannelsFilter = {\n  connectedAccountId?: string;\n};\n\nexport const listMessageChannels = async (\n  filter: ListMessageChannelsFilter = {},\n): Promise<AppMessageChannel[]> => {\n  const { appMessageChannels } = await postGraphqlRequest<\n    { filter: ListMessageChannelsFilter },\n    { appMessageChannels: AppMessageChannel[] }\n  >({\n    query: LIST_APP_MESSAGE_CHANNELS_QUERY,\n    variables: { filter },\n    caller: 'listMessageChannels',\n  });\n\n  return appMessageChannels;\n};\n","import { type MessageChannelVisibility } from '@/sdk/define/common/types/loose-shared-types.type';\nimport { APP_MESSAGE_CHANNEL_SELECTION } from '@/sdk/logic-function/messaging/message-channel-fields.constant';\nimport { type AppMessageChannel } from '@/sdk/logic-function/messaging/types/app-message-channel.type';\nimport { postGraphqlRequest } from '@/sdk/logic-function/utils/post-graphql-request.util';\n\nconst UPDATE_APP_MESSAGE_CHANNEL_MUTATION = `\n  mutation UpdateAppMessageChannel($input: UpdateAppMessageChannelInput!) {\n    updateAppMessageChannel(input: $input) {\n      ${APP_MESSAGE_CHANNEL_SELECTION}\n    }\n  }\n`;\n\nexport type UpdateMessageChannelInput = {\n  id: string;\n  // Omitted leaves the current label untouched; null clears it.\n  displayName?: string | null;\n  // Changes who can read every message already ingested, not just the ones that follow\n  visibility?: MessageChannelVisibility;\n  // False pauses ingestion (further ingests are rejected) without deleting the history\n  isSyncEnabled?: boolean;\n  messagingProvider?: { universalIdentifier: string } | null;\n};\n\nexport const updateMessageChannel = async ({\n  messagingProvider,\n  ...input\n}: UpdateMessageChannelInput): Promise<AppMessageChannel> => {\n  const { updateAppMessageChannel } = await postGraphqlRequest<\n    {\n      input: Omit<UpdateMessageChannelInput, 'messagingProvider'> & {\n        messagingProviderUniversalIdentifier?: string | null;\n      };\n    },\n    { updateAppMessageChannel: AppMessageChannel }\n  >({\n    query: UPDATE_APP_MESSAGE_CHANNEL_MUTATION,\n    variables: {\n      input: {\n        ...input,\n        messagingProviderUniversalIdentifier:\n          messagingProvider === undefined\n            ? undefined\n            : (messagingProvider?.universalIdentifier ?? null),\n      },\n    },\n    caller: 'updateMessageChannel',\n  });\n\n  return updateAppMessageChannel;\n};\n","import { APP_MESSAGE_CHANNEL_SELECTION } from '@/sdk/logic-function/messaging/message-channel-fields.constant';\nimport { type AppMessageChannel } from '@/sdk/logic-function/messaging/types/app-message-channel.type';\nimport { postGraphqlRequest } from '@/sdk/logic-function/utils/post-graphql-request.util';\n\nconst DELETE_APP_MESSAGE_CHANNEL_MUTATION = `\n  mutation DeleteAppMessageChannel($id: UUID!) {\n    deleteAppMessageChannel(id: $id) {\n      ${APP_MESSAGE_CHANNEL_SELECTION}\n    }\n  }\n`;\n\n// Also deletes the channel's ingested messages and emptied threads; call from onDisconnect to retire a channel with its credential.\n// To stop ingesting but keep the history, set `isSyncEnabled` to false instead.\nexport const deleteMessageChannel = async (\n  id: string,\n): Promise<AppMessageChannel> => {\n  const { deleteAppMessageChannel } = await postGraphqlRequest<\n    { id: string },\n    { deleteAppMessageChannel: AppMessageChannel }\n  >({\n    query: DELETE_APP_MESSAGE_CHANNEL_MUTATION,\n    variables: { id },\n    caller: 'deleteMessageChannel',\n  });\n\n  return deleteAppMessageChannel;\n};\n","import {\n  type IngestMessage,\n  type IngestedMessage,\n} from '@/sdk/logic-function/messaging/types/ingest-message.type';\nimport { postGraphqlRequest } from '@/sdk/logic-function/utils/post-graphql-request.util';\n\nconst INGEST_APP_MESSAGES_MUTATION = `\n  mutation IngestAppMessages($input: IngestAppMessagesInput!) {\n    ingestAppMessages(input: $input) {\n      messages {\n        externalId\n        messageId\n        messageThreadId\n      }\n    }\n  }\n`;\n\n// Threading, dedup and privacy are handled server-side. At most 100 messages per call (one transaction\n// within one logic-function timeout), so page provider backfills\nexport const ingestMessages = async ({\n  messageChannelId,\n  messages,\n}: {\n  messageChannelId: string;\n  messages: IngestMessage[];\n}): Promise<IngestedMessage[]> => {\n  const { ingestAppMessages } = await postGraphqlRequest<\n    { input: { messageChannelId: string; messages: IngestMessage[] } },\n    { ingestAppMessages: { messages: IngestedMessage[] } }\n  >({\n    query: INGEST_APP_MESSAGES_MUTATION,\n    variables: { input: { messageChannelId, messages } },\n    caller: 'ingestMessages',\n  });\n\n  return ingestAppMessages.messages;\n};\n","export const APP_MESSAGE_FOLDER_SELECTION = `\n  id\n  externalId\n  name\n  isSynced\n  messageChannelId\n`;\n","import { APP_MESSAGE_FOLDER_SELECTION } from '@/sdk/logic-function/messaging/message-folder-fields.constant';\nimport { type AppMessageFolder } from '@/sdk/logic-function/messaging/types/app-message-folder.type';\nimport { postGraphqlRequest } from '@/sdk/logic-function/utils/post-graphql-request.util';\n\nconst LIST_APP_MESSAGE_FOLDERS_QUERY = `\n  query ListAppMessageFolders($filter: ListAppMessageFoldersInput) {\n    appMessageFolders(filter: $filter) {\n      ${APP_MESSAGE_FOLDER_SELECTION}\n    }\n  }\n`;\n\nexport type ListMessageFoldersFilter = {\n  messageChannelId?: string;\n};\n\nexport const listMessageFolders = async (\n  filter: ListMessageFoldersFilter = {},\n): Promise<AppMessageFolder[]> => {\n  const { appMessageFolders } = await postGraphqlRequest<\n    { filter: ListMessageFoldersFilter },\n    { appMessageFolders: AppMessageFolder[] }\n  >({\n    query: LIST_APP_MESSAGE_FOLDERS_QUERY,\n    variables: { filter },\n    caller: 'listMessageFolders',\n  });\n\n  return appMessageFolders;\n};\n","import { APP_MESSAGE_FOLDER_SELECTION } from '@/sdk/logic-function/messaging/message-folder-fields.constant';\nimport { type AppMessageFolder } from '@/sdk/logic-function/messaging/types/app-message-folder.type';\nimport { postGraphqlRequest } from '@/sdk/logic-function/utils/post-graphql-request.util';\n\nconst SYNC_APP_MESSAGE_FOLDERS_MUTATION = `\n  mutation SyncAppMessageFolders($input: SyncAppMessageFoldersInput!) {\n    syncAppMessageFolders(input: $input) {\n      ${APP_MESSAGE_FOLDER_SELECTION}\n    }\n  }\n`;\n\nexport type SyncMessageFoldersInput = {\n  messageChannelId: string;\n  folders: {\n    externalId: string;\n    name: string;\n    isSynced?: boolean;\n  }[];\n};\n\nexport const syncMessageFolders = async (\n  input: SyncMessageFoldersInput,\n): Promise<AppMessageFolder[]> => {\n  const { syncAppMessageFolders } = await postGraphqlRequest<\n    { input: SyncMessageFoldersInput },\n    { syncAppMessageFolders: AppMessageFolder[] }\n  >({\n    query: SYNC_APP_MESSAGE_FOLDERS_MUTATION,\n    variables: { input },\n    caller: 'syncMessageFolders',\n  });\n\n  return syncAppMessageFolders;\n};\n","import {\n  type RunAgentInput,\n  type RunAgentResult,\n} from 'twenty-shared/application';\nimport { isDefined } from 'twenty-shared/utils';\n\nimport { postGraphqlRequest } from '@/sdk/logic-function/utils/post-graphql-request.util';\n\nconst RUN_AGENT_MUTATION = `\n  mutation RunAgent($input: RunAgentInput!) {\n    runAgent(input: $input) {\n      threadId\n      status\n      result\n      error\n      success\n    }\n  }\n`;\n\nexport const runAgent = async ({\n  input,\n  ...rest\n}: RunAgentInput): Promise<RunAgentResult> => {\n  const variables = {\n    input: isDefined(input)\n      ? {\n          ...rest,\n          input:\n            typeof input === 'string'\n              ? [{ role: 'user', content: input }]\n              : input,\n        }\n      : rest,\n  };\n\n  const { runAgent: result } = await postGraphqlRequest<\n    typeof variables,\n    { runAgent: RunAgentResult }\n  >({\n    query: RUN_AGENT_MUTATION,\n    variables,\n    caller: 'runAgent',\n  });\n\n  return result;\n};\n","import { MetadataApiClient } from 'twenty-client-sdk/metadata';\nimport { type SendInboxMessageResult } from 'twenty-shared/application';\n\nimport { type SendInboxMessageInput } from '@/sdk/define/common/types/loose-shared-types.type';\n\nexport const sendInboxMessage = async (\n  input: SendInboxMessageInput,\n): Promise<SendInboxMessageResult> => {\n  const client = new MetadataApiClient();\n\n  const { sendInboxMessage: result } = await client.mutation({\n    sendInboxMessage: {\n      __args: { input },\n      threadId: true,\n    },\n  });\n\n  return result;\n};\n","const OPENING_BRACKET_PATTERN = /\\[/g;\nconst CLOSING_BRACKET_PATTERN = /\\]/g;\nconst LINE_BREAK_PATTERN = /\\r?\\n/g;\n\nexport const sanitizeInboxReferenceLabel = (label: string): string =>\n  label\n    .replace(OPENING_BRACKET_PATTERN, '(')\n    .replace(CLOSING_BRACKET_PATTERN, ')')\n    .replace(LINE_BREAK_PATTERN, ' ')\n    .trim();\n","import { isNonEmptyString } from '@sniptt/guards';\nimport { RestApiClient } from 'twenty-client-sdk/rest';\nimport { formatRecordReference } from 'twenty-shared/ai';\n\nimport { sanitizeInboxReferenceLabel } from '@/sdk/inbox/mentions/utils/sanitize-inbox-reference-label.util';\n\ntype WorkspaceMemberResponse = {\n  data: {\n    workspaceMember: {\n      name: { firstName: string | null; lastName: string | null };\n      userEmail: string;\n    };\n  };\n};\n\nexport const inboxMention = async ({\n  workspaceMemberId,\n}: {\n  workspaceMemberId: string;\n}): Promise<string> => {\n  const {\n    data: { workspaceMember },\n  } = await new RestApiClient().get<WorkspaceMemberResponse>(\n    `/rest/workspaceMembers/${workspaceMemberId}`,\n  );\n\n  const fullName =\n    `${workspaceMember.name.firstName ?? ''} ${workspaceMember.name.lastName ?? ''}`.trim();\n\n  return formatRecordReference({\n    objectNameSingular: 'workspaceMember',\n    recordId: workspaceMemberId,\n    displayName: sanitizeInboxReferenceLabel(\n      isNonEmptyString(fullName) ? fullName : workspaceMember.userEmail,\n    ),\n  });\n};\n","import { isObject, isString } from '@sniptt/guards';\nimport { isDefined } from 'twenty-shared/utils';\n\nimport { type InboxLabelIdentifierField } from '@/sdk/inbox/mentions/types/inbox-label-identifier-field.type';\n\nconst getFullNamePart = ({\n  fullName,\n  partName,\n}: {\n  fullName: unknown;\n  partName: 'firstName' | 'lastName';\n}): string => {\n  const part = isObject(fullName) ? Reflect.get(fullName, partName) : undefined;\n\n  return isString(part) ? part : '';\n};\n\nexport const computeInboxRecordLabel = ({\n  record,\n  recordId,\n  labelIdentifierField,\n}: {\n  record: Record<string, unknown>;\n  recordId: string;\n  labelIdentifierField: InboxLabelIdentifierField | undefined;\n}): string => {\n  if (!isDefined(labelIdentifierField)) {\n    return recordId;\n  }\n\n  const labelValue = record[labelIdentifierField.name];\n\n  if (labelIdentifierField.type === 'FULL_NAME') {\n    return `${getFullNamePart({ fullName: labelValue, partName: 'firstName' })} ${getFullNamePart({ fullName: labelValue, partName: 'lastName' })}`.trim();\n  }\n\n  return isDefined(labelValue) ? String(labelValue) : '';\n};\n","import { type MetadataApiClient } from 'twenty-client-sdk/metadata';\nimport { isDefined } from 'twenty-shared/utils';\n\nimport { type InboxLabelIdentifierField } from '@/sdk/inbox/mentions/types/inbox-label-identifier-field.type';\nimport { type InboxObjectMetadata } from '@/sdk/inbox/mentions/types/inbox-object-metadata.type';\n\nexport const findInboxLabelIdentifierField = async ({\n  metadataClient,\n  objectMetadata,\n}: {\n  metadataClient: MetadataApiClient;\n  objectMetadata: Pick<\n    InboxObjectMetadata,\n    'id' | 'labelIdentifierFieldMetadataId'\n  >;\n}): Promise<InboxLabelIdentifierField | undefined> => {\n  if (!isDefined(objectMetadata.labelIdentifierFieldMetadataId)) {\n    return undefined;\n  }\n\n  const { object } = await metadataClient.query({\n    object: {\n      __args: { id: objectMetadata.id },\n      fields: {\n        __args: {\n          filter: { id: { eq: objectMetadata.labelIdentifierFieldMetadataId } },\n          paging: { first: 1 },\n        },\n        edges: { node: { name: true, type: true } },\n      },\n    },\n  });\n\n  return object.fields.edges[0]?.node;\n};\n","import { type MetadataApiClient } from 'twenty-client-sdk/metadata';\nimport { isDefined } from 'twenty-shared/utils';\n\nimport { type InboxObjectMetadata } from '@/sdk/inbox/mentions/types/inbox-object-metadata.type';\n\nconst OBJECTS_PAGE_SIZE = 1000;\n\nexport const findInboxObjectMetadataOrThrow = async ({\n  metadataClient,\n  objectNameSingular,\n}: {\n  metadataClient: MetadataApiClient;\n  objectNameSingular: string;\n}): Promise<InboxObjectMetadata> => {\n  const { objects } = await metadataClient.query({\n    objects: {\n      __args: { filter: {}, paging: { first: OBJECTS_PAGE_SIZE } },\n      edges: {\n        node: {\n          id: true,\n          nameSingular: true,\n          namePlural: true,\n          labelIdentifierFieldMetadataId: true,\n        },\n      },\n    },\n  });\n\n  const objectMetadata = objects.edges.find(\n    ({ node }) => node.nameSingular === objectNameSingular,\n  )?.node;\n\n  if (!isDefined(objectMetadata)) {\n    throw new Error(`This workspace has no ${objectNameSingular} object.`);\n  }\n\n  return objectMetadata;\n};\n","import { MetadataApiClient } from 'twenty-client-sdk/metadata';\nimport { RestApiClient } from 'twenty-client-sdk/rest';\nimport { formatRecordReference } from 'twenty-shared/ai';\n\nimport { computeInboxRecordLabel } from '@/sdk/inbox/mentions/utils/compute-inbox-record-label.util';\nimport { findInboxLabelIdentifierField } from '@/sdk/inbox/mentions/utils/find-inbox-label-identifier-field.util';\nimport { findInboxObjectMetadataOrThrow } from '@/sdk/inbox/mentions/utils/find-inbox-object-metadata-or-throw.util';\nimport { sanitizeInboxReferenceLabel } from '@/sdk/inbox/mentions/utils/sanitize-inbox-reference-label.util';\n\nexport const inboxReferenceRecord = async ({\n  objectNameSingular,\n  recordId,\n}: {\n  objectNameSingular: string;\n  recordId: string;\n}): Promise<string> => {\n  const metadataClient = new MetadataApiClient();\n  const objectMetadata = await findInboxObjectMetadataOrThrow({\n    metadataClient,\n    objectNameSingular,\n  });\n\n  const [labelIdentifierField, recordResponse] = await Promise.all([\n    findInboxLabelIdentifierField({ metadataClient, objectMetadata }),\n    new RestApiClient().get<{\n      data: Record<string, Record<string, unknown>>;\n    }>(`/rest/${objectMetadata.namePlural}/${recordId}`),\n  ]);\n\n  return formatRecordReference({\n    objectNameSingular,\n    recordId,\n    displayName: sanitizeInboxReferenceLabel(\n      computeInboxRecordLabel({\n        record: recordResponse.data[objectNameSingular],\n        recordId,\n        labelIdentifierField,\n      }),\n    ),\n  });\n};\n","import {\n  AGENT_CHAT_ASSISTANT_MENTION_OBJECT_NAME_SINGULAR,\n  AGENT_CHAT_ASSISTANT_NAME,\n  formatRecordReference,\n} from 'twenty-shared/ai';\n\nexport const INBOX_ASSISTANT_MENTION = formatRecordReference({\n  objectNameSingular: AGENT_CHAT_ASSISTANT_MENTION_OBJECT_NAME_SINGULAR,\n  recordId: AGENT_CHAT_ASSISTANT_MENTION_OBJECT_NAME_SINGULAR,\n  displayName: AGENT_CHAT_ASSISTANT_NAME,\n});\n","import { MetadataApiClient } from 'twenty-client-sdk/metadata';\nimport {\n  type EnqueueJobInput,\n  type EnqueueJobResult,\n} from 'twenty-shared/application';\n\n/**\n * @deprecated Use `enqueueJobs` instead.\n */\nexport const enqueueJob = async (\n  input: EnqueueJobInput,\n): Promise<EnqueueJobResult> => {\n  const client = new MetadataApiClient();\n\n  const { enqueueJob: result } = await client.mutation({\n    enqueueJob: {\n      __args: { input },\n      enqueued: true,\n      logicFunctionUniversalIdentifier: true,\n      jobId: true,\n    },\n  });\n\n  return result;\n};\n","import { MetadataApiClient } from 'twenty-client-sdk/metadata';\nimport {\n  type EnqueueJobsInput,\n  type EnqueueJobsResult,\n} from 'twenty-shared/application';\n\nexport const enqueueJobs = async (\n  input: EnqueueJobsInput,\n): Promise<EnqueueJobsResult> => {\n  const client = new MetadataApiClient();\n\n  const { enqueueJobs: result } = await client.mutation({\n    enqueueJobs: {\n      __args: { input },\n      enqueued: true,\n      logicFunctionUniversalIdentifier: true,\n      enqueuedJobsCount: true,\n      jobIds: true,\n    },\n  });\n\n  return result;\n};\n","import { MetadataApiClient } from 'twenty-client-sdk/metadata';\nimport { type JobStatusResult } from 'twenty-shared/application';\n\nexport const getJobs = async (jobIds: string[]): Promise<JobStatusResult[]> => {\n  const client = new MetadataApiClient();\n\n  const { getJobs: result } = await client.query({\n    getJobs: {\n      __args: { jobIds },\n      jobId: true,\n      state: true,\n      attemptsMade: true,\n      failedReason: true,\n      enqueuedAt: true,\n      startedAt: true,\n      finishedAt: true,\n    },\n  });\n\n  return result;\n};\n","import { MetadataApiClient } from 'twenty-client-sdk/metadata';\nimport { RestApiClient } from 'twenty-client-sdk/rest';\nimport { capitalize, isDefined } from 'twenty-shared/utils';\nimport { type TimelineActivityTypeSnapshot } from 'twenty-shared/timeline';\n\ntype CreateTimelineActivityBaseInput = {\n  timelineActivityTypeUniversalIdentifier: string;\n  targetObjectUniversalIdentifier: string;\n  targetRecordId: string;\n  happensAt?: string;\n  properties?: Record<string, unknown>;\n};\n\ntype CreateTimelineActivityLinkedRecordInput =\n  | {\n      linkedRecordId: string;\n      linkedObjectMetadataUniversalIdentifier: string;\n    }\n  | {\n      linkedRecordId?: never;\n      linkedObjectMetadataUniversalIdentifier?: never;\n    };\n\nexport type CreateTimelineActivityInput = CreateTimelineActivityBaseInput &\n  CreateTimelineActivityLinkedRecordInput;\n\nexport type CreatedTimelineActivity = {\n  id: string;\n  timelineActivityTypeId: string;\n  timelineActivityTypeSnapshot: TimelineActivityTypeSnapshot;\n};\n\nconst getObjectMetadataSelection = (universalIdentifiers: string[]) => ({\n  __args: {\n    paging: {\n      first: universalIdentifiers.length,\n    },\n    filter: {\n      universalIdentifier: {\n        in: universalIdentifiers,\n      },\n    },\n  },\n  edges: {\n    node: {\n      id: true,\n      universalIdentifier: true,\n      nameSingular: true,\n    },\n  },\n});\n\n// Apps address manifest entities by universal identifier; the row stores the installation-specific metadata id\nexport const createTimelineActivity = async ({\n  timelineActivityTypeUniversalIdentifier,\n  targetObjectUniversalIdentifier,\n  linkedObjectMetadataUniversalIdentifier,\n  targetRecordId,\n  ...input\n}: CreateTimelineActivityInput): Promise<CreatedTimelineActivity> => {\n  const requiredObjectUniversalIdentifiers = [\n    ...new Set(\n      [\n        targetObjectUniversalIdentifier,\n        linkedObjectMetadataUniversalIdentifier,\n      ].filter(isDefined),\n    ),\n  ];\n  const metadataClient = new MetadataApiClient();\n  const { timelineActivityTypes, objects } = await metadataClient.query({\n    timelineActivityTypes: {\n      id: true,\n      universalIdentifier: true,\n      isActive: true,\n    },\n    objects: getObjectMetadataSelection(requiredObjectUniversalIdentifiers),\n  });\n\n  const timelineActivityType = timelineActivityTypes.find(\n    ({ universalIdentifier }) =>\n      universalIdentifier === timelineActivityTypeUniversalIdentifier,\n  );\n\n  if (!isDefined(timelineActivityType)) {\n    throw new Error(\n      `Timeline activity type ${timelineActivityTypeUniversalIdentifier} is not installed`,\n    );\n  }\n\n  if (!timelineActivityType.isActive) {\n    throw new Error(\n      `Timeline activity type ${timelineActivityTypeUniversalIdentifier} is inactive`,\n    );\n  }\n\n  const objectMetadataByUniversalIdentifier = new Map(\n    objects.edges.map(({ node }) => [node.universalIdentifier, node]),\n  );\n\n  const targetObject = objectMetadataByUniversalIdentifier.get(\n    targetObjectUniversalIdentifier,\n  );\n\n  if (!isDefined(targetObject)) {\n    throw new Error(\n      `Timeline activity target object ${targetObjectUniversalIdentifier} is not installed`,\n    );\n  }\n\n  const targetFieldName = `target${capitalize(targetObject.nameSingular)}Id`;\n  const linkedObject = isDefined(linkedObjectMetadataUniversalIdentifier)\n    ? objectMetadataByUniversalIdentifier.get(\n        linkedObjectMetadataUniversalIdentifier,\n      )\n    : undefined;\n\n  if (\n    isDefined(linkedObjectMetadataUniversalIdentifier) &&\n    !isDefined(linkedObject)\n  ) {\n    throw new Error(\n      `Timeline activity linked object ${linkedObjectMetadataUniversalIdentifier} is not installed`,\n    );\n  }\n\n  const response = await new RestApiClient().post<{\n    data: { createTimelineActivity: CreatedTimelineActivity };\n  }>('/rest/timelineActivities', {\n    ...input,\n    timelineActivityTypeId: timelineActivityType.id,\n    linkedObjectMetadataId: linkedObject?.id,\n    [targetFieldName]: targetRecordId,\n  });\n\n  return response.data.createTimelineActivity;\n};\n","import {\n  type AppKeyValue,\n  type AppKeyValueScope,\n} from 'twenty-shared/application';\n\nimport { postGraphqlRequest } from '@/sdk/logic-function/utils/post-graphql-request.util';\n\nconst GET_APP_KEY_VALUE_QUERY = `\n  query GetAppKeyValue($key: String!, $scope: AppKeyValueScope) {\n    appKeyValue(key: $key, scope: $scope) {\n      key\n      value\n      scope\n    }\n  }\n`;\n\nconst SET_APP_KEY_VALUE_MUTATION = `\n  mutation SetAppKeyValue($input: SetAppKeyValueInput!) {\n    setAppKeyValue(input: $input) {\n      key\n      value\n      scope\n    }\n  }\n`;\n\nconst DELETE_APP_KEY_VALUE_MUTATION = `\n  mutation DeleteAppKeyValue($key: String!, $scope: AppKeyValueScope) {\n    deleteAppKeyValue(key: $key, scope: $scope)\n  }\n`;\n\nconst DEFAULT_APP_KEY_VALUE_SCOPE: AppKeyValueScope = 'WORKSPACE';\n\ntype KvOptions = {\n  scope?: AppKeyValueScope;\n};\n\nexport const kv = {\n  async get<TValue = unknown>(\n    key: string,\n    options?: KvOptions,\n  ): Promise<TValue | null> {\n    const { appKeyValue } = await postGraphqlRequest<\n      { key: string; scope: AppKeyValueScope },\n      { appKeyValue: AppKeyValue | null }\n    >({\n      query: GET_APP_KEY_VALUE_QUERY,\n      variables: { key, scope: options?.scope ?? DEFAULT_APP_KEY_VALUE_SCOPE },\n      caller: 'kv.get',\n    });\n\n    return (appKeyValue?.value ?? null) as TValue | null;\n  },\n\n  async set<TValue>(\n    key: string,\n    value: TValue,\n    options?: KvOptions,\n  ): Promise<void> {\n    await postGraphqlRequest<\n      {\n        input: { key: string; value: TValue; scope: AppKeyValueScope };\n      },\n      { setAppKeyValue: AppKeyValue }\n    >({\n      query: SET_APP_KEY_VALUE_MUTATION,\n      variables: {\n        input: {\n          key,\n          value,\n          scope: options?.scope ?? DEFAULT_APP_KEY_VALUE_SCOPE,\n        },\n      },\n      caller: 'kv.set',\n    });\n  },\n\n  async delete(key: string, options?: KvOptions): Promise<boolean> {\n    const { deleteAppKeyValue } = await postGraphqlRequest<\n      { key: string; scope: AppKeyValueScope },\n      { deleteAppKeyValue: boolean }\n    >({\n      query: DELETE_APP_KEY_VALUE_MUTATION,\n      variables: { key, scope: options?.scope ?? DEFAULT_APP_KEY_VALUE_SCOPE },\n      caller: 'kv.delete',\n    });\n\n    return deleteAppKeyValue;\n  },\n};\n","import { type LogicFunctionHttpResponse } from 'twenty-shared/types';\n\nexport type ResponseInit = {\n  status?: number;\n  headers?: Record<string, string>;\n};\n\nexport class Response implements LogicFunctionHttpResponse {\n  readonly __twentyHttpResponse = true as const;\n  readonly body: unknown;\n  readonly status?: number;\n  readonly headers?: Record<string, string>;\n\n  constructor(body: unknown, init?: ResponseInit) {\n    this.body = body;\n    this.status = init?.status;\n    this.headers = init?.headers;\n  }\n}\n"],"mappings":"+KAEA,IAAIA,EAAK,GAAM,EAAA,EAAA,EAAA,YAAA,CAAG,CAAC,GAAK,EAAA,EAAA,EAAA,OAAA,CAAG,CAAC,ECsBzB,EAAK,GAAM,CACb,IAAI,EAAI,CAAE,KAAM,SAAU,EAC1B,OAAQ,EAAE,KAAV,CACC,IAAK,SACJ,EAAE,KAAO,SACT,MACD,IAAK,SACL,IAAK,UACJ,EAAE,KAAO,SACT,MACD,IAAK,UACJ,EAAE,KAAO,UACT,MACD,IAAK,QACJ,EAAE,KAAO,QAAS,EAAE,QAAU,EAAE,MAAQ,EAAE,EAAE,KAAK,GACjD,MACD,IAAK,SACJ,EAAE,KAAO,SAAU,EAAE,aAAe,EAAE,WAAa,OAAO,YAAY,OAAO,QAAQ,EAAE,UAAU,CAAC,CAAC,KAAK,CAAC,EAAG,KAAO,CAAC,EAAG,EAAE,CAAC,CAAC,CAAC,CAAC,GAC7H,MACD,IAAK,SACJ,EAAE,KAAO,SACT,MACD,IAAK,UACJ,EAAE,KAAO,UACT,MACD,QAAS,EAAE,KAAO,SACnB,CACA,OAAO,MAAM,QAAQ,EAAE,IAAI,IAAM,EAAE,KAAO,EAAE,KAAK,OAAQ,GAAM,OAAO,GAAK,QAAQ,GAAI,EAAE,YAAc,CAAC,IAAM,EAAE,UAAY,CAAC,IAAA,EAAA,EAAA,iBAAA,CAAM,EAAE,KAAK,IAAM,EAAE,MAAQ,EAAE,QAAA,EAAA,EAAA,iBAAA,CAAU,EAAE,yBAAyB,IAAM,EAAE,0BAA4B,EAAE,2BAA4B,CACpQ,EAAG,EAAK,GAAM,CAAC,EAAE,CAAC,CAAC,EAAsB,E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