AgentThreadsApi.php 81 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078
  1. <?php
  2. /**
  3. * AgentThreadsApi
  4. * PHP version 8.1
  5. *
  6. * @category Class
  7. * @package WikipaliApi
  8. * @author OpenAPI Generator team
  9. * @link https://openapi-generator.tech
  10. */
  11. /**
  12. * MINT API
  13. *
  14. * International Academy Of Pali Tipitaka(国际巴利三藏学院) 由 `php openapi/scripts/generate.php` 依据 api-v13 的路由与控制器源码生成。 响应统一封装为 `{ok, message, data}`;`ok=false` 时 `message` 为错误信息。
  15. *
  16. * The version of the OpenAPI document: 1.0.0
  17. * Generated by: https://openapi-generator.tech
  18. * Generator version: 7.25.0
  19. */
  20. /**
  21. * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
  22. * https://openapi-generator.tech
  23. * Do not edit the class manually.
  24. */
  25. namespace WikipaliApi\Api;
  26. use GuzzleHttp\Client;
  27. use GuzzleHttp\ClientInterface;
  28. use GuzzleHttp\Exception\ConnectException;
  29. use GuzzleHttp\Exception\RequestException;
  30. use GuzzleHttp\Psr7\MultipartStream;
  31. use GuzzleHttp\Psr7\Request;
  32. use GuzzleHttp\RequestOptions;
  33. use Psr\Http\Message\RequestInterface;
  34. use Psr\Http\Message\ResponseInterface;
  35. use WikipaliApi\ApiException;
  36. use WikipaliApi\Configuration;
  37. use WikipaliApi\FormDataProcessor;
  38. use WikipaliApi\HeaderSelector;
  39. use WikipaliApi\ObjectSerializer;
  40. /**
  41. * AgentThreadsApi Class Doc Comment
  42. *
  43. * @category Class
  44. * @package WikipaliApi
  45. * @author OpenAPI Generator team
  46. * @link https://openapi-generator.tech
  47. */
  48. class AgentThreadsApi
  49. {
  50. /**
  51. * @var ClientInterface
  52. */
  53. protected $client;
  54. /**
  55. * @var Configuration
  56. */
  57. protected $config;
  58. /**
  59. * @var HeaderSelector
  60. */
  61. protected $headerSelector;
  62. /**
  63. * @var int Host index
  64. */
  65. protected $hostIndex;
  66. /** @var string[] $contentTypes **/
  67. public const contentTypes = [
  68. 'deleteApiV3MeAgentThreadsThread' => [
  69. 'application/json',
  70. ],
  71. 'deleteApiV3MeAgentThreadsThreadArchive' => [
  72. 'application/json',
  73. ],
  74. 'getApiV3MeAgentThreads' => [
  75. 'application/json',
  76. ],
  77. 'getApiV3MeAgentThreadsThread' => [
  78. 'application/json',
  79. ],
  80. 'patchApiV3MeAgentThreadsThread' => [
  81. 'application/json',
  82. ],
  83. 'putApiV3MeAgentThreadsThreadArchive' => [
  84. 'application/json',
  85. ],
  86. ];
  87. /**
  88. * @param ClientInterface $client
  89. * @param Configuration $config
  90. * @param HeaderSelector $selector
  91. * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
  92. */
  93. public function __construct(
  94. ?ClientInterface $client = null,
  95. ?Configuration $config = null,
  96. ?HeaderSelector $selector = null,
  97. int $hostIndex = 0
  98. ) {
  99. $this->client = $client ?: new Client();
  100. $this->config = $config ?: Configuration::getDefaultConfiguration();
  101. $this->headerSelector = $selector ?: new HeaderSelector();
  102. $this->hostIndex = $hostIndex;
  103. }
  104. /**
  105. * Set the host index
  106. *
  107. * @param int $hostIndex Host index (required)
  108. */
  109. public function setHostIndex($hostIndex): void
  110. {
  111. $this->hostIndex = $hostIndex;
  112. }
  113. /**
  114. * Get the host index
  115. *
  116. * @return int Host index
  117. */
  118. public function getHostIndex()
  119. {
  120. return $this->hostIndex;
  121. }
  122. /**
  123. * @return Configuration
  124. */
  125. public function getConfig()
  126. {
  127. return $this->config;
  128. }
  129. /**
  130. * Operation deleteApiV3MeAgentThreadsThread
  131. *
  132. * 删除会话
  133. *
  134. * @param string $thread AG-UI threadId(uuid) (required)
  135. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3MeAgentThreadsThread'] to see the possible values for this operation
  136. *
  137. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  138. * @throws \InvalidArgumentException
  139. * @return \WikipaliApi\Model\GetApiV3MeAgentThreadsThread200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  140. */
  141. public function deleteApiV3MeAgentThreadsThread($thread, string $contentType = self::contentTypes['deleteApiV3MeAgentThreadsThread'][0])
  142. {
  143. list($response) = $this->deleteApiV3MeAgentThreadsThreadWithHttpInfo($thread, $contentType);
  144. return $response;
  145. }
  146. /**
  147. * Operation deleteApiV3MeAgentThreadsThreadWithHttpInfo
  148. *
  149. * 删除会话
  150. *
  151. * @param string $thread AG-UI threadId(uuid) (required)
  152. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3MeAgentThreadsThread'] to see the possible values for this operation
  153. *
  154. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  155. * @throws \InvalidArgumentException
  156. * @return array of \WikipaliApi\Model\GetApiV3MeAgentThreadsThread200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  157. */
  158. public function deleteApiV3MeAgentThreadsThreadWithHttpInfo($thread, string $contentType = self::contentTypes['deleteApiV3MeAgentThreadsThread'][0])
  159. {
  160. $request = $this->deleteApiV3MeAgentThreadsThreadRequest($thread, $contentType);
  161. try {
  162. $options = $this->createHttpClientOption();
  163. try {
  164. $response = $this->client->send($request, $options);
  165. } catch (RequestException $e) {
  166. throw new ApiException(
  167. "[{$e->getCode()}] {$e->getMessage()}",
  168. (int) $e->getCode(),
  169. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  170. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  171. );
  172. } catch (ConnectException $e) {
  173. throw new ApiException(
  174. "[{$e->getCode()}] {$e->getMessage()}",
  175. (int) $e->getCode(),
  176. null,
  177. null
  178. );
  179. }
  180. $statusCode = $response->getStatusCode();
  181. switch($statusCode) {
  182. case 200:
  183. return $this->handleResponseWithDataType(
  184. '\WikipaliApi\Model\GetApiV3MeAgentThreadsThread200Response',
  185. $request,
  186. $response,
  187. );
  188. case 401:
  189. return $this->handleResponseWithDataType(
  190. '\WikipaliApi\Model\ProblemDetails',
  191. $request,
  192. $response,
  193. );
  194. case 422:
  195. return $this->handleResponseWithDataType(
  196. '\WikipaliApi\Model\ProblemDetails',
  197. $request,
  198. $response,
  199. );
  200. }
  201. if ($statusCode < 200 || $statusCode > 299) {
  202. throw new ApiException(
  203. sprintf(
  204. '[%d] Error connecting to the API (%s)',
  205. $statusCode,
  206. (string) $request->getUri()
  207. ),
  208. $statusCode,
  209. $response->getHeaders(),
  210. (string) $response->getBody()
  211. );
  212. }
  213. return $this->handleResponseWithDataType(
  214. '\WikipaliApi\Model\GetApiV3MeAgentThreadsThread200Response',
  215. $request,
  216. $response,
  217. );
  218. } catch (ApiException $e) {
  219. switch ($e->getCode()) {
  220. case 200:
  221. $data = ObjectSerializer::deserialize(
  222. $e->getResponseBody(),
  223. '\WikipaliApi\Model\GetApiV3MeAgentThreadsThread200Response',
  224. $e->getResponseHeaders()
  225. );
  226. $e->setResponseObject($data);
  227. throw $e;
  228. case 401:
  229. $data = ObjectSerializer::deserialize(
  230. $e->getResponseBody(),
  231. '\WikipaliApi\Model\ProblemDetails',
  232. $e->getResponseHeaders()
  233. );
  234. $e->setResponseObject($data);
  235. throw $e;
  236. case 422:
  237. $data = ObjectSerializer::deserialize(
  238. $e->getResponseBody(),
  239. '\WikipaliApi\Model\ProblemDetails',
  240. $e->getResponseHeaders()
  241. );
  242. $e->setResponseObject($data);
  243. throw $e;
  244. }
  245. throw $e;
  246. }
  247. }
  248. /**
  249. * Operation deleteApiV3MeAgentThreadsThreadAsync
  250. *
  251. * 删除会话
  252. *
  253. * @param string $thread AG-UI threadId(uuid) (required)
  254. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3MeAgentThreadsThread'] to see the possible values for this operation
  255. *
  256. * @throws \InvalidArgumentException
  257. * @return \GuzzleHttp\Promise\PromiseInterface
  258. */
  259. public function deleteApiV3MeAgentThreadsThreadAsync($thread, string $contentType = self::contentTypes['deleteApiV3MeAgentThreadsThread'][0])
  260. {
  261. return $this->deleteApiV3MeAgentThreadsThreadAsyncWithHttpInfo($thread, $contentType)
  262. ->then(
  263. function ($response) {
  264. return $response[0];
  265. }
  266. );
  267. }
  268. /**
  269. * Operation deleteApiV3MeAgentThreadsThreadAsyncWithHttpInfo
  270. *
  271. * 删除会话
  272. *
  273. * @param string $thread AG-UI threadId(uuid) (required)
  274. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3MeAgentThreadsThread'] to see the possible values for this operation
  275. *
  276. * @throws \InvalidArgumentException
  277. * @return \GuzzleHttp\Promise\PromiseInterface
  278. */
  279. public function deleteApiV3MeAgentThreadsThreadAsyncWithHttpInfo($thread, string $contentType = self::contentTypes['deleteApiV3MeAgentThreadsThread'][0])
  280. {
  281. $returnType = '\WikipaliApi\Model\GetApiV3MeAgentThreadsThread200Response';
  282. $request = $this->deleteApiV3MeAgentThreadsThreadRequest($thread, $contentType);
  283. return $this->client
  284. ->sendAsync($request, $this->createHttpClientOption())
  285. ->then(
  286. function ($response) use ($returnType) {
  287. if ($returnType === '\SplFileObject') {
  288. $content = $response->getBody(); //stream goes to serializer
  289. } else {
  290. $content = (string) $response->getBody();
  291. if ($returnType !== 'string') {
  292. $content = json_decode($content);
  293. }
  294. }
  295. return [
  296. ObjectSerializer::deserialize($content, $returnType, []),
  297. $response->getStatusCode(),
  298. $response->getHeaders()
  299. ];
  300. },
  301. function ($exception) {
  302. $response = $exception->getResponse();
  303. $statusCode = $response->getStatusCode();
  304. throw new ApiException(
  305. sprintf(
  306. '[%d] Error connecting to the API (%s)',
  307. $statusCode,
  308. $exception->getRequest()->getUri()
  309. ),
  310. $statusCode,
  311. $response->getHeaders(),
  312. (string) $response->getBody()
  313. );
  314. }
  315. );
  316. }
  317. /**
  318. * Create request for operation 'deleteApiV3MeAgentThreadsThread'
  319. *
  320. * @param string $thread AG-UI threadId(uuid) (required)
  321. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3MeAgentThreadsThread'] to see the possible values for this operation
  322. *
  323. * @throws \InvalidArgumentException
  324. * @return \GuzzleHttp\Psr7\Request
  325. */
  326. public function deleteApiV3MeAgentThreadsThreadRequest($thread, string $contentType = self::contentTypes['deleteApiV3MeAgentThreadsThread'][0])
  327. {
  328. // verify the required parameter 'thread' is set
  329. if ($thread === null || (is_array($thread) && count($thread) === 0)) {
  330. throw new \InvalidArgumentException(
  331. 'Missing the required parameter $thread when calling deleteApiV3MeAgentThreadsThread'
  332. );
  333. }
  334. $resourcePath = '/v3/me/agent-threads/{thread}';
  335. $formParams = [];
  336. $queryParams = [];
  337. $headerParams = [];
  338. $httpBody = '';
  339. $multipart = false;
  340. // path params
  341. if ($thread !== null) {
  342. $resourcePath = str_replace(
  343. '{thread}',
  344. ObjectSerializer::toPathValue($thread),
  345. $resourcePath
  346. );
  347. }
  348. $headers = $this->headerSelector->selectHeaders(
  349. ['application/json', 'application/problem+json', ],
  350. $contentType,
  351. $multipart
  352. );
  353. // for model (json/xml)
  354. if (count($formParams) > 0) {
  355. if ($multipart) {
  356. $multipartContents = [];
  357. foreach ($formParams as $formParamName => $formParamValue) {
  358. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  359. foreach ($formParamValueItems as $formParamValueItem) {
  360. $multipartContents[] = [
  361. 'name' => $formParamName,
  362. 'contents' => $formParamValueItem
  363. ];
  364. }
  365. }
  366. // for HTTP post (form)
  367. $httpBody = new MultipartStream($multipartContents);
  368. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  369. # if Content-Type contains "application/json", json_encode the form parameters
  370. try {
  371. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  372. } catch (\JsonException $e) {
  373. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  374. }
  375. } else {
  376. // for HTTP post (form)
  377. $httpBody = ObjectSerializer::buildQuery($formParams);
  378. }
  379. }
  380. // this endpoint requires Bearer authentication (access token)
  381. if (!empty($this->config->getAccessToken())) {
  382. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  383. }
  384. $defaultHeaders = [];
  385. if ($this->config->getUserAgent()) {
  386. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  387. }
  388. $headers = array_merge(
  389. $defaultHeaders,
  390. $headerParams,
  391. $headers
  392. );
  393. $operationHost = $this->config->getHost();
  394. $query = ObjectSerializer::buildQuery($queryParams);
  395. return new Request(
  396. 'DELETE',
  397. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  398. $headers,
  399. $httpBody
  400. );
  401. }
  402. /**
  403. * Operation deleteApiV3MeAgentThreadsThreadArchive
  404. *
  405. * 取消存档
  406. *
  407. * @param string $thread AG-UI threadId(uuid) (required)
  408. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3MeAgentThreadsThreadArchive'] to see the possible values for this operation
  409. *
  410. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  411. * @throws \InvalidArgumentException
  412. * @return \WikipaliApi\Model\GetApiV3MeAgentThreadsThread200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  413. */
  414. public function deleteApiV3MeAgentThreadsThreadArchive($thread, string $contentType = self::contentTypes['deleteApiV3MeAgentThreadsThreadArchive'][0])
  415. {
  416. list($response) = $this->deleteApiV3MeAgentThreadsThreadArchiveWithHttpInfo($thread, $contentType);
  417. return $response;
  418. }
  419. /**
  420. * Operation deleteApiV3MeAgentThreadsThreadArchiveWithHttpInfo
  421. *
  422. * 取消存档
  423. *
  424. * @param string $thread AG-UI threadId(uuid) (required)
  425. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3MeAgentThreadsThreadArchive'] to see the possible values for this operation
  426. *
  427. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  428. * @throws \InvalidArgumentException
  429. * @return array of \WikipaliApi\Model\GetApiV3MeAgentThreadsThread200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  430. */
  431. public function deleteApiV3MeAgentThreadsThreadArchiveWithHttpInfo($thread, string $contentType = self::contentTypes['deleteApiV3MeAgentThreadsThreadArchive'][0])
  432. {
  433. $request = $this->deleteApiV3MeAgentThreadsThreadArchiveRequest($thread, $contentType);
  434. try {
  435. $options = $this->createHttpClientOption();
  436. try {
  437. $response = $this->client->send($request, $options);
  438. } catch (RequestException $e) {
  439. throw new ApiException(
  440. "[{$e->getCode()}] {$e->getMessage()}",
  441. (int) $e->getCode(),
  442. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  443. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  444. );
  445. } catch (ConnectException $e) {
  446. throw new ApiException(
  447. "[{$e->getCode()}] {$e->getMessage()}",
  448. (int) $e->getCode(),
  449. null,
  450. null
  451. );
  452. }
  453. $statusCode = $response->getStatusCode();
  454. switch($statusCode) {
  455. case 200:
  456. return $this->handleResponseWithDataType(
  457. '\WikipaliApi\Model\GetApiV3MeAgentThreadsThread200Response',
  458. $request,
  459. $response,
  460. );
  461. case 401:
  462. return $this->handleResponseWithDataType(
  463. '\WikipaliApi\Model\ProblemDetails',
  464. $request,
  465. $response,
  466. );
  467. case 422:
  468. return $this->handleResponseWithDataType(
  469. '\WikipaliApi\Model\ProblemDetails',
  470. $request,
  471. $response,
  472. );
  473. }
  474. if ($statusCode < 200 || $statusCode > 299) {
  475. throw new ApiException(
  476. sprintf(
  477. '[%d] Error connecting to the API (%s)',
  478. $statusCode,
  479. (string) $request->getUri()
  480. ),
  481. $statusCode,
  482. $response->getHeaders(),
  483. (string) $response->getBody()
  484. );
  485. }
  486. return $this->handleResponseWithDataType(
  487. '\WikipaliApi\Model\GetApiV3MeAgentThreadsThread200Response',
  488. $request,
  489. $response,
  490. );
  491. } catch (ApiException $e) {
  492. switch ($e->getCode()) {
  493. case 200:
  494. $data = ObjectSerializer::deserialize(
  495. $e->getResponseBody(),
  496. '\WikipaliApi\Model\GetApiV3MeAgentThreadsThread200Response',
  497. $e->getResponseHeaders()
  498. );
  499. $e->setResponseObject($data);
  500. throw $e;
  501. case 401:
  502. $data = ObjectSerializer::deserialize(
  503. $e->getResponseBody(),
  504. '\WikipaliApi\Model\ProblemDetails',
  505. $e->getResponseHeaders()
  506. );
  507. $e->setResponseObject($data);
  508. throw $e;
  509. case 422:
  510. $data = ObjectSerializer::deserialize(
  511. $e->getResponseBody(),
  512. '\WikipaliApi\Model\ProblemDetails',
  513. $e->getResponseHeaders()
  514. );
  515. $e->setResponseObject($data);
  516. throw $e;
  517. }
  518. throw $e;
  519. }
  520. }
  521. /**
  522. * Operation deleteApiV3MeAgentThreadsThreadArchiveAsync
  523. *
  524. * 取消存档
  525. *
  526. * @param string $thread AG-UI threadId(uuid) (required)
  527. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3MeAgentThreadsThreadArchive'] to see the possible values for this operation
  528. *
  529. * @throws \InvalidArgumentException
  530. * @return \GuzzleHttp\Promise\PromiseInterface
  531. */
  532. public function deleteApiV3MeAgentThreadsThreadArchiveAsync($thread, string $contentType = self::contentTypes['deleteApiV3MeAgentThreadsThreadArchive'][0])
  533. {
  534. return $this->deleteApiV3MeAgentThreadsThreadArchiveAsyncWithHttpInfo($thread, $contentType)
  535. ->then(
  536. function ($response) {
  537. return $response[0];
  538. }
  539. );
  540. }
  541. /**
  542. * Operation deleteApiV3MeAgentThreadsThreadArchiveAsyncWithHttpInfo
  543. *
  544. * 取消存档
  545. *
  546. * @param string $thread AG-UI threadId(uuid) (required)
  547. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3MeAgentThreadsThreadArchive'] to see the possible values for this operation
  548. *
  549. * @throws \InvalidArgumentException
  550. * @return \GuzzleHttp\Promise\PromiseInterface
  551. */
  552. public function deleteApiV3MeAgentThreadsThreadArchiveAsyncWithHttpInfo($thread, string $contentType = self::contentTypes['deleteApiV3MeAgentThreadsThreadArchive'][0])
  553. {
  554. $returnType = '\WikipaliApi\Model\GetApiV3MeAgentThreadsThread200Response';
  555. $request = $this->deleteApiV3MeAgentThreadsThreadArchiveRequest($thread, $contentType);
  556. return $this->client
  557. ->sendAsync($request, $this->createHttpClientOption())
  558. ->then(
  559. function ($response) use ($returnType) {
  560. if ($returnType === '\SplFileObject') {
  561. $content = $response->getBody(); //stream goes to serializer
  562. } else {
  563. $content = (string) $response->getBody();
  564. if ($returnType !== 'string') {
  565. $content = json_decode($content);
  566. }
  567. }
  568. return [
  569. ObjectSerializer::deserialize($content, $returnType, []),
  570. $response->getStatusCode(),
  571. $response->getHeaders()
  572. ];
  573. },
  574. function ($exception) {
  575. $response = $exception->getResponse();
  576. $statusCode = $response->getStatusCode();
  577. throw new ApiException(
  578. sprintf(
  579. '[%d] Error connecting to the API (%s)',
  580. $statusCode,
  581. $exception->getRequest()->getUri()
  582. ),
  583. $statusCode,
  584. $response->getHeaders(),
  585. (string) $response->getBody()
  586. );
  587. }
  588. );
  589. }
  590. /**
  591. * Create request for operation 'deleteApiV3MeAgentThreadsThreadArchive'
  592. *
  593. * @param string $thread AG-UI threadId(uuid) (required)
  594. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteApiV3MeAgentThreadsThreadArchive'] to see the possible values for this operation
  595. *
  596. * @throws \InvalidArgumentException
  597. * @return \GuzzleHttp\Psr7\Request
  598. */
  599. public function deleteApiV3MeAgentThreadsThreadArchiveRequest($thread, string $contentType = self::contentTypes['deleteApiV3MeAgentThreadsThreadArchive'][0])
  600. {
  601. // verify the required parameter 'thread' is set
  602. if ($thread === null || (is_array($thread) && count($thread) === 0)) {
  603. throw new \InvalidArgumentException(
  604. 'Missing the required parameter $thread when calling deleteApiV3MeAgentThreadsThreadArchive'
  605. );
  606. }
  607. $resourcePath = '/v3/me/agent-threads/{thread}/archive';
  608. $formParams = [];
  609. $queryParams = [];
  610. $headerParams = [];
  611. $httpBody = '';
  612. $multipart = false;
  613. // path params
  614. if ($thread !== null) {
  615. $resourcePath = str_replace(
  616. '{thread}',
  617. ObjectSerializer::toPathValue($thread),
  618. $resourcePath
  619. );
  620. }
  621. $headers = $this->headerSelector->selectHeaders(
  622. ['application/json', 'application/problem+json', ],
  623. $contentType,
  624. $multipart
  625. );
  626. // for model (json/xml)
  627. if (count($formParams) > 0) {
  628. if ($multipart) {
  629. $multipartContents = [];
  630. foreach ($formParams as $formParamName => $formParamValue) {
  631. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  632. foreach ($formParamValueItems as $formParamValueItem) {
  633. $multipartContents[] = [
  634. 'name' => $formParamName,
  635. 'contents' => $formParamValueItem
  636. ];
  637. }
  638. }
  639. // for HTTP post (form)
  640. $httpBody = new MultipartStream($multipartContents);
  641. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  642. # if Content-Type contains "application/json", json_encode the form parameters
  643. try {
  644. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  645. } catch (\JsonException $e) {
  646. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  647. }
  648. } else {
  649. // for HTTP post (form)
  650. $httpBody = ObjectSerializer::buildQuery($formParams);
  651. }
  652. }
  653. // this endpoint requires Bearer authentication (access token)
  654. if (!empty($this->config->getAccessToken())) {
  655. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  656. }
  657. $defaultHeaders = [];
  658. if ($this->config->getUserAgent()) {
  659. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  660. }
  661. $headers = array_merge(
  662. $defaultHeaders,
  663. $headerParams,
  664. $headers
  665. );
  666. $operationHost = $this->config->getHost();
  667. $query = ObjectSerializer::buildQuery($queryParams);
  668. return new Request(
  669. 'DELETE',
  670. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  671. $headers,
  672. $httpBody
  673. );
  674. }
  675. /**
  676. * Operation getApiV3MeAgentThreads
  677. *
  678. * 列出我的会话
  679. *
  680. * @param int|null $per_page 每页数量,最大 100 (optional, default to 30)
  681. * @param bool|null $filter_archived 只看已存档(true)或未存档(false)的;不传则全部 (optional)
  682. * @param int|null $page 页码 (optional, default to 1)
  683. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3MeAgentThreads'] to see the possible values for this operation
  684. *
  685. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  686. * @throws \InvalidArgumentException
  687. * @return \WikipaliApi\Model\GetApiV3MeAgentThreads200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  688. */
  689. public function getApiV3MeAgentThreads($per_page = 30, $filter_archived = null, $page = 1, string $contentType = self::contentTypes['getApiV3MeAgentThreads'][0])
  690. {
  691. list($response) = $this->getApiV3MeAgentThreadsWithHttpInfo($per_page, $filter_archived, $page, $contentType);
  692. return $response;
  693. }
  694. /**
  695. * Operation getApiV3MeAgentThreadsWithHttpInfo
  696. *
  697. * 列出我的会话
  698. *
  699. * @param int|null $per_page 每页数量,最大 100 (optional, default to 30)
  700. * @param bool|null $filter_archived 只看已存档(true)或未存档(false)的;不传则全部 (optional)
  701. * @param int|null $page 页码 (optional, default to 1)
  702. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3MeAgentThreads'] to see the possible values for this operation
  703. *
  704. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  705. * @throws \InvalidArgumentException
  706. * @return array of \WikipaliApi\Model\GetApiV3MeAgentThreads200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  707. */
  708. public function getApiV3MeAgentThreadsWithHttpInfo($per_page = 30, $filter_archived = null, $page = 1, string $contentType = self::contentTypes['getApiV3MeAgentThreads'][0])
  709. {
  710. $request = $this->getApiV3MeAgentThreadsRequest($per_page, $filter_archived, $page, $contentType);
  711. try {
  712. $options = $this->createHttpClientOption();
  713. try {
  714. $response = $this->client->send($request, $options);
  715. } catch (RequestException $e) {
  716. throw new ApiException(
  717. "[{$e->getCode()}] {$e->getMessage()}",
  718. (int) $e->getCode(),
  719. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  720. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  721. );
  722. } catch (ConnectException $e) {
  723. throw new ApiException(
  724. "[{$e->getCode()}] {$e->getMessage()}",
  725. (int) $e->getCode(),
  726. null,
  727. null
  728. );
  729. }
  730. $statusCode = $response->getStatusCode();
  731. switch($statusCode) {
  732. case 200:
  733. return $this->handleResponseWithDataType(
  734. '\WikipaliApi\Model\GetApiV3MeAgentThreads200Response',
  735. $request,
  736. $response,
  737. );
  738. case 401:
  739. return $this->handleResponseWithDataType(
  740. '\WikipaliApi\Model\ProblemDetails',
  741. $request,
  742. $response,
  743. );
  744. case 422:
  745. return $this->handleResponseWithDataType(
  746. '\WikipaliApi\Model\ProblemDetails',
  747. $request,
  748. $response,
  749. );
  750. }
  751. if ($statusCode < 200 || $statusCode > 299) {
  752. throw new ApiException(
  753. sprintf(
  754. '[%d] Error connecting to the API (%s)',
  755. $statusCode,
  756. (string) $request->getUri()
  757. ),
  758. $statusCode,
  759. $response->getHeaders(),
  760. (string) $response->getBody()
  761. );
  762. }
  763. return $this->handleResponseWithDataType(
  764. '\WikipaliApi\Model\GetApiV3MeAgentThreads200Response',
  765. $request,
  766. $response,
  767. );
  768. } catch (ApiException $e) {
  769. switch ($e->getCode()) {
  770. case 200:
  771. $data = ObjectSerializer::deserialize(
  772. $e->getResponseBody(),
  773. '\WikipaliApi\Model\GetApiV3MeAgentThreads200Response',
  774. $e->getResponseHeaders()
  775. );
  776. $e->setResponseObject($data);
  777. throw $e;
  778. case 401:
  779. $data = ObjectSerializer::deserialize(
  780. $e->getResponseBody(),
  781. '\WikipaliApi\Model\ProblemDetails',
  782. $e->getResponseHeaders()
  783. );
  784. $e->setResponseObject($data);
  785. throw $e;
  786. case 422:
  787. $data = ObjectSerializer::deserialize(
  788. $e->getResponseBody(),
  789. '\WikipaliApi\Model\ProblemDetails',
  790. $e->getResponseHeaders()
  791. );
  792. $e->setResponseObject($data);
  793. throw $e;
  794. }
  795. throw $e;
  796. }
  797. }
  798. /**
  799. * Operation getApiV3MeAgentThreadsAsync
  800. *
  801. * 列出我的会话
  802. *
  803. * @param int|null $per_page 每页数量,最大 100 (optional, default to 30)
  804. * @param bool|null $filter_archived 只看已存档(true)或未存档(false)的;不传则全部 (optional)
  805. * @param int|null $page 页码 (optional, default to 1)
  806. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3MeAgentThreads'] to see the possible values for this operation
  807. *
  808. * @throws \InvalidArgumentException
  809. * @return \GuzzleHttp\Promise\PromiseInterface
  810. */
  811. public function getApiV3MeAgentThreadsAsync($per_page = 30, $filter_archived = null, $page = 1, string $contentType = self::contentTypes['getApiV3MeAgentThreads'][0])
  812. {
  813. return $this->getApiV3MeAgentThreadsAsyncWithHttpInfo($per_page, $filter_archived, $page, $contentType)
  814. ->then(
  815. function ($response) {
  816. return $response[0];
  817. }
  818. );
  819. }
  820. /**
  821. * Operation getApiV3MeAgentThreadsAsyncWithHttpInfo
  822. *
  823. * 列出我的会话
  824. *
  825. * @param int|null $per_page 每页数量,最大 100 (optional, default to 30)
  826. * @param bool|null $filter_archived 只看已存档(true)或未存档(false)的;不传则全部 (optional)
  827. * @param int|null $page 页码 (optional, default to 1)
  828. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3MeAgentThreads'] to see the possible values for this operation
  829. *
  830. * @throws \InvalidArgumentException
  831. * @return \GuzzleHttp\Promise\PromiseInterface
  832. */
  833. public function getApiV3MeAgentThreadsAsyncWithHttpInfo($per_page = 30, $filter_archived = null, $page = 1, string $contentType = self::contentTypes['getApiV3MeAgentThreads'][0])
  834. {
  835. $returnType = '\WikipaliApi\Model\GetApiV3MeAgentThreads200Response';
  836. $request = $this->getApiV3MeAgentThreadsRequest($per_page, $filter_archived, $page, $contentType);
  837. return $this->client
  838. ->sendAsync($request, $this->createHttpClientOption())
  839. ->then(
  840. function ($response) use ($returnType) {
  841. if ($returnType === '\SplFileObject') {
  842. $content = $response->getBody(); //stream goes to serializer
  843. } else {
  844. $content = (string) $response->getBody();
  845. if ($returnType !== 'string') {
  846. $content = json_decode($content);
  847. }
  848. }
  849. return [
  850. ObjectSerializer::deserialize($content, $returnType, []),
  851. $response->getStatusCode(),
  852. $response->getHeaders()
  853. ];
  854. },
  855. function ($exception) {
  856. $response = $exception->getResponse();
  857. $statusCode = $response->getStatusCode();
  858. throw new ApiException(
  859. sprintf(
  860. '[%d] Error connecting to the API (%s)',
  861. $statusCode,
  862. $exception->getRequest()->getUri()
  863. ),
  864. $statusCode,
  865. $response->getHeaders(),
  866. (string) $response->getBody()
  867. );
  868. }
  869. );
  870. }
  871. /**
  872. * Create request for operation 'getApiV3MeAgentThreads'
  873. *
  874. * @param int|null $per_page 每页数量,最大 100 (optional, default to 30)
  875. * @param bool|null $filter_archived 只看已存档(true)或未存档(false)的;不传则全部 (optional)
  876. * @param int|null $page 页码 (optional, default to 1)
  877. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3MeAgentThreads'] to see the possible values for this operation
  878. *
  879. * @throws \InvalidArgumentException
  880. * @return \GuzzleHttp\Psr7\Request
  881. */
  882. public function getApiV3MeAgentThreadsRequest($per_page = 30, $filter_archived = null, $page = 1, string $contentType = self::contentTypes['getApiV3MeAgentThreads'][0])
  883. {
  884. $resourcePath = '/v3/me/agent-threads';
  885. $formParams = [];
  886. $queryParams = [];
  887. $headerParams = [];
  888. $httpBody = '';
  889. $multipart = false;
  890. // query params
  891. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  892. $per_page,
  893. 'per_page', // param base name
  894. 'integer', // openApiType
  895. 'form', // style
  896. true, // explode
  897. false // required
  898. ) ?? []);
  899. // query params
  900. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  901. $filter_archived,
  902. 'filter[archived]', // param base name
  903. 'boolean', // openApiType
  904. 'form', // style
  905. true, // explode
  906. false // required
  907. ) ?? []);
  908. // query params
  909. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  910. $page,
  911. 'page', // param base name
  912. 'integer', // openApiType
  913. 'form', // style
  914. true, // explode
  915. false // required
  916. ) ?? []);
  917. $headers = $this->headerSelector->selectHeaders(
  918. ['application/json', 'application/problem+json', ],
  919. $contentType,
  920. $multipart
  921. );
  922. // for model (json/xml)
  923. if (count($formParams) > 0) {
  924. if ($multipart) {
  925. $multipartContents = [];
  926. foreach ($formParams as $formParamName => $formParamValue) {
  927. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  928. foreach ($formParamValueItems as $formParamValueItem) {
  929. $multipartContents[] = [
  930. 'name' => $formParamName,
  931. 'contents' => $formParamValueItem
  932. ];
  933. }
  934. }
  935. // for HTTP post (form)
  936. $httpBody = new MultipartStream($multipartContents);
  937. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  938. # if Content-Type contains "application/json", json_encode the form parameters
  939. try {
  940. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  941. } catch (\JsonException $e) {
  942. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  943. }
  944. } else {
  945. // for HTTP post (form)
  946. $httpBody = ObjectSerializer::buildQuery($formParams);
  947. }
  948. }
  949. // this endpoint requires Bearer authentication (access token)
  950. if (!empty($this->config->getAccessToken())) {
  951. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  952. }
  953. $defaultHeaders = [];
  954. if ($this->config->getUserAgent()) {
  955. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  956. }
  957. $headers = array_merge(
  958. $defaultHeaders,
  959. $headerParams,
  960. $headers
  961. );
  962. $operationHost = $this->config->getHost();
  963. $query = ObjectSerializer::buildQuery($queryParams);
  964. return new Request(
  965. 'GET',
  966. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  967. $headers,
  968. $httpBody
  969. );
  970. }
  971. /**
  972. * Operation getApiV3MeAgentThreadsThread
  973. *
  974. * 查看一个会话
  975. *
  976. * @param string $thread AG-UI threadId(uuid) (required)
  977. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3MeAgentThreadsThread'] to see the possible values for this operation
  978. *
  979. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  980. * @throws \InvalidArgumentException
  981. * @return \WikipaliApi\Model\GetApiV3MeAgentThreadsThread200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  982. */
  983. public function getApiV3MeAgentThreadsThread($thread, string $contentType = self::contentTypes['getApiV3MeAgentThreadsThread'][0])
  984. {
  985. list($response) = $this->getApiV3MeAgentThreadsThreadWithHttpInfo($thread, $contentType);
  986. return $response;
  987. }
  988. /**
  989. * Operation getApiV3MeAgentThreadsThreadWithHttpInfo
  990. *
  991. * 查看一个会话
  992. *
  993. * @param string $thread AG-UI threadId(uuid) (required)
  994. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3MeAgentThreadsThread'] to see the possible values for this operation
  995. *
  996. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  997. * @throws \InvalidArgumentException
  998. * @return array of \WikipaliApi\Model\GetApiV3MeAgentThreadsThread200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  999. */
  1000. public function getApiV3MeAgentThreadsThreadWithHttpInfo($thread, string $contentType = self::contentTypes['getApiV3MeAgentThreadsThread'][0])
  1001. {
  1002. $request = $this->getApiV3MeAgentThreadsThreadRequest($thread, $contentType);
  1003. try {
  1004. $options = $this->createHttpClientOption();
  1005. try {
  1006. $response = $this->client->send($request, $options);
  1007. } catch (RequestException $e) {
  1008. throw new ApiException(
  1009. "[{$e->getCode()}] {$e->getMessage()}",
  1010. (int) $e->getCode(),
  1011. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  1012. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  1013. );
  1014. } catch (ConnectException $e) {
  1015. throw new ApiException(
  1016. "[{$e->getCode()}] {$e->getMessage()}",
  1017. (int) $e->getCode(),
  1018. null,
  1019. null
  1020. );
  1021. }
  1022. $statusCode = $response->getStatusCode();
  1023. switch($statusCode) {
  1024. case 200:
  1025. return $this->handleResponseWithDataType(
  1026. '\WikipaliApi\Model\GetApiV3MeAgentThreadsThread200Response',
  1027. $request,
  1028. $response,
  1029. );
  1030. case 401:
  1031. return $this->handleResponseWithDataType(
  1032. '\WikipaliApi\Model\ProblemDetails',
  1033. $request,
  1034. $response,
  1035. );
  1036. case 422:
  1037. return $this->handleResponseWithDataType(
  1038. '\WikipaliApi\Model\ProblemDetails',
  1039. $request,
  1040. $response,
  1041. );
  1042. }
  1043. if ($statusCode < 200 || $statusCode > 299) {
  1044. throw new ApiException(
  1045. sprintf(
  1046. '[%d] Error connecting to the API (%s)',
  1047. $statusCode,
  1048. (string) $request->getUri()
  1049. ),
  1050. $statusCode,
  1051. $response->getHeaders(),
  1052. (string) $response->getBody()
  1053. );
  1054. }
  1055. return $this->handleResponseWithDataType(
  1056. '\WikipaliApi\Model\GetApiV3MeAgentThreadsThread200Response',
  1057. $request,
  1058. $response,
  1059. );
  1060. } catch (ApiException $e) {
  1061. switch ($e->getCode()) {
  1062. case 200:
  1063. $data = ObjectSerializer::deserialize(
  1064. $e->getResponseBody(),
  1065. '\WikipaliApi\Model\GetApiV3MeAgentThreadsThread200Response',
  1066. $e->getResponseHeaders()
  1067. );
  1068. $e->setResponseObject($data);
  1069. throw $e;
  1070. case 401:
  1071. $data = ObjectSerializer::deserialize(
  1072. $e->getResponseBody(),
  1073. '\WikipaliApi\Model\ProblemDetails',
  1074. $e->getResponseHeaders()
  1075. );
  1076. $e->setResponseObject($data);
  1077. throw $e;
  1078. case 422:
  1079. $data = ObjectSerializer::deserialize(
  1080. $e->getResponseBody(),
  1081. '\WikipaliApi\Model\ProblemDetails',
  1082. $e->getResponseHeaders()
  1083. );
  1084. $e->setResponseObject($data);
  1085. throw $e;
  1086. }
  1087. throw $e;
  1088. }
  1089. }
  1090. /**
  1091. * Operation getApiV3MeAgentThreadsThreadAsync
  1092. *
  1093. * 查看一个会话
  1094. *
  1095. * @param string $thread AG-UI threadId(uuid) (required)
  1096. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3MeAgentThreadsThread'] to see the possible values for this operation
  1097. *
  1098. * @throws \InvalidArgumentException
  1099. * @return \GuzzleHttp\Promise\PromiseInterface
  1100. */
  1101. public function getApiV3MeAgentThreadsThreadAsync($thread, string $contentType = self::contentTypes['getApiV3MeAgentThreadsThread'][0])
  1102. {
  1103. return $this->getApiV3MeAgentThreadsThreadAsyncWithHttpInfo($thread, $contentType)
  1104. ->then(
  1105. function ($response) {
  1106. return $response[0];
  1107. }
  1108. );
  1109. }
  1110. /**
  1111. * Operation getApiV3MeAgentThreadsThreadAsyncWithHttpInfo
  1112. *
  1113. * 查看一个会话
  1114. *
  1115. * @param string $thread AG-UI threadId(uuid) (required)
  1116. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3MeAgentThreadsThread'] to see the possible values for this operation
  1117. *
  1118. * @throws \InvalidArgumentException
  1119. * @return \GuzzleHttp\Promise\PromiseInterface
  1120. */
  1121. public function getApiV3MeAgentThreadsThreadAsyncWithHttpInfo($thread, string $contentType = self::contentTypes['getApiV3MeAgentThreadsThread'][0])
  1122. {
  1123. $returnType = '\WikipaliApi\Model\GetApiV3MeAgentThreadsThread200Response';
  1124. $request = $this->getApiV3MeAgentThreadsThreadRequest($thread, $contentType);
  1125. return $this->client
  1126. ->sendAsync($request, $this->createHttpClientOption())
  1127. ->then(
  1128. function ($response) use ($returnType) {
  1129. if ($returnType === '\SplFileObject') {
  1130. $content = $response->getBody(); //stream goes to serializer
  1131. } else {
  1132. $content = (string) $response->getBody();
  1133. if ($returnType !== 'string') {
  1134. $content = json_decode($content);
  1135. }
  1136. }
  1137. return [
  1138. ObjectSerializer::deserialize($content, $returnType, []),
  1139. $response->getStatusCode(),
  1140. $response->getHeaders()
  1141. ];
  1142. },
  1143. function ($exception) {
  1144. $response = $exception->getResponse();
  1145. $statusCode = $response->getStatusCode();
  1146. throw new ApiException(
  1147. sprintf(
  1148. '[%d] Error connecting to the API (%s)',
  1149. $statusCode,
  1150. $exception->getRequest()->getUri()
  1151. ),
  1152. $statusCode,
  1153. $response->getHeaders(),
  1154. (string) $response->getBody()
  1155. );
  1156. }
  1157. );
  1158. }
  1159. /**
  1160. * Create request for operation 'getApiV3MeAgentThreadsThread'
  1161. *
  1162. * @param string $thread AG-UI threadId(uuid) (required)
  1163. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3MeAgentThreadsThread'] to see the possible values for this operation
  1164. *
  1165. * @throws \InvalidArgumentException
  1166. * @return \GuzzleHttp\Psr7\Request
  1167. */
  1168. public function getApiV3MeAgentThreadsThreadRequest($thread, string $contentType = self::contentTypes['getApiV3MeAgentThreadsThread'][0])
  1169. {
  1170. // verify the required parameter 'thread' is set
  1171. if ($thread === null || (is_array($thread) && count($thread) === 0)) {
  1172. throw new \InvalidArgumentException(
  1173. 'Missing the required parameter $thread when calling getApiV3MeAgentThreadsThread'
  1174. );
  1175. }
  1176. $resourcePath = '/v3/me/agent-threads/{thread}';
  1177. $formParams = [];
  1178. $queryParams = [];
  1179. $headerParams = [];
  1180. $httpBody = '';
  1181. $multipart = false;
  1182. // path params
  1183. if ($thread !== null) {
  1184. $resourcePath = str_replace(
  1185. '{thread}',
  1186. ObjectSerializer::toPathValue($thread),
  1187. $resourcePath
  1188. );
  1189. }
  1190. $headers = $this->headerSelector->selectHeaders(
  1191. ['application/json', 'application/problem+json', ],
  1192. $contentType,
  1193. $multipart
  1194. );
  1195. // for model (json/xml)
  1196. if (count($formParams) > 0) {
  1197. if ($multipart) {
  1198. $multipartContents = [];
  1199. foreach ($formParams as $formParamName => $formParamValue) {
  1200. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  1201. foreach ($formParamValueItems as $formParamValueItem) {
  1202. $multipartContents[] = [
  1203. 'name' => $formParamName,
  1204. 'contents' => $formParamValueItem
  1205. ];
  1206. }
  1207. }
  1208. // for HTTP post (form)
  1209. $httpBody = new MultipartStream($multipartContents);
  1210. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  1211. # if Content-Type contains "application/json", json_encode the form parameters
  1212. try {
  1213. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  1214. } catch (\JsonException $e) {
  1215. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  1216. }
  1217. } else {
  1218. // for HTTP post (form)
  1219. $httpBody = ObjectSerializer::buildQuery($formParams);
  1220. }
  1221. }
  1222. // this endpoint requires Bearer authentication (access token)
  1223. if (!empty($this->config->getAccessToken())) {
  1224. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  1225. }
  1226. $defaultHeaders = [];
  1227. if ($this->config->getUserAgent()) {
  1228. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  1229. }
  1230. $headers = array_merge(
  1231. $defaultHeaders,
  1232. $headerParams,
  1233. $headers
  1234. );
  1235. $operationHost = $this->config->getHost();
  1236. $query = ObjectSerializer::buildQuery($queryParams);
  1237. return new Request(
  1238. 'GET',
  1239. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  1240. $headers,
  1241. $httpBody
  1242. );
  1243. }
  1244. /**
  1245. * Operation patchApiV3MeAgentThreadsThread
  1246. *
  1247. * 修改会话(目前只有标题)
  1248. *
  1249. * @param string $thread AG-UI threadId(uuid) (required)
  1250. * @param \WikipaliApi\Model\PatchApiV3MeAgentThreadsThreadRequest|null $patch_api_v3_me_agent_threads_thread_request patch_api_v3_me_agent_threads_thread_request (optional)
  1251. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3MeAgentThreadsThread'] to see the possible values for this operation
  1252. *
  1253. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  1254. * @throws \InvalidArgumentException
  1255. * @return \WikipaliApi\Model\GetApiV3MeAgentThreadsThread200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  1256. */
  1257. public function patchApiV3MeAgentThreadsThread($thread, $patch_api_v3_me_agent_threads_thread_request = null, string $contentType = self::contentTypes['patchApiV3MeAgentThreadsThread'][0])
  1258. {
  1259. list($response) = $this->patchApiV3MeAgentThreadsThreadWithHttpInfo($thread, $patch_api_v3_me_agent_threads_thread_request, $contentType);
  1260. return $response;
  1261. }
  1262. /**
  1263. * Operation patchApiV3MeAgentThreadsThreadWithHttpInfo
  1264. *
  1265. * 修改会话(目前只有标题)
  1266. *
  1267. * @param string $thread AG-UI threadId(uuid) (required)
  1268. * @param \WikipaliApi\Model\PatchApiV3MeAgentThreadsThreadRequest|null $patch_api_v3_me_agent_threads_thread_request (optional)
  1269. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3MeAgentThreadsThread'] to see the possible values for this operation
  1270. *
  1271. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  1272. * @throws \InvalidArgumentException
  1273. * @return array of \WikipaliApi\Model\GetApiV3MeAgentThreadsThread200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  1274. */
  1275. public function patchApiV3MeAgentThreadsThreadWithHttpInfo($thread, $patch_api_v3_me_agent_threads_thread_request = null, string $contentType = self::contentTypes['patchApiV3MeAgentThreadsThread'][0])
  1276. {
  1277. $request = $this->patchApiV3MeAgentThreadsThreadRequest($thread, $patch_api_v3_me_agent_threads_thread_request, $contentType);
  1278. try {
  1279. $options = $this->createHttpClientOption();
  1280. try {
  1281. $response = $this->client->send($request, $options);
  1282. } catch (RequestException $e) {
  1283. throw new ApiException(
  1284. "[{$e->getCode()}] {$e->getMessage()}",
  1285. (int) $e->getCode(),
  1286. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  1287. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  1288. );
  1289. } catch (ConnectException $e) {
  1290. throw new ApiException(
  1291. "[{$e->getCode()}] {$e->getMessage()}",
  1292. (int) $e->getCode(),
  1293. null,
  1294. null
  1295. );
  1296. }
  1297. $statusCode = $response->getStatusCode();
  1298. switch($statusCode) {
  1299. case 200:
  1300. return $this->handleResponseWithDataType(
  1301. '\WikipaliApi\Model\GetApiV3MeAgentThreadsThread200Response',
  1302. $request,
  1303. $response,
  1304. );
  1305. case 401:
  1306. return $this->handleResponseWithDataType(
  1307. '\WikipaliApi\Model\ProblemDetails',
  1308. $request,
  1309. $response,
  1310. );
  1311. case 422:
  1312. return $this->handleResponseWithDataType(
  1313. '\WikipaliApi\Model\ProblemDetails',
  1314. $request,
  1315. $response,
  1316. );
  1317. }
  1318. if ($statusCode < 200 || $statusCode > 299) {
  1319. throw new ApiException(
  1320. sprintf(
  1321. '[%d] Error connecting to the API (%s)',
  1322. $statusCode,
  1323. (string) $request->getUri()
  1324. ),
  1325. $statusCode,
  1326. $response->getHeaders(),
  1327. (string) $response->getBody()
  1328. );
  1329. }
  1330. return $this->handleResponseWithDataType(
  1331. '\WikipaliApi\Model\GetApiV3MeAgentThreadsThread200Response',
  1332. $request,
  1333. $response,
  1334. );
  1335. } catch (ApiException $e) {
  1336. switch ($e->getCode()) {
  1337. case 200:
  1338. $data = ObjectSerializer::deserialize(
  1339. $e->getResponseBody(),
  1340. '\WikipaliApi\Model\GetApiV3MeAgentThreadsThread200Response',
  1341. $e->getResponseHeaders()
  1342. );
  1343. $e->setResponseObject($data);
  1344. throw $e;
  1345. case 401:
  1346. $data = ObjectSerializer::deserialize(
  1347. $e->getResponseBody(),
  1348. '\WikipaliApi\Model\ProblemDetails',
  1349. $e->getResponseHeaders()
  1350. );
  1351. $e->setResponseObject($data);
  1352. throw $e;
  1353. case 422:
  1354. $data = ObjectSerializer::deserialize(
  1355. $e->getResponseBody(),
  1356. '\WikipaliApi\Model\ProblemDetails',
  1357. $e->getResponseHeaders()
  1358. );
  1359. $e->setResponseObject($data);
  1360. throw $e;
  1361. }
  1362. throw $e;
  1363. }
  1364. }
  1365. /**
  1366. * Operation patchApiV3MeAgentThreadsThreadAsync
  1367. *
  1368. * 修改会话(目前只有标题)
  1369. *
  1370. * @param string $thread AG-UI threadId(uuid) (required)
  1371. * @param \WikipaliApi\Model\PatchApiV3MeAgentThreadsThreadRequest|null $patch_api_v3_me_agent_threads_thread_request (optional)
  1372. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3MeAgentThreadsThread'] to see the possible values for this operation
  1373. *
  1374. * @throws \InvalidArgumentException
  1375. * @return \GuzzleHttp\Promise\PromiseInterface
  1376. */
  1377. public function patchApiV3MeAgentThreadsThreadAsync($thread, $patch_api_v3_me_agent_threads_thread_request = null, string $contentType = self::contentTypes['patchApiV3MeAgentThreadsThread'][0])
  1378. {
  1379. return $this->patchApiV3MeAgentThreadsThreadAsyncWithHttpInfo($thread, $patch_api_v3_me_agent_threads_thread_request, $contentType)
  1380. ->then(
  1381. function ($response) {
  1382. return $response[0];
  1383. }
  1384. );
  1385. }
  1386. /**
  1387. * Operation patchApiV3MeAgentThreadsThreadAsyncWithHttpInfo
  1388. *
  1389. * 修改会话(目前只有标题)
  1390. *
  1391. * @param string $thread AG-UI threadId(uuid) (required)
  1392. * @param \WikipaliApi\Model\PatchApiV3MeAgentThreadsThreadRequest|null $patch_api_v3_me_agent_threads_thread_request (optional)
  1393. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3MeAgentThreadsThread'] to see the possible values for this operation
  1394. *
  1395. * @throws \InvalidArgumentException
  1396. * @return \GuzzleHttp\Promise\PromiseInterface
  1397. */
  1398. public function patchApiV3MeAgentThreadsThreadAsyncWithHttpInfo($thread, $patch_api_v3_me_agent_threads_thread_request = null, string $contentType = self::contentTypes['patchApiV3MeAgentThreadsThread'][0])
  1399. {
  1400. $returnType = '\WikipaliApi\Model\GetApiV3MeAgentThreadsThread200Response';
  1401. $request = $this->patchApiV3MeAgentThreadsThreadRequest($thread, $patch_api_v3_me_agent_threads_thread_request, $contentType);
  1402. return $this->client
  1403. ->sendAsync($request, $this->createHttpClientOption())
  1404. ->then(
  1405. function ($response) use ($returnType) {
  1406. if ($returnType === '\SplFileObject') {
  1407. $content = $response->getBody(); //stream goes to serializer
  1408. } else {
  1409. $content = (string) $response->getBody();
  1410. if ($returnType !== 'string') {
  1411. $content = json_decode($content);
  1412. }
  1413. }
  1414. return [
  1415. ObjectSerializer::deserialize($content, $returnType, []),
  1416. $response->getStatusCode(),
  1417. $response->getHeaders()
  1418. ];
  1419. },
  1420. function ($exception) {
  1421. $response = $exception->getResponse();
  1422. $statusCode = $response->getStatusCode();
  1423. throw new ApiException(
  1424. sprintf(
  1425. '[%d] Error connecting to the API (%s)',
  1426. $statusCode,
  1427. $exception->getRequest()->getUri()
  1428. ),
  1429. $statusCode,
  1430. $response->getHeaders(),
  1431. (string) $response->getBody()
  1432. );
  1433. }
  1434. );
  1435. }
  1436. /**
  1437. * Create request for operation 'patchApiV3MeAgentThreadsThread'
  1438. *
  1439. * @param string $thread AG-UI threadId(uuid) (required)
  1440. * @param \WikipaliApi\Model\PatchApiV3MeAgentThreadsThreadRequest|null $patch_api_v3_me_agent_threads_thread_request (optional)
  1441. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['patchApiV3MeAgentThreadsThread'] to see the possible values for this operation
  1442. *
  1443. * @throws \InvalidArgumentException
  1444. * @return \GuzzleHttp\Psr7\Request
  1445. */
  1446. public function patchApiV3MeAgentThreadsThreadRequest($thread, $patch_api_v3_me_agent_threads_thread_request = null, string $contentType = self::contentTypes['patchApiV3MeAgentThreadsThread'][0])
  1447. {
  1448. // verify the required parameter 'thread' is set
  1449. if ($thread === null || (is_array($thread) && count($thread) === 0)) {
  1450. throw new \InvalidArgumentException(
  1451. 'Missing the required parameter $thread when calling patchApiV3MeAgentThreadsThread'
  1452. );
  1453. }
  1454. $resourcePath = '/v3/me/agent-threads/{thread}';
  1455. $formParams = [];
  1456. $queryParams = [];
  1457. $headerParams = [];
  1458. $httpBody = '';
  1459. $multipart = false;
  1460. // path params
  1461. if ($thread !== null) {
  1462. $resourcePath = str_replace(
  1463. '{thread}',
  1464. ObjectSerializer::toPathValue($thread),
  1465. $resourcePath
  1466. );
  1467. }
  1468. $headers = $this->headerSelector->selectHeaders(
  1469. ['application/json', 'application/problem+json', ],
  1470. $contentType,
  1471. $multipart
  1472. );
  1473. // for model (json/xml)
  1474. if (isset($patch_api_v3_me_agent_threads_thread_request)) {
  1475. if (stripos($headers['Content-Type'], 'application/json') !== false) {
  1476. # if Content-Type contains "application/json", json_encode the body
  1477. try {
  1478. $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($patch_api_v3_me_agent_threads_thread_request), JSON_THROW_ON_ERROR);
  1479. } catch (\JsonException $e) {
  1480. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  1481. }
  1482. } else {
  1483. $httpBody = $patch_api_v3_me_agent_threads_thread_request;
  1484. }
  1485. } elseif (count($formParams) > 0) {
  1486. if ($multipart) {
  1487. $multipartContents = [];
  1488. foreach ($formParams as $formParamName => $formParamValue) {
  1489. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  1490. foreach ($formParamValueItems as $formParamValueItem) {
  1491. $multipartContents[] = [
  1492. 'name' => $formParamName,
  1493. 'contents' => $formParamValueItem
  1494. ];
  1495. }
  1496. }
  1497. // for HTTP post (form)
  1498. $httpBody = new MultipartStream($multipartContents);
  1499. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  1500. # if Content-Type contains "application/json", json_encode the form parameters
  1501. try {
  1502. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  1503. } catch (\JsonException $e) {
  1504. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  1505. }
  1506. } else {
  1507. // for HTTP post (form)
  1508. $httpBody = ObjectSerializer::buildQuery($formParams);
  1509. }
  1510. }
  1511. // this endpoint requires Bearer authentication (access token)
  1512. if (!empty($this->config->getAccessToken())) {
  1513. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  1514. }
  1515. $defaultHeaders = [];
  1516. if ($this->config->getUserAgent()) {
  1517. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  1518. }
  1519. $headers = array_merge(
  1520. $defaultHeaders,
  1521. $headerParams,
  1522. $headers
  1523. );
  1524. $operationHost = $this->config->getHost();
  1525. $query = ObjectSerializer::buildQuery($queryParams);
  1526. return new Request(
  1527. 'PATCH',
  1528. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  1529. $headers,
  1530. $httpBody
  1531. );
  1532. }
  1533. /**
  1534. * Operation putApiV3MeAgentThreadsThreadArchive
  1535. *
  1536. * 存档会话
  1537. *
  1538. * @param string $thread AG-UI threadId(uuid) (required)
  1539. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['putApiV3MeAgentThreadsThreadArchive'] to see the possible values for this operation
  1540. *
  1541. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  1542. * @throws \InvalidArgumentException
  1543. * @return \WikipaliApi\Model\GetApiV3MeAgentThreadsThread200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails
  1544. */
  1545. public function putApiV3MeAgentThreadsThreadArchive($thread, string $contentType = self::contentTypes['putApiV3MeAgentThreadsThreadArchive'][0])
  1546. {
  1547. list($response) = $this->putApiV3MeAgentThreadsThreadArchiveWithHttpInfo($thread, $contentType);
  1548. return $response;
  1549. }
  1550. /**
  1551. * Operation putApiV3MeAgentThreadsThreadArchiveWithHttpInfo
  1552. *
  1553. * 存档会话
  1554. *
  1555. * @param string $thread AG-UI threadId(uuid) (required)
  1556. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['putApiV3MeAgentThreadsThreadArchive'] to see the possible values for this operation
  1557. *
  1558. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  1559. * @throws \InvalidArgumentException
  1560. * @return array of \WikipaliApi\Model\GetApiV3MeAgentThreadsThread200Response|\WikipaliApi\Model\ProblemDetails|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  1561. */
  1562. public function putApiV3MeAgentThreadsThreadArchiveWithHttpInfo($thread, string $contentType = self::contentTypes['putApiV3MeAgentThreadsThreadArchive'][0])
  1563. {
  1564. $request = $this->putApiV3MeAgentThreadsThreadArchiveRequest($thread, $contentType);
  1565. try {
  1566. $options = $this->createHttpClientOption();
  1567. try {
  1568. $response = $this->client->send($request, $options);
  1569. } catch (RequestException $e) {
  1570. throw new ApiException(
  1571. "[{$e->getCode()}] {$e->getMessage()}",
  1572. (int) $e->getCode(),
  1573. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  1574. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  1575. );
  1576. } catch (ConnectException $e) {
  1577. throw new ApiException(
  1578. "[{$e->getCode()}] {$e->getMessage()}",
  1579. (int) $e->getCode(),
  1580. null,
  1581. null
  1582. );
  1583. }
  1584. $statusCode = $response->getStatusCode();
  1585. switch($statusCode) {
  1586. case 200:
  1587. return $this->handleResponseWithDataType(
  1588. '\WikipaliApi\Model\GetApiV3MeAgentThreadsThread200Response',
  1589. $request,
  1590. $response,
  1591. );
  1592. case 401:
  1593. return $this->handleResponseWithDataType(
  1594. '\WikipaliApi\Model\ProblemDetails',
  1595. $request,
  1596. $response,
  1597. );
  1598. case 422:
  1599. return $this->handleResponseWithDataType(
  1600. '\WikipaliApi\Model\ProblemDetails',
  1601. $request,
  1602. $response,
  1603. );
  1604. }
  1605. if ($statusCode < 200 || $statusCode > 299) {
  1606. throw new ApiException(
  1607. sprintf(
  1608. '[%d] Error connecting to the API (%s)',
  1609. $statusCode,
  1610. (string) $request->getUri()
  1611. ),
  1612. $statusCode,
  1613. $response->getHeaders(),
  1614. (string) $response->getBody()
  1615. );
  1616. }
  1617. return $this->handleResponseWithDataType(
  1618. '\WikipaliApi\Model\GetApiV3MeAgentThreadsThread200Response',
  1619. $request,
  1620. $response,
  1621. );
  1622. } catch (ApiException $e) {
  1623. switch ($e->getCode()) {
  1624. case 200:
  1625. $data = ObjectSerializer::deserialize(
  1626. $e->getResponseBody(),
  1627. '\WikipaliApi\Model\GetApiV3MeAgentThreadsThread200Response',
  1628. $e->getResponseHeaders()
  1629. );
  1630. $e->setResponseObject($data);
  1631. throw $e;
  1632. case 401:
  1633. $data = ObjectSerializer::deserialize(
  1634. $e->getResponseBody(),
  1635. '\WikipaliApi\Model\ProblemDetails',
  1636. $e->getResponseHeaders()
  1637. );
  1638. $e->setResponseObject($data);
  1639. throw $e;
  1640. case 422:
  1641. $data = ObjectSerializer::deserialize(
  1642. $e->getResponseBody(),
  1643. '\WikipaliApi\Model\ProblemDetails',
  1644. $e->getResponseHeaders()
  1645. );
  1646. $e->setResponseObject($data);
  1647. throw $e;
  1648. }
  1649. throw $e;
  1650. }
  1651. }
  1652. /**
  1653. * Operation putApiV3MeAgentThreadsThreadArchiveAsync
  1654. *
  1655. * 存档会话
  1656. *
  1657. * @param string $thread AG-UI threadId(uuid) (required)
  1658. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['putApiV3MeAgentThreadsThreadArchive'] to see the possible values for this operation
  1659. *
  1660. * @throws \InvalidArgumentException
  1661. * @return \GuzzleHttp\Promise\PromiseInterface
  1662. */
  1663. public function putApiV3MeAgentThreadsThreadArchiveAsync($thread, string $contentType = self::contentTypes['putApiV3MeAgentThreadsThreadArchive'][0])
  1664. {
  1665. return $this->putApiV3MeAgentThreadsThreadArchiveAsyncWithHttpInfo($thread, $contentType)
  1666. ->then(
  1667. function ($response) {
  1668. return $response[0];
  1669. }
  1670. );
  1671. }
  1672. /**
  1673. * Operation putApiV3MeAgentThreadsThreadArchiveAsyncWithHttpInfo
  1674. *
  1675. * 存档会话
  1676. *
  1677. * @param string $thread AG-UI threadId(uuid) (required)
  1678. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['putApiV3MeAgentThreadsThreadArchive'] to see the possible values for this operation
  1679. *
  1680. * @throws \InvalidArgumentException
  1681. * @return \GuzzleHttp\Promise\PromiseInterface
  1682. */
  1683. public function putApiV3MeAgentThreadsThreadArchiveAsyncWithHttpInfo($thread, string $contentType = self::contentTypes['putApiV3MeAgentThreadsThreadArchive'][0])
  1684. {
  1685. $returnType = '\WikipaliApi\Model\GetApiV3MeAgentThreadsThread200Response';
  1686. $request = $this->putApiV3MeAgentThreadsThreadArchiveRequest($thread, $contentType);
  1687. return $this->client
  1688. ->sendAsync($request, $this->createHttpClientOption())
  1689. ->then(
  1690. function ($response) use ($returnType) {
  1691. if ($returnType === '\SplFileObject') {
  1692. $content = $response->getBody(); //stream goes to serializer
  1693. } else {
  1694. $content = (string) $response->getBody();
  1695. if ($returnType !== 'string') {
  1696. $content = json_decode($content);
  1697. }
  1698. }
  1699. return [
  1700. ObjectSerializer::deserialize($content, $returnType, []),
  1701. $response->getStatusCode(),
  1702. $response->getHeaders()
  1703. ];
  1704. },
  1705. function ($exception) {
  1706. $response = $exception->getResponse();
  1707. $statusCode = $response->getStatusCode();
  1708. throw new ApiException(
  1709. sprintf(
  1710. '[%d] Error connecting to the API (%s)',
  1711. $statusCode,
  1712. $exception->getRequest()->getUri()
  1713. ),
  1714. $statusCode,
  1715. $response->getHeaders(),
  1716. (string) $response->getBody()
  1717. );
  1718. }
  1719. );
  1720. }
  1721. /**
  1722. * Create request for operation 'putApiV3MeAgentThreadsThreadArchive'
  1723. *
  1724. * @param string $thread AG-UI threadId(uuid) (required)
  1725. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['putApiV3MeAgentThreadsThreadArchive'] to see the possible values for this operation
  1726. *
  1727. * @throws \InvalidArgumentException
  1728. * @return \GuzzleHttp\Psr7\Request
  1729. */
  1730. public function putApiV3MeAgentThreadsThreadArchiveRequest($thread, string $contentType = self::contentTypes['putApiV3MeAgentThreadsThreadArchive'][0])
  1731. {
  1732. // verify the required parameter 'thread' is set
  1733. if ($thread === null || (is_array($thread) && count($thread) === 0)) {
  1734. throw new \InvalidArgumentException(
  1735. 'Missing the required parameter $thread when calling putApiV3MeAgentThreadsThreadArchive'
  1736. );
  1737. }
  1738. $resourcePath = '/v3/me/agent-threads/{thread}/archive';
  1739. $formParams = [];
  1740. $queryParams = [];
  1741. $headerParams = [];
  1742. $httpBody = '';
  1743. $multipart = false;
  1744. // path params
  1745. if ($thread !== null) {
  1746. $resourcePath = str_replace(
  1747. '{thread}',
  1748. ObjectSerializer::toPathValue($thread),
  1749. $resourcePath
  1750. );
  1751. }
  1752. $headers = $this->headerSelector->selectHeaders(
  1753. ['application/json', 'application/problem+json', ],
  1754. $contentType,
  1755. $multipart
  1756. );
  1757. // for model (json/xml)
  1758. if (count($formParams) > 0) {
  1759. if ($multipart) {
  1760. $multipartContents = [];
  1761. foreach ($formParams as $formParamName => $formParamValue) {
  1762. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  1763. foreach ($formParamValueItems as $formParamValueItem) {
  1764. $multipartContents[] = [
  1765. 'name' => $formParamName,
  1766. 'contents' => $formParamValueItem
  1767. ];
  1768. }
  1769. }
  1770. // for HTTP post (form)
  1771. $httpBody = new MultipartStream($multipartContents);
  1772. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  1773. # if Content-Type contains "application/json", json_encode the form parameters
  1774. try {
  1775. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  1776. } catch (\JsonException $e) {
  1777. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  1778. }
  1779. } else {
  1780. // for HTTP post (form)
  1781. $httpBody = ObjectSerializer::buildQuery($formParams);
  1782. }
  1783. }
  1784. // this endpoint requires Bearer authentication (access token)
  1785. if (!empty($this->config->getAccessToken())) {
  1786. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  1787. }
  1788. $defaultHeaders = [];
  1789. if ($this->config->getUserAgent()) {
  1790. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  1791. }
  1792. $headers = array_merge(
  1793. $defaultHeaders,
  1794. $headerParams,
  1795. $headers
  1796. );
  1797. $operationHost = $this->config->getHost();
  1798. $query = ObjectSerializer::buildQuery($queryParams);
  1799. return new Request(
  1800. 'PUT',
  1801. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  1802. $headers,
  1803. $httpBody
  1804. );
  1805. }
  1806. /**
  1807. * Create http client option
  1808. *
  1809. * @throws \RuntimeException on file opening failure
  1810. * @return array of http client options
  1811. */
  1812. protected function createHttpClientOption()
  1813. {
  1814. $options = [];
  1815. if ($this->config->getDebug()) {
  1816. $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
  1817. if (!$options[RequestOptions::DEBUG]) {
  1818. throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
  1819. }
  1820. }
  1821. if ($this->config->getCertFile()) {
  1822. $options[RequestOptions::CERT] = $this->config->getCertFile();
  1823. }
  1824. if ($this->config->getKeyFile()) {
  1825. $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile();
  1826. }
  1827. return $options;
  1828. }
  1829. private function handleResponseWithDataType(
  1830. string $dataType,
  1831. RequestInterface $request,
  1832. ResponseInterface $response
  1833. ): array {
  1834. if ($dataType === '\SplFileObject') {
  1835. $content = $response->getBody(); //stream goes to serializer
  1836. } else {
  1837. $content = (string) $response->getBody();
  1838. if ($dataType !== 'string') {
  1839. try {
  1840. $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
  1841. } catch (\JsonException $exception) {
  1842. throw new ApiException(
  1843. sprintf(
  1844. 'Error JSON decoding server response (%s)',
  1845. $request->getUri()
  1846. ),
  1847. $response->getStatusCode(),
  1848. $response->getHeaders(),
  1849. $content
  1850. );
  1851. }
  1852. }
  1853. }
  1854. return [
  1855. ObjectSerializer::deserialize($content, $dataType, []),
  1856. $response->getStatusCode(),
  1857. $response->getHeaders()
  1858. ];
  1859. }
  1860. private function responseWithinRangeCode(
  1861. string $rangeCode,
  1862. int $statusCode
  1863. ): bool {
  1864. $left = (int) ($rangeCode[0].'00');
  1865. $right = (int) ($rangeCode[0].'99');
  1866. return $statusCode >= $left && $statusCode <= $right;
  1867. }
  1868. }