{"version":3,"sources":["../../../src/runtimes/local/useLocalRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useMemo, useState } from \"react\";\nimport type { ChatModelAdapter } from \"./ChatModelAdapter\";\nimport { LocalRuntimeCore } from \"./LocalRuntimeCore\";\nimport { LocalRuntimeOptions } from \"./LocalRuntimeOptions\";\nimport {\n  AssistantRuntime,\n  AssistantRuntimeImpl,\n} from \"../../api/AssistantRuntime\";\nimport { ThreadRuntimeImpl } from \"../../internal\";\nimport { ThreadRuntime } from \"../../api/ThreadRuntime\";\n\nexport type LocalRuntime = AssistantRuntime & {\n  reset: (options?: Parameters<LocalRuntimeCore[\"reset\"]>[0]) => void;\n};\n\nclass LocalRuntimeImpl extends AssistantRuntimeImpl implements LocalRuntime {\n  private constructor(\n    private core: LocalRuntimeCore,\n    thread: ThreadRuntime,\n  ) {\n    super(core, thread);\n  }\n\n  public reset(options?: Parameters<LocalRuntimeCore[\"reset\"]>[0]) {\n    this.core.reset(options);\n  }\n\n  public static override create(_core: LocalRuntimeCore) {\n    return new LocalRuntimeImpl(\n      _core,\n      AssistantRuntimeImpl.createMainThreadRuntime(_core, ThreadRuntimeImpl),\n    ) as LocalRuntime;\n  }\n}\n\nexport const useLocalRuntime = (\n  adapter: ChatModelAdapter,\n  { initialMessages, ...options }: LocalRuntimeOptions = {},\n) => {\n  const opt = {\n    ...options,\n    adapters: {\n      ...options.adapters,\n      chatModel: adapter,\n    },\n  };\n\n  const [runtime] = useState(() => new LocalRuntimeCore(opt, initialMessages));\n\n  useEffect(() => {\n    runtime.setOptions(opt);\n  });\n\n  return useMemo(() => LocalRuntimeImpl.create(runtime), [runtime]);\n};\n"],"mappings":";;;AAEA,SAAS,WAAW,SAAS,gBAAgB;AAE7C,SAAS,wBAAwB;AAEjC;AAAA,EAEE;AAAA,OACK;AACP,SAAS,yBAAyB;AAOlC,IAAM,mBAAN,MAAM,0BAAyB,qBAA6C;AAAA,EAClE,YACE,MACR,QACA;AACA,UAAM,MAAM,MAAM;AAHV;AAAA,EAIV;AAAA,EAEO,MAAM,SAAoD;AAC/D,SAAK,KAAK,MAAM,OAAO;AAAA,EACzB;AAAA,EAEA,OAAuB,OAAO,OAAyB;AACrD,WAAO,IAAI;AAAA,MACT;AAAA,MACA,qBAAqB,wBAAwB,OAAO,iBAAiB;AAAA,IACvE;AAAA,EACF;AACF;AAEO,IAAM,kBAAkB,CAC7B,SACA,EAAE,iBAAiB,GAAG,QAAQ,IAAyB,CAAC,MACrD;AACH,QAAM,MAAM;AAAA,IACV,GAAG;AAAA,IACH,UAAU;AAAA,MACR,GAAG,QAAQ;AAAA,MACX,WAAW;AAAA,IACb;AAAA,EACF;AAEA,QAAM,CAAC,OAAO,IAAI,SAAS,MAAM,IAAI,iBAAiB,KAAK,eAAe,CAAC;AAE3E,YAAU,MAAM;AACd,YAAQ,WAAW,GAAG;AAAA,EACxB,CAAC;AAED,SAAO,QAAQ,MAAM,iBAAiB,OAAO,OAAO,GAAG,CAAC,OAAO,CAAC;AAClE;","names":[]}