{"version":3,"file":"AIToolApprover.mjs","names":[],"sources":["../../../../../src/plugins/AIComponents/ToolCalls/AIToolApprover.tsx"],"sourcesContent":["import React, {\n  createContext,\n  type PropsWithChildren,\n  type ReactNode,\n  useContext,\n} from 'react';\n\nimport type { AIToolCallPart } from '../MessageParts';\n\n/**\n * How the person signs in on this device when a tool call waits for their account at a\n * provider, and how their \"not now\" reaches your backend, which holds the call until one or\n * the other. `createPopupAuthorizer` makes one that opens the sign-in in a popup.\n */\nexport type AIToolAuthorizer = {\n  /**\n   * Opens the call's sign-in. It is called in the click handler, so a popup it opens before\n   * anything is awaited is not blocked.\n   *\n   * Resolves `true` once the account is connected: your backend then updates the call's step,\n   * and until it does the sign-in reads as connecting. Resolves `false` when the person closed\n   * the sign-in or it ended without connecting, so they can try again. Rejects when the sign-in\n   * could not be opened.\n   */\n  connect: (call: AIToolCallPart) => Promise<boolean>;\n  /**\n   * Tells your backend the person won't sign in now. Your backend ends the call, which never\n   * runs. A rejection lets the person answer again.\n   */\n  decline: (call: AIToolCallPart) => Promise<void>;\n};\n\n/**\n * The person answering tool calls' questions on this device, and how their answer reaches\n * your backend, which holds each call until it gets one.\n */\nexport type AIToolApprover = {\n  /** This install, matched against a client tool call's `target_client_id`. Use `AIClientIdentity.installId()`. */\n  clientId: string;\n  /**\n   * Sends the answer. Your backend checks it is this person's (and this install's, for a\n   * client tool), then updates the call's step; until then the question stays, with its\n   * buttons disabled. A rejection lets the person answer again.\n   */\n  decide: (call: AIToolCallPart, allowed: boolean) => Promise<void>;\n  /** The person signed in, matched against a call's `target_user_id`. */\n  userId: string;\n  /**\n   * What an approval card shows of what the call will send, under its question. Return the\n   * view of `call.arguments` the app wants, such as a sentence or a table, `null` to show\n   * nothing, or `undefined` for the default: the arguments as JSON, collapsed when long.\n   */\n  argumentsPreview?: (call: AIToolCallPart) => ReactNode | null | undefined;\n  /** How this person signs in when a call waits for their account. Without one, no sign-in is offered here. */\n  authorizer?: AIToolAuthorizer;\n};\n\nconst AIToolApproverContext = createContext<AIToolApprover | undefined>(undefined);\n\n/**\n * Provides the approver to the AI components below it, for those not given one as a prop.\n */\nexport const AIToolApproverProvider = ({\n  approver,\n  children,\n}: PropsWithChildren<{ approver?: AIToolApprover }>) => (\n  <AIToolApproverContext.Provider value={approver}>\n    {children}\n  </AIToolApproverContext.Provider>\n);\n\n/** The approver given as a prop, else the one of the nearest `AIToolApproverProvider`. */\nexport const useAIToolApprover = (approver?: AIToolApprover) => {\n  const fromContext = useContext(AIToolApproverContext);\n  return approver ?? fromContext;\n};\n"],"mappings":";;;AAyDA,IAAM,wBAAwB,cAA0C,KAAA,CAAS;;;;AAKjF,IAAa,0BAA0B,EACrC,UACA,eAEA,oBAAC,sBAAsB,UAAvB;CAAgC,OAAO;CACpC;AAC6B,CAAA;;AAIlC,IAAa,qBAAqB,aAA8B;CAC9D,MAAM,cAAc,WAAW,qBAAqB;CACpD,OAAO,YAAY;AACrB"}