session.go 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667
  1. // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
  2. package opencode
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "net/http"
  8. "reflect"
  9. "github.com/sst/opencode-sdk-go/internal/apijson"
  10. "github.com/sst/opencode-sdk-go/internal/param"
  11. "github.com/sst/opencode-sdk-go/internal/requestconfig"
  12. "github.com/sst/opencode-sdk-go/option"
  13. "github.com/sst/opencode-sdk-go/shared"
  14. "github.com/tidwall/gjson"
  15. )
  16. // SessionService contains methods and other services that help with interacting
  17. // with the opencode API.
  18. //
  19. // Note, unlike clients, this service does not read variables from the environment
  20. // automatically. You should not instantiate this service directly, and instead use
  21. // the [NewSessionService] method instead.
  22. type SessionService struct {
  23. Options []option.RequestOption
  24. }
  25. // NewSessionService generates a new service that applies the given options to each
  26. // request. These options are applied after the parent client's options (if there
  27. // is one), and before any request-specific options.
  28. func NewSessionService(opts ...option.RequestOption) (r *SessionService) {
  29. r = &SessionService{}
  30. r.Options = opts
  31. return
  32. }
  33. // Create a new session
  34. func (r *SessionService) New(ctx context.Context, opts ...option.RequestOption) (res *Session, err error) {
  35. opts = append(r.Options[:], opts...)
  36. path := "session"
  37. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
  38. return
  39. }
  40. // List all sessions
  41. func (r *SessionService) List(ctx context.Context, opts ...option.RequestOption) (res *[]Session, err error) {
  42. opts = append(r.Options[:], opts...)
  43. path := "session"
  44. err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
  45. return
  46. }
  47. // Delete a session and all its data
  48. func (r *SessionService) Delete(ctx context.Context, id string, opts ...option.RequestOption) (res *bool, err error) {
  49. opts = append(r.Options[:], opts...)
  50. if id == "" {
  51. err = errors.New("missing required id parameter")
  52. return
  53. }
  54. path := fmt.Sprintf("session/%s", id)
  55. err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
  56. return
  57. }
  58. // Abort a session
  59. func (r *SessionService) Abort(ctx context.Context, id string, opts ...option.RequestOption) (res *bool, err error) {
  60. opts = append(r.Options[:], opts...)
  61. if id == "" {
  62. err = errors.New("missing required id parameter")
  63. return
  64. }
  65. path := fmt.Sprintf("session/%s/abort", id)
  66. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
  67. return
  68. }
  69. // Create and send a new message to a session
  70. func (r *SessionService) Chat(ctx context.Context, id string, body SessionChatParams, opts ...option.RequestOption) (res *AssistantMessage, err error) {
  71. opts = append(r.Options[:], opts...)
  72. if id == "" {
  73. err = errors.New("missing required id parameter")
  74. return
  75. }
  76. path := fmt.Sprintf("session/%s/message", id)
  77. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
  78. return
  79. }
  80. // Analyze the app and create an AGENTS.md file
  81. func (r *SessionService) Init(ctx context.Context, id string, body SessionInitParams, opts ...option.RequestOption) (res *bool, err error) {
  82. opts = append(r.Options[:], opts...)
  83. if id == "" {
  84. err = errors.New("missing required id parameter")
  85. return
  86. }
  87. path := fmt.Sprintf("session/%s/init", id)
  88. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
  89. return
  90. }
  91. // List messages for a session
  92. func (r *SessionService) Messages(ctx context.Context, id string, opts ...option.RequestOption) (res *[]SessionMessagesResponse, err error) {
  93. opts = append(r.Options[:], opts...)
  94. if id == "" {
  95. err = errors.New("missing required id parameter")
  96. return
  97. }
  98. path := fmt.Sprintf("session/%s/message", id)
  99. err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
  100. return
  101. }
  102. // Share a session
  103. func (r *SessionService) Share(ctx context.Context, id string, opts ...option.RequestOption) (res *Session, err error) {
  104. opts = append(r.Options[:], opts...)
  105. if id == "" {
  106. err = errors.New("missing required id parameter")
  107. return
  108. }
  109. path := fmt.Sprintf("session/%s/share", id)
  110. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
  111. return
  112. }
  113. // Summarize the session
  114. func (r *SessionService) Summarize(ctx context.Context, id string, body SessionSummarizeParams, opts ...option.RequestOption) (res *bool, err error) {
  115. opts = append(r.Options[:], opts...)
  116. if id == "" {
  117. err = errors.New("missing required id parameter")
  118. return
  119. }
  120. path := fmt.Sprintf("session/%s/summarize", id)
  121. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
  122. return
  123. }
  124. // Unshare the session
  125. func (r *SessionService) Unshare(ctx context.Context, id string, opts ...option.RequestOption) (res *Session, err error) {
  126. opts = append(r.Options[:], opts...)
  127. if id == "" {
  128. err = errors.New("missing required id parameter")
  129. return
  130. }
  131. path := fmt.Sprintf("session/%s/share", id)
  132. err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
  133. return
  134. }
  135. type AssistantMessage struct {
  136. ID string `json:"id,required"`
  137. Cost float64 `json:"cost,required"`
  138. ModelID string `json:"modelID,required"`
  139. Path AssistantMessagePath `json:"path,required"`
  140. ProviderID string `json:"providerID,required"`
  141. Role AssistantMessageRole `json:"role,required"`
  142. SessionID string `json:"sessionID,required"`
  143. System []string `json:"system,required"`
  144. Time AssistantMessageTime `json:"time,required"`
  145. Tokens AssistantMessageTokens `json:"tokens,required"`
  146. Error AssistantMessageError `json:"error"`
  147. Summary bool `json:"summary"`
  148. JSON assistantMessageJSON `json:"-"`
  149. }
  150. // assistantMessageJSON contains the JSON metadata for the struct
  151. // [AssistantMessage]
  152. type assistantMessageJSON struct {
  153. ID apijson.Field
  154. Cost apijson.Field
  155. ModelID apijson.Field
  156. Path apijson.Field
  157. ProviderID apijson.Field
  158. Role apijson.Field
  159. SessionID apijson.Field
  160. System apijson.Field
  161. Time apijson.Field
  162. Tokens apijson.Field
  163. Error apijson.Field
  164. Summary apijson.Field
  165. raw string
  166. ExtraFields map[string]apijson.Field
  167. }
  168. func (r *AssistantMessage) UnmarshalJSON(data []byte) (err error) {
  169. return apijson.UnmarshalRoot(data, r)
  170. }
  171. func (r assistantMessageJSON) RawJSON() string {
  172. return r.raw
  173. }
  174. func (r AssistantMessage) implementsMessage() {}
  175. type AssistantMessagePath struct {
  176. Cwd string `json:"cwd,required"`
  177. Root string `json:"root,required"`
  178. JSON assistantMessagePathJSON `json:"-"`
  179. }
  180. // assistantMessagePathJSON contains the JSON metadata for the struct
  181. // [AssistantMessagePath]
  182. type assistantMessagePathJSON struct {
  183. Cwd apijson.Field
  184. Root apijson.Field
  185. raw string
  186. ExtraFields map[string]apijson.Field
  187. }
  188. func (r *AssistantMessagePath) UnmarshalJSON(data []byte) (err error) {
  189. return apijson.UnmarshalRoot(data, r)
  190. }
  191. func (r assistantMessagePathJSON) RawJSON() string {
  192. return r.raw
  193. }
  194. type AssistantMessageRole string
  195. const (
  196. AssistantMessageRoleAssistant AssistantMessageRole = "assistant"
  197. )
  198. func (r AssistantMessageRole) IsKnown() bool {
  199. switch r {
  200. case AssistantMessageRoleAssistant:
  201. return true
  202. }
  203. return false
  204. }
  205. type AssistantMessageTime struct {
  206. Created float64 `json:"created,required"`
  207. Completed float64 `json:"completed"`
  208. JSON assistantMessageTimeJSON `json:"-"`
  209. }
  210. // assistantMessageTimeJSON contains the JSON metadata for the struct
  211. // [AssistantMessageTime]
  212. type assistantMessageTimeJSON struct {
  213. Created apijson.Field
  214. Completed apijson.Field
  215. raw string
  216. ExtraFields map[string]apijson.Field
  217. }
  218. func (r *AssistantMessageTime) UnmarshalJSON(data []byte) (err error) {
  219. return apijson.UnmarshalRoot(data, r)
  220. }
  221. func (r assistantMessageTimeJSON) RawJSON() string {
  222. return r.raw
  223. }
  224. type AssistantMessageTokens struct {
  225. Cache AssistantMessageTokensCache `json:"cache,required"`
  226. Input float64 `json:"input,required"`
  227. Output float64 `json:"output,required"`
  228. Reasoning float64 `json:"reasoning,required"`
  229. JSON assistantMessageTokensJSON `json:"-"`
  230. }
  231. // assistantMessageTokensJSON contains the JSON metadata for the struct
  232. // [AssistantMessageTokens]
  233. type assistantMessageTokensJSON struct {
  234. Cache apijson.Field
  235. Input apijson.Field
  236. Output apijson.Field
  237. Reasoning apijson.Field
  238. raw string
  239. ExtraFields map[string]apijson.Field
  240. }
  241. func (r *AssistantMessageTokens) UnmarshalJSON(data []byte) (err error) {
  242. return apijson.UnmarshalRoot(data, r)
  243. }
  244. func (r assistantMessageTokensJSON) RawJSON() string {
  245. return r.raw
  246. }
  247. type AssistantMessageTokensCache struct {
  248. Read float64 `json:"read,required"`
  249. Write float64 `json:"write,required"`
  250. JSON assistantMessageTokensCacheJSON `json:"-"`
  251. }
  252. // assistantMessageTokensCacheJSON contains the JSON metadata for the struct
  253. // [AssistantMessageTokensCache]
  254. type assistantMessageTokensCacheJSON struct {
  255. Read apijson.Field
  256. Write apijson.Field
  257. raw string
  258. ExtraFields map[string]apijson.Field
  259. }
  260. func (r *AssistantMessageTokensCache) UnmarshalJSON(data []byte) (err error) {
  261. return apijson.UnmarshalRoot(data, r)
  262. }
  263. func (r assistantMessageTokensCacheJSON) RawJSON() string {
  264. return r.raw
  265. }
  266. type AssistantMessageError struct {
  267. // This field can have the runtime type of [shared.ProviderAuthErrorData],
  268. // [shared.UnknownErrorData], [interface{}].
  269. Data interface{} `json:"data,required"`
  270. Name AssistantMessageErrorName `json:"name,required"`
  271. JSON assistantMessageErrorJSON `json:"-"`
  272. union AssistantMessageErrorUnion
  273. }
  274. // assistantMessageErrorJSON contains the JSON metadata for the struct
  275. // [AssistantMessageError]
  276. type assistantMessageErrorJSON struct {
  277. Data apijson.Field
  278. Name apijson.Field
  279. raw string
  280. ExtraFields map[string]apijson.Field
  281. }
  282. func (r assistantMessageErrorJSON) RawJSON() string {
  283. return r.raw
  284. }
  285. func (r *AssistantMessageError) UnmarshalJSON(data []byte) (err error) {
  286. *r = AssistantMessageError{}
  287. err = apijson.UnmarshalRoot(data, &r.union)
  288. if err != nil {
  289. return err
  290. }
  291. return apijson.Port(r.union, &r)
  292. }
  293. // AsUnion returns a [AssistantMessageErrorUnion] interface which you can cast to
  294. // the specific types for more type safety.
  295. //
  296. // Possible runtime types of the union are [shared.ProviderAuthError],
  297. // [shared.UnknownError], [AssistantMessageErrorMessageOutputLengthError],
  298. // [shared.MessageAbortedError].
  299. func (r AssistantMessageError) AsUnion() AssistantMessageErrorUnion {
  300. return r.union
  301. }
  302. // Union satisfied by [shared.ProviderAuthError], [shared.UnknownError],
  303. // [AssistantMessageErrorMessageOutputLengthError] or [shared.MessageAbortedError].
  304. type AssistantMessageErrorUnion interface {
  305. ImplementsAssistantMessageError()
  306. }
  307. func init() {
  308. apijson.RegisterUnion(
  309. reflect.TypeOf((*AssistantMessageErrorUnion)(nil)).Elem(),
  310. "name",
  311. apijson.UnionVariant{
  312. TypeFilter: gjson.JSON,
  313. Type: reflect.TypeOf(shared.ProviderAuthError{}),
  314. DiscriminatorValue: "ProviderAuthError",
  315. },
  316. apijson.UnionVariant{
  317. TypeFilter: gjson.JSON,
  318. Type: reflect.TypeOf(shared.UnknownError{}),
  319. DiscriminatorValue: "UnknownError",
  320. },
  321. apijson.UnionVariant{
  322. TypeFilter: gjson.JSON,
  323. Type: reflect.TypeOf(AssistantMessageErrorMessageOutputLengthError{}),
  324. DiscriminatorValue: "MessageOutputLengthError",
  325. },
  326. apijson.UnionVariant{
  327. TypeFilter: gjson.JSON,
  328. Type: reflect.TypeOf(shared.MessageAbortedError{}),
  329. DiscriminatorValue: "MessageAbortedError",
  330. },
  331. )
  332. }
  333. type AssistantMessageErrorMessageOutputLengthError struct {
  334. Data interface{} `json:"data,required"`
  335. Name AssistantMessageErrorMessageOutputLengthErrorName `json:"name,required"`
  336. JSON assistantMessageErrorMessageOutputLengthErrorJSON `json:"-"`
  337. }
  338. // assistantMessageErrorMessageOutputLengthErrorJSON contains the JSON metadata for
  339. // the struct [AssistantMessageErrorMessageOutputLengthError]
  340. type assistantMessageErrorMessageOutputLengthErrorJSON struct {
  341. Data apijson.Field
  342. Name apijson.Field
  343. raw string
  344. ExtraFields map[string]apijson.Field
  345. }
  346. func (r *AssistantMessageErrorMessageOutputLengthError) UnmarshalJSON(data []byte) (err error) {
  347. return apijson.UnmarshalRoot(data, r)
  348. }
  349. func (r assistantMessageErrorMessageOutputLengthErrorJSON) RawJSON() string {
  350. return r.raw
  351. }
  352. func (r AssistantMessageErrorMessageOutputLengthError) ImplementsAssistantMessageError() {}
  353. type AssistantMessageErrorMessageOutputLengthErrorName string
  354. const (
  355. AssistantMessageErrorMessageOutputLengthErrorNameMessageOutputLengthError AssistantMessageErrorMessageOutputLengthErrorName = "MessageOutputLengthError"
  356. )
  357. func (r AssistantMessageErrorMessageOutputLengthErrorName) IsKnown() bool {
  358. switch r {
  359. case AssistantMessageErrorMessageOutputLengthErrorNameMessageOutputLengthError:
  360. return true
  361. }
  362. return false
  363. }
  364. type AssistantMessageErrorName string
  365. const (
  366. AssistantMessageErrorNameProviderAuthError AssistantMessageErrorName = "ProviderAuthError"
  367. AssistantMessageErrorNameUnknownError AssistantMessageErrorName = "UnknownError"
  368. AssistantMessageErrorNameMessageOutputLengthError AssistantMessageErrorName = "MessageOutputLengthError"
  369. AssistantMessageErrorNameMessageAbortedError AssistantMessageErrorName = "MessageAbortedError"
  370. )
  371. func (r AssistantMessageErrorName) IsKnown() bool {
  372. switch r {
  373. case AssistantMessageErrorNameProviderAuthError, AssistantMessageErrorNameUnknownError, AssistantMessageErrorNameMessageOutputLengthError, AssistantMessageErrorNameMessageAbortedError:
  374. return true
  375. }
  376. return false
  377. }
  378. type FilePart struct {
  379. ID string `json:"id,required"`
  380. MessageID string `json:"messageID,required"`
  381. Mime string `json:"mime,required"`
  382. SessionID string `json:"sessionID,required"`
  383. Type FilePartType `json:"type,required"`
  384. URL string `json:"url,required"`
  385. Filename string `json:"filename"`
  386. JSON filePartJSON `json:"-"`
  387. }
  388. // filePartJSON contains the JSON metadata for the struct [FilePart]
  389. type filePartJSON struct {
  390. ID apijson.Field
  391. MessageID apijson.Field
  392. Mime apijson.Field
  393. SessionID apijson.Field
  394. Type apijson.Field
  395. URL apijson.Field
  396. Filename apijson.Field
  397. raw string
  398. ExtraFields map[string]apijson.Field
  399. }
  400. func (r *FilePart) UnmarshalJSON(data []byte) (err error) {
  401. return apijson.UnmarshalRoot(data, r)
  402. }
  403. func (r filePartJSON) RawJSON() string {
  404. return r.raw
  405. }
  406. func (r FilePart) implementsPart() {}
  407. type FilePartType string
  408. const (
  409. FilePartTypeFile FilePartType = "file"
  410. )
  411. func (r FilePartType) IsKnown() bool {
  412. switch r {
  413. case FilePartTypeFile:
  414. return true
  415. }
  416. return false
  417. }
  418. type FilePartInputParam struct {
  419. Mime param.Field[string] `json:"mime,required"`
  420. Type param.Field[FilePartInputType] `json:"type,required"`
  421. URL param.Field[string] `json:"url,required"`
  422. ID param.Field[string] `json:"id"`
  423. Filename param.Field[string] `json:"filename"`
  424. }
  425. func (r FilePartInputParam) MarshalJSON() (data []byte, err error) {
  426. return apijson.MarshalRoot(r)
  427. }
  428. func (r FilePartInputParam) implementsSessionChatParamsPartUnion() {}
  429. type FilePartInputType string
  430. const (
  431. FilePartInputTypeFile FilePartInputType = "file"
  432. )
  433. func (r FilePartInputType) IsKnown() bool {
  434. switch r {
  435. case FilePartInputTypeFile:
  436. return true
  437. }
  438. return false
  439. }
  440. type Message struct {
  441. ID string `json:"id,required"`
  442. Role MessageRole `json:"role,required"`
  443. SessionID string `json:"sessionID,required"`
  444. // This field can have the runtime type of [UserMessageTime],
  445. // [AssistantMessageTime].
  446. Time interface{} `json:"time,required"`
  447. Cost float64 `json:"cost"`
  448. // This field can have the runtime type of [AssistantMessageError].
  449. Error interface{} `json:"error"`
  450. ModelID string `json:"modelID"`
  451. // This field can have the runtime type of [AssistantMessagePath].
  452. Path interface{} `json:"path"`
  453. ProviderID string `json:"providerID"`
  454. Summary bool `json:"summary"`
  455. // This field can have the runtime type of [[]string].
  456. System interface{} `json:"system"`
  457. // This field can have the runtime type of [AssistantMessageTokens].
  458. Tokens interface{} `json:"tokens"`
  459. JSON messageJSON `json:"-"`
  460. union MessageUnion
  461. }
  462. // messageJSON contains the JSON metadata for the struct [Message]
  463. type messageJSON struct {
  464. ID apijson.Field
  465. Role apijson.Field
  466. SessionID apijson.Field
  467. Time apijson.Field
  468. Cost apijson.Field
  469. Error apijson.Field
  470. ModelID apijson.Field
  471. Path apijson.Field
  472. ProviderID apijson.Field
  473. Summary apijson.Field
  474. System apijson.Field
  475. Tokens apijson.Field
  476. raw string
  477. ExtraFields map[string]apijson.Field
  478. }
  479. func (r messageJSON) RawJSON() string {
  480. return r.raw
  481. }
  482. func (r *Message) UnmarshalJSON(data []byte) (err error) {
  483. *r = Message{}
  484. err = apijson.UnmarshalRoot(data, &r.union)
  485. if err != nil {
  486. return err
  487. }
  488. return apijson.Port(r.union, &r)
  489. }
  490. // AsUnion returns a [MessageUnion] interface which you can cast to the specific
  491. // types for more type safety.
  492. //
  493. // Possible runtime types of the union are [UserMessage], [AssistantMessage].
  494. func (r Message) AsUnion() MessageUnion {
  495. return r.union
  496. }
  497. // Union satisfied by [UserMessage] or [AssistantMessage].
  498. type MessageUnion interface {
  499. implementsMessage()
  500. }
  501. func init() {
  502. apijson.RegisterUnion(
  503. reflect.TypeOf((*MessageUnion)(nil)).Elem(),
  504. "role",
  505. apijson.UnionVariant{
  506. TypeFilter: gjson.JSON,
  507. Type: reflect.TypeOf(UserMessage{}),
  508. DiscriminatorValue: "user",
  509. },
  510. apijson.UnionVariant{
  511. TypeFilter: gjson.JSON,
  512. Type: reflect.TypeOf(AssistantMessage{}),
  513. DiscriminatorValue: "assistant",
  514. },
  515. )
  516. }
  517. type MessageRole string
  518. const (
  519. MessageRoleUser MessageRole = "user"
  520. MessageRoleAssistant MessageRole = "assistant"
  521. )
  522. func (r MessageRole) IsKnown() bool {
  523. switch r {
  524. case MessageRoleUser, MessageRoleAssistant:
  525. return true
  526. }
  527. return false
  528. }
  529. type Part struct {
  530. ID string `json:"id,required"`
  531. MessageID string `json:"messageID,required"`
  532. SessionID string `json:"sessionID,required"`
  533. Type PartType `json:"type,required"`
  534. CallID string `json:"callID"`
  535. Cost float64 `json:"cost"`
  536. Filename string `json:"filename"`
  537. Mime string `json:"mime"`
  538. Snapshot string `json:"snapshot"`
  539. // This field can have the runtime type of [ToolPartState].
  540. State interface{} `json:"state"`
  541. Synthetic bool `json:"synthetic"`
  542. Text string `json:"text"`
  543. // This field can have the runtime type of [TextPartTime].
  544. Time interface{} `json:"time"`
  545. // This field can have the runtime type of [StepFinishPartTokens].
  546. Tokens interface{} `json:"tokens"`
  547. Tool string `json:"tool"`
  548. URL string `json:"url"`
  549. JSON partJSON `json:"-"`
  550. union PartUnion
  551. }
  552. // partJSON contains the JSON metadata for the struct [Part]
  553. type partJSON struct {
  554. ID apijson.Field
  555. MessageID apijson.Field
  556. SessionID apijson.Field
  557. Type apijson.Field
  558. CallID apijson.Field
  559. Cost apijson.Field
  560. Filename apijson.Field
  561. Mime apijson.Field
  562. Snapshot apijson.Field
  563. State apijson.Field
  564. Synthetic apijson.Field
  565. Text apijson.Field
  566. Time apijson.Field
  567. Tokens apijson.Field
  568. Tool apijson.Field
  569. URL apijson.Field
  570. raw string
  571. ExtraFields map[string]apijson.Field
  572. }
  573. func (r partJSON) RawJSON() string {
  574. return r.raw
  575. }
  576. func (r *Part) UnmarshalJSON(data []byte) (err error) {
  577. *r = Part{}
  578. err = apijson.UnmarshalRoot(data, &r.union)
  579. if err != nil {
  580. return err
  581. }
  582. return apijson.Port(r.union, &r)
  583. }
  584. // AsUnion returns a [PartUnion] interface which you can cast to the specific types
  585. // for more type safety.
  586. //
  587. // Possible runtime types of the union are [TextPart], [FilePart], [ToolPart],
  588. // [StepStartPart], [StepFinishPart], [SnapshotPart].
  589. func (r Part) AsUnion() PartUnion {
  590. return r.union
  591. }
  592. // Union satisfied by [TextPart], [FilePart], [ToolPart], [StepStartPart],
  593. // [StepFinishPart] or [SnapshotPart].
  594. type PartUnion interface {
  595. implementsPart()
  596. }
  597. func init() {
  598. apijson.RegisterUnion(
  599. reflect.TypeOf((*PartUnion)(nil)).Elem(),
  600. "type",
  601. apijson.UnionVariant{
  602. TypeFilter: gjson.JSON,
  603. Type: reflect.TypeOf(TextPart{}),
  604. DiscriminatorValue: "text",
  605. },
  606. apijson.UnionVariant{
  607. TypeFilter: gjson.JSON,
  608. Type: reflect.TypeOf(FilePart{}),
  609. DiscriminatorValue: "file",
  610. },
  611. apijson.UnionVariant{
  612. TypeFilter: gjson.JSON,
  613. Type: reflect.TypeOf(ToolPart{}),
  614. DiscriminatorValue: "tool",
  615. },
  616. apijson.UnionVariant{
  617. TypeFilter: gjson.JSON,
  618. Type: reflect.TypeOf(StepStartPart{}),
  619. DiscriminatorValue: "step-start",
  620. },
  621. apijson.UnionVariant{
  622. TypeFilter: gjson.JSON,
  623. Type: reflect.TypeOf(StepFinishPart{}),
  624. DiscriminatorValue: "step-finish",
  625. },
  626. apijson.UnionVariant{
  627. TypeFilter: gjson.JSON,
  628. Type: reflect.TypeOf(SnapshotPart{}),
  629. DiscriminatorValue: "snapshot",
  630. },
  631. )
  632. }
  633. type PartType string
  634. const (
  635. PartTypeText PartType = "text"
  636. PartTypeFile PartType = "file"
  637. PartTypeTool PartType = "tool"
  638. PartTypeStepStart PartType = "step-start"
  639. PartTypeStepFinish PartType = "step-finish"
  640. PartTypeSnapshot PartType = "snapshot"
  641. )
  642. func (r PartType) IsKnown() bool {
  643. switch r {
  644. case PartTypeText, PartTypeFile, PartTypeTool, PartTypeStepStart, PartTypeStepFinish, PartTypeSnapshot:
  645. return true
  646. }
  647. return false
  648. }
  649. type Session struct {
  650. ID string `json:"id,required"`
  651. Time SessionTime `json:"time,required"`
  652. Title string `json:"title,required"`
  653. Version string `json:"version,required"`
  654. ParentID string `json:"parentID"`
  655. Revert SessionRevert `json:"revert"`
  656. Share SessionShare `json:"share"`
  657. JSON sessionJSON `json:"-"`
  658. }
  659. // sessionJSON contains the JSON metadata for the struct [Session]
  660. type sessionJSON struct {
  661. ID apijson.Field
  662. Time apijson.Field
  663. Title apijson.Field
  664. Version apijson.Field
  665. ParentID apijson.Field
  666. Revert apijson.Field
  667. Share apijson.Field
  668. raw string
  669. ExtraFields map[string]apijson.Field
  670. }
  671. func (r *Session) UnmarshalJSON(data []byte) (err error) {
  672. return apijson.UnmarshalRoot(data, r)
  673. }
  674. func (r sessionJSON) RawJSON() string {
  675. return r.raw
  676. }
  677. type SessionTime struct {
  678. Created float64 `json:"created,required"`
  679. Updated float64 `json:"updated,required"`
  680. JSON sessionTimeJSON `json:"-"`
  681. }
  682. // sessionTimeJSON contains the JSON metadata for the struct [SessionTime]
  683. type sessionTimeJSON struct {
  684. Created apijson.Field
  685. Updated apijson.Field
  686. raw string
  687. ExtraFields map[string]apijson.Field
  688. }
  689. func (r *SessionTime) UnmarshalJSON(data []byte) (err error) {
  690. return apijson.UnmarshalRoot(data, r)
  691. }
  692. func (r sessionTimeJSON) RawJSON() string {
  693. return r.raw
  694. }
  695. type SessionRevert struct {
  696. MessageID string `json:"messageID,required"`
  697. Part float64 `json:"part,required"`
  698. Snapshot string `json:"snapshot"`
  699. JSON sessionRevertJSON `json:"-"`
  700. }
  701. // sessionRevertJSON contains the JSON metadata for the struct [SessionRevert]
  702. type sessionRevertJSON struct {
  703. MessageID apijson.Field
  704. Part apijson.Field
  705. Snapshot apijson.Field
  706. raw string
  707. ExtraFields map[string]apijson.Field
  708. }
  709. func (r *SessionRevert) UnmarshalJSON(data []byte) (err error) {
  710. return apijson.UnmarshalRoot(data, r)
  711. }
  712. func (r sessionRevertJSON) RawJSON() string {
  713. return r.raw
  714. }
  715. type SessionShare struct {
  716. URL string `json:"url,required"`
  717. JSON sessionShareJSON `json:"-"`
  718. }
  719. // sessionShareJSON contains the JSON metadata for the struct [SessionShare]
  720. type sessionShareJSON struct {
  721. URL apijson.Field
  722. raw string
  723. ExtraFields map[string]apijson.Field
  724. }
  725. func (r *SessionShare) UnmarshalJSON(data []byte) (err error) {
  726. return apijson.UnmarshalRoot(data, r)
  727. }
  728. func (r sessionShareJSON) RawJSON() string {
  729. return r.raw
  730. }
  731. type SnapshotPart struct {
  732. ID string `json:"id,required"`
  733. MessageID string `json:"messageID,required"`
  734. SessionID string `json:"sessionID,required"`
  735. Snapshot string `json:"snapshot,required"`
  736. Type SnapshotPartType `json:"type,required"`
  737. JSON snapshotPartJSON `json:"-"`
  738. }
  739. // snapshotPartJSON contains the JSON metadata for the struct [SnapshotPart]
  740. type snapshotPartJSON struct {
  741. ID apijson.Field
  742. MessageID apijson.Field
  743. SessionID apijson.Field
  744. Snapshot apijson.Field
  745. Type apijson.Field
  746. raw string
  747. ExtraFields map[string]apijson.Field
  748. }
  749. func (r *SnapshotPart) UnmarshalJSON(data []byte) (err error) {
  750. return apijson.UnmarshalRoot(data, r)
  751. }
  752. func (r snapshotPartJSON) RawJSON() string {
  753. return r.raw
  754. }
  755. func (r SnapshotPart) implementsPart() {}
  756. type SnapshotPartType string
  757. const (
  758. SnapshotPartTypeSnapshot SnapshotPartType = "snapshot"
  759. )
  760. func (r SnapshotPartType) IsKnown() bool {
  761. switch r {
  762. case SnapshotPartTypeSnapshot:
  763. return true
  764. }
  765. return false
  766. }
  767. type StepFinishPart struct {
  768. ID string `json:"id,required"`
  769. Cost float64 `json:"cost,required"`
  770. MessageID string `json:"messageID,required"`
  771. SessionID string `json:"sessionID,required"`
  772. Tokens StepFinishPartTokens `json:"tokens,required"`
  773. Type StepFinishPartType `json:"type,required"`
  774. JSON stepFinishPartJSON `json:"-"`
  775. }
  776. // stepFinishPartJSON contains the JSON metadata for the struct [StepFinishPart]
  777. type stepFinishPartJSON struct {
  778. ID apijson.Field
  779. Cost apijson.Field
  780. MessageID apijson.Field
  781. SessionID apijson.Field
  782. Tokens apijson.Field
  783. Type apijson.Field
  784. raw string
  785. ExtraFields map[string]apijson.Field
  786. }
  787. func (r *StepFinishPart) UnmarshalJSON(data []byte) (err error) {
  788. return apijson.UnmarshalRoot(data, r)
  789. }
  790. func (r stepFinishPartJSON) RawJSON() string {
  791. return r.raw
  792. }
  793. func (r StepFinishPart) implementsPart() {}
  794. type StepFinishPartTokens struct {
  795. Cache StepFinishPartTokensCache `json:"cache,required"`
  796. Input float64 `json:"input,required"`
  797. Output float64 `json:"output,required"`
  798. Reasoning float64 `json:"reasoning,required"`
  799. JSON stepFinishPartTokensJSON `json:"-"`
  800. }
  801. // stepFinishPartTokensJSON contains the JSON metadata for the struct
  802. // [StepFinishPartTokens]
  803. type stepFinishPartTokensJSON struct {
  804. Cache apijson.Field
  805. Input apijson.Field
  806. Output apijson.Field
  807. Reasoning apijson.Field
  808. raw string
  809. ExtraFields map[string]apijson.Field
  810. }
  811. func (r *StepFinishPartTokens) UnmarshalJSON(data []byte) (err error) {
  812. return apijson.UnmarshalRoot(data, r)
  813. }
  814. func (r stepFinishPartTokensJSON) RawJSON() string {
  815. return r.raw
  816. }
  817. type StepFinishPartTokensCache struct {
  818. Read float64 `json:"read,required"`
  819. Write float64 `json:"write,required"`
  820. JSON stepFinishPartTokensCacheJSON `json:"-"`
  821. }
  822. // stepFinishPartTokensCacheJSON contains the JSON metadata for the struct
  823. // [StepFinishPartTokensCache]
  824. type stepFinishPartTokensCacheJSON struct {
  825. Read apijson.Field
  826. Write apijson.Field
  827. raw string
  828. ExtraFields map[string]apijson.Field
  829. }
  830. func (r *StepFinishPartTokensCache) UnmarshalJSON(data []byte) (err error) {
  831. return apijson.UnmarshalRoot(data, r)
  832. }
  833. func (r stepFinishPartTokensCacheJSON) RawJSON() string {
  834. return r.raw
  835. }
  836. type StepFinishPartType string
  837. const (
  838. StepFinishPartTypeStepFinish StepFinishPartType = "step-finish"
  839. )
  840. func (r StepFinishPartType) IsKnown() bool {
  841. switch r {
  842. case StepFinishPartTypeStepFinish:
  843. return true
  844. }
  845. return false
  846. }
  847. type StepStartPart struct {
  848. ID string `json:"id,required"`
  849. MessageID string `json:"messageID,required"`
  850. SessionID string `json:"sessionID,required"`
  851. Type StepStartPartType `json:"type,required"`
  852. JSON stepStartPartJSON `json:"-"`
  853. }
  854. // stepStartPartJSON contains the JSON metadata for the struct [StepStartPart]
  855. type stepStartPartJSON struct {
  856. ID apijson.Field
  857. MessageID apijson.Field
  858. SessionID apijson.Field
  859. Type apijson.Field
  860. raw string
  861. ExtraFields map[string]apijson.Field
  862. }
  863. func (r *StepStartPart) UnmarshalJSON(data []byte) (err error) {
  864. return apijson.UnmarshalRoot(data, r)
  865. }
  866. func (r stepStartPartJSON) RawJSON() string {
  867. return r.raw
  868. }
  869. func (r StepStartPart) implementsPart() {}
  870. type StepStartPartType string
  871. const (
  872. StepStartPartTypeStepStart StepStartPartType = "step-start"
  873. )
  874. func (r StepStartPartType) IsKnown() bool {
  875. switch r {
  876. case StepStartPartTypeStepStart:
  877. return true
  878. }
  879. return false
  880. }
  881. type TextPart struct {
  882. ID string `json:"id,required"`
  883. MessageID string `json:"messageID,required"`
  884. SessionID string `json:"sessionID,required"`
  885. Text string `json:"text,required"`
  886. Type TextPartType `json:"type,required"`
  887. Synthetic bool `json:"synthetic"`
  888. Time TextPartTime `json:"time"`
  889. JSON textPartJSON `json:"-"`
  890. }
  891. // textPartJSON contains the JSON metadata for the struct [TextPart]
  892. type textPartJSON struct {
  893. ID apijson.Field
  894. MessageID apijson.Field
  895. SessionID apijson.Field
  896. Text apijson.Field
  897. Type apijson.Field
  898. Synthetic apijson.Field
  899. Time apijson.Field
  900. raw string
  901. ExtraFields map[string]apijson.Field
  902. }
  903. func (r *TextPart) UnmarshalJSON(data []byte) (err error) {
  904. return apijson.UnmarshalRoot(data, r)
  905. }
  906. func (r textPartJSON) RawJSON() string {
  907. return r.raw
  908. }
  909. func (r TextPart) implementsPart() {}
  910. type TextPartType string
  911. const (
  912. TextPartTypeText TextPartType = "text"
  913. )
  914. func (r TextPartType) IsKnown() bool {
  915. switch r {
  916. case TextPartTypeText:
  917. return true
  918. }
  919. return false
  920. }
  921. type TextPartTime struct {
  922. Start float64 `json:"start,required"`
  923. End float64 `json:"end"`
  924. JSON textPartTimeJSON `json:"-"`
  925. }
  926. // textPartTimeJSON contains the JSON metadata for the struct [TextPartTime]
  927. type textPartTimeJSON struct {
  928. Start apijson.Field
  929. End apijson.Field
  930. raw string
  931. ExtraFields map[string]apijson.Field
  932. }
  933. func (r *TextPartTime) UnmarshalJSON(data []byte) (err error) {
  934. return apijson.UnmarshalRoot(data, r)
  935. }
  936. func (r textPartTimeJSON) RawJSON() string {
  937. return r.raw
  938. }
  939. type TextPartInputParam struct {
  940. Text param.Field[string] `json:"text,required"`
  941. Type param.Field[TextPartInputType] `json:"type,required"`
  942. ID param.Field[string] `json:"id"`
  943. Synthetic param.Field[bool] `json:"synthetic"`
  944. Time param.Field[TextPartInputTimeParam] `json:"time"`
  945. }
  946. func (r TextPartInputParam) MarshalJSON() (data []byte, err error) {
  947. return apijson.MarshalRoot(r)
  948. }
  949. func (r TextPartInputParam) implementsSessionChatParamsPartUnion() {}
  950. type TextPartInputType string
  951. const (
  952. TextPartInputTypeText TextPartInputType = "text"
  953. )
  954. func (r TextPartInputType) IsKnown() bool {
  955. switch r {
  956. case TextPartInputTypeText:
  957. return true
  958. }
  959. return false
  960. }
  961. type TextPartInputTimeParam struct {
  962. Start param.Field[float64] `json:"start,required"`
  963. End param.Field[float64] `json:"end"`
  964. }
  965. func (r TextPartInputTimeParam) MarshalJSON() (data []byte, err error) {
  966. return apijson.MarshalRoot(r)
  967. }
  968. type ToolPart struct {
  969. ID string `json:"id,required"`
  970. CallID string `json:"callID,required"`
  971. MessageID string `json:"messageID,required"`
  972. SessionID string `json:"sessionID,required"`
  973. State ToolPartState `json:"state,required"`
  974. Tool string `json:"tool,required"`
  975. Type ToolPartType `json:"type,required"`
  976. JSON toolPartJSON `json:"-"`
  977. }
  978. // toolPartJSON contains the JSON metadata for the struct [ToolPart]
  979. type toolPartJSON struct {
  980. ID apijson.Field
  981. CallID apijson.Field
  982. MessageID apijson.Field
  983. SessionID apijson.Field
  984. State apijson.Field
  985. Tool apijson.Field
  986. Type apijson.Field
  987. raw string
  988. ExtraFields map[string]apijson.Field
  989. }
  990. func (r *ToolPart) UnmarshalJSON(data []byte) (err error) {
  991. return apijson.UnmarshalRoot(data, r)
  992. }
  993. func (r toolPartJSON) RawJSON() string {
  994. return r.raw
  995. }
  996. func (r ToolPart) implementsPart() {}
  997. type ToolPartState struct {
  998. Status ToolPartStateStatus `json:"status,required"`
  999. Error string `json:"error"`
  1000. // This field can have the runtime type of [interface{}], [map[string]interface{}].
  1001. Input interface{} `json:"input"`
  1002. // This field can have the runtime type of [map[string]interface{}].
  1003. Metadata interface{} `json:"metadata"`
  1004. Output string `json:"output"`
  1005. // This field can have the runtime type of [ToolStateRunningTime],
  1006. // [ToolStateCompletedTime], [ToolStateErrorTime].
  1007. Time interface{} `json:"time"`
  1008. Title string `json:"title"`
  1009. JSON toolPartStateJSON `json:"-"`
  1010. union ToolPartStateUnion
  1011. }
  1012. // toolPartStateJSON contains the JSON metadata for the struct [ToolPartState]
  1013. type toolPartStateJSON struct {
  1014. Status apijson.Field
  1015. Error apijson.Field
  1016. Input apijson.Field
  1017. Metadata apijson.Field
  1018. Output apijson.Field
  1019. Time apijson.Field
  1020. Title apijson.Field
  1021. raw string
  1022. ExtraFields map[string]apijson.Field
  1023. }
  1024. func (r toolPartStateJSON) RawJSON() string {
  1025. return r.raw
  1026. }
  1027. func (r *ToolPartState) UnmarshalJSON(data []byte) (err error) {
  1028. *r = ToolPartState{}
  1029. err = apijson.UnmarshalRoot(data, &r.union)
  1030. if err != nil {
  1031. return err
  1032. }
  1033. return apijson.Port(r.union, &r)
  1034. }
  1035. // AsUnion returns a [ToolPartStateUnion] interface which you can cast to the
  1036. // specific types for more type safety.
  1037. //
  1038. // Possible runtime types of the union are [ToolStatePending], [ToolStateRunning],
  1039. // [ToolStateCompleted], [ToolStateError].
  1040. func (r ToolPartState) AsUnion() ToolPartStateUnion {
  1041. return r.union
  1042. }
  1043. // Union satisfied by [ToolStatePending], [ToolStateRunning], [ToolStateCompleted]
  1044. // or [ToolStateError].
  1045. type ToolPartStateUnion interface {
  1046. implementsToolPartState()
  1047. }
  1048. func init() {
  1049. apijson.RegisterUnion(
  1050. reflect.TypeOf((*ToolPartStateUnion)(nil)).Elem(),
  1051. "status",
  1052. apijson.UnionVariant{
  1053. TypeFilter: gjson.JSON,
  1054. Type: reflect.TypeOf(ToolStatePending{}),
  1055. DiscriminatorValue: "pending",
  1056. },
  1057. apijson.UnionVariant{
  1058. TypeFilter: gjson.JSON,
  1059. Type: reflect.TypeOf(ToolStateRunning{}),
  1060. DiscriminatorValue: "running",
  1061. },
  1062. apijson.UnionVariant{
  1063. TypeFilter: gjson.JSON,
  1064. Type: reflect.TypeOf(ToolStateCompleted{}),
  1065. DiscriminatorValue: "completed",
  1066. },
  1067. apijson.UnionVariant{
  1068. TypeFilter: gjson.JSON,
  1069. Type: reflect.TypeOf(ToolStateError{}),
  1070. DiscriminatorValue: "error",
  1071. },
  1072. )
  1073. }
  1074. type ToolPartStateStatus string
  1075. const (
  1076. ToolPartStateStatusPending ToolPartStateStatus = "pending"
  1077. ToolPartStateStatusRunning ToolPartStateStatus = "running"
  1078. ToolPartStateStatusCompleted ToolPartStateStatus = "completed"
  1079. ToolPartStateStatusError ToolPartStateStatus = "error"
  1080. )
  1081. func (r ToolPartStateStatus) IsKnown() bool {
  1082. switch r {
  1083. case ToolPartStateStatusPending, ToolPartStateStatusRunning, ToolPartStateStatusCompleted, ToolPartStateStatusError:
  1084. return true
  1085. }
  1086. return false
  1087. }
  1088. type ToolPartType string
  1089. const (
  1090. ToolPartTypeTool ToolPartType = "tool"
  1091. )
  1092. func (r ToolPartType) IsKnown() bool {
  1093. switch r {
  1094. case ToolPartTypeTool:
  1095. return true
  1096. }
  1097. return false
  1098. }
  1099. type ToolStateCompleted struct {
  1100. Input map[string]interface{} `json:"input,required"`
  1101. Metadata map[string]interface{} `json:"metadata,required"`
  1102. Output string `json:"output,required"`
  1103. Status ToolStateCompletedStatus `json:"status,required"`
  1104. Time ToolStateCompletedTime `json:"time,required"`
  1105. Title string `json:"title,required"`
  1106. JSON toolStateCompletedJSON `json:"-"`
  1107. }
  1108. // toolStateCompletedJSON contains the JSON metadata for the struct
  1109. // [ToolStateCompleted]
  1110. type toolStateCompletedJSON struct {
  1111. Input apijson.Field
  1112. Metadata apijson.Field
  1113. Output apijson.Field
  1114. Status apijson.Field
  1115. Time apijson.Field
  1116. Title apijson.Field
  1117. raw string
  1118. ExtraFields map[string]apijson.Field
  1119. }
  1120. func (r *ToolStateCompleted) UnmarshalJSON(data []byte) (err error) {
  1121. return apijson.UnmarshalRoot(data, r)
  1122. }
  1123. func (r toolStateCompletedJSON) RawJSON() string {
  1124. return r.raw
  1125. }
  1126. func (r ToolStateCompleted) implementsToolPartState() {}
  1127. type ToolStateCompletedStatus string
  1128. const (
  1129. ToolStateCompletedStatusCompleted ToolStateCompletedStatus = "completed"
  1130. )
  1131. func (r ToolStateCompletedStatus) IsKnown() bool {
  1132. switch r {
  1133. case ToolStateCompletedStatusCompleted:
  1134. return true
  1135. }
  1136. return false
  1137. }
  1138. type ToolStateCompletedTime struct {
  1139. End float64 `json:"end,required"`
  1140. Start float64 `json:"start,required"`
  1141. JSON toolStateCompletedTimeJSON `json:"-"`
  1142. }
  1143. // toolStateCompletedTimeJSON contains the JSON metadata for the struct
  1144. // [ToolStateCompletedTime]
  1145. type toolStateCompletedTimeJSON struct {
  1146. End apijson.Field
  1147. Start apijson.Field
  1148. raw string
  1149. ExtraFields map[string]apijson.Field
  1150. }
  1151. func (r *ToolStateCompletedTime) UnmarshalJSON(data []byte) (err error) {
  1152. return apijson.UnmarshalRoot(data, r)
  1153. }
  1154. func (r toolStateCompletedTimeJSON) RawJSON() string {
  1155. return r.raw
  1156. }
  1157. type ToolStateError struct {
  1158. Error string `json:"error,required"`
  1159. Input map[string]interface{} `json:"input,required"`
  1160. Status ToolStateErrorStatus `json:"status,required"`
  1161. Time ToolStateErrorTime `json:"time,required"`
  1162. JSON toolStateErrorJSON `json:"-"`
  1163. }
  1164. // toolStateErrorJSON contains the JSON metadata for the struct [ToolStateError]
  1165. type toolStateErrorJSON struct {
  1166. Error apijson.Field
  1167. Input apijson.Field
  1168. Status apijson.Field
  1169. Time apijson.Field
  1170. raw string
  1171. ExtraFields map[string]apijson.Field
  1172. }
  1173. func (r *ToolStateError) UnmarshalJSON(data []byte) (err error) {
  1174. return apijson.UnmarshalRoot(data, r)
  1175. }
  1176. func (r toolStateErrorJSON) RawJSON() string {
  1177. return r.raw
  1178. }
  1179. func (r ToolStateError) implementsToolPartState() {}
  1180. type ToolStateErrorStatus string
  1181. const (
  1182. ToolStateErrorStatusError ToolStateErrorStatus = "error"
  1183. )
  1184. func (r ToolStateErrorStatus) IsKnown() bool {
  1185. switch r {
  1186. case ToolStateErrorStatusError:
  1187. return true
  1188. }
  1189. return false
  1190. }
  1191. type ToolStateErrorTime struct {
  1192. End float64 `json:"end,required"`
  1193. Start float64 `json:"start,required"`
  1194. JSON toolStateErrorTimeJSON `json:"-"`
  1195. }
  1196. // toolStateErrorTimeJSON contains the JSON metadata for the struct
  1197. // [ToolStateErrorTime]
  1198. type toolStateErrorTimeJSON struct {
  1199. End apijson.Field
  1200. Start apijson.Field
  1201. raw string
  1202. ExtraFields map[string]apijson.Field
  1203. }
  1204. func (r *ToolStateErrorTime) UnmarshalJSON(data []byte) (err error) {
  1205. return apijson.UnmarshalRoot(data, r)
  1206. }
  1207. func (r toolStateErrorTimeJSON) RawJSON() string {
  1208. return r.raw
  1209. }
  1210. type ToolStatePending struct {
  1211. Status ToolStatePendingStatus `json:"status,required"`
  1212. JSON toolStatePendingJSON `json:"-"`
  1213. }
  1214. // toolStatePendingJSON contains the JSON metadata for the struct
  1215. // [ToolStatePending]
  1216. type toolStatePendingJSON struct {
  1217. Status apijson.Field
  1218. raw string
  1219. ExtraFields map[string]apijson.Field
  1220. }
  1221. func (r *ToolStatePending) UnmarshalJSON(data []byte) (err error) {
  1222. return apijson.UnmarshalRoot(data, r)
  1223. }
  1224. func (r toolStatePendingJSON) RawJSON() string {
  1225. return r.raw
  1226. }
  1227. func (r ToolStatePending) implementsToolPartState() {}
  1228. type ToolStatePendingStatus string
  1229. const (
  1230. ToolStatePendingStatusPending ToolStatePendingStatus = "pending"
  1231. )
  1232. func (r ToolStatePendingStatus) IsKnown() bool {
  1233. switch r {
  1234. case ToolStatePendingStatusPending:
  1235. return true
  1236. }
  1237. return false
  1238. }
  1239. type ToolStateRunning struct {
  1240. Status ToolStateRunningStatus `json:"status,required"`
  1241. Time ToolStateRunningTime `json:"time,required"`
  1242. Input interface{} `json:"input"`
  1243. Metadata map[string]interface{} `json:"metadata"`
  1244. Title string `json:"title"`
  1245. JSON toolStateRunningJSON `json:"-"`
  1246. }
  1247. // toolStateRunningJSON contains the JSON metadata for the struct
  1248. // [ToolStateRunning]
  1249. type toolStateRunningJSON struct {
  1250. Status apijson.Field
  1251. Time apijson.Field
  1252. Input apijson.Field
  1253. Metadata apijson.Field
  1254. Title apijson.Field
  1255. raw string
  1256. ExtraFields map[string]apijson.Field
  1257. }
  1258. func (r *ToolStateRunning) UnmarshalJSON(data []byte) (err error) {
  1259. return apijson.UnmarshalRoot(data, r)
  1260. }
  1261. func (r toolStateRunningJSON) RawJSON() string {
  1262. return r.raw
  1263. }
  1264. func (r ToolStateRunning) implementsToolPartState() {}
  1265. type ToolStateRunningStatus string
  1266. const (
  1267. ToolStateRunningStatusRunning ToolStateRunningStatus = "running"
  1268. )
  1269. func (r ToolStateRunningStatus) IsKnown() bool {
  1270. switch r {
  1271. case ToolStateRunningStatusRunning:
  1272. return true
  1273. }
  1274. return false
  1275. }
  1276. type ToolStateRunningTime struct {
  1277. Start float64 `json:"start,required"`
  1278. JSON toolStateRunningTimeJSON `json:"-"`
  1279. }
  1280. // toolStateRunningTimeJSON contains the JSON metadata for the struct
  1281. // [ToolStateRunningTime]
  1282. type toolStateRunningTimeJSON struct {
  1283. Start apijson.Field
  1284. raw string
  1285. ExtraFields map[string]apijson.Field
  1286. }
  1287. func (r *ToolStateRunningTime) UnmarshalJSON(data []byte) (err error) {
  1288. return apijson.UnmarshalRoot(data, r)
  1289. }
  1290. func (r toolStateRunningTimeJSON) RawJSON() string {
  1291. return r.raw
  1292. }
  1293. type UserMessage struct {
  1294. ID string `json:"id,required"`
  1295. Role UserMessageRole `json:"role,required"`
  1296. SessionID string `json:"sessionID,required"`
  1297. Time UserMessageTime `json:"time,required"`
  1298. JSON userMessageJSON `json:"-"`
  1299. }
  1300. // userMessageJSON contains the JSON metadata for the struct [UserMessage]
  1301. type userMessageJSON struct {
  1302. ID apijson.Field
  1303. Role apijson.Field
  1304. SessionID apijson.Field
  1305. Time apijson.Field
  1306. raw string
  1307. ExtraFields map[string]apijson.Field
  1308. }
  1309. func (r *UserMessage) UnmarshalJSON(data []byte) (err error) {
  1310. return apijson.UnmarshalRoot(data, r)
  1311. }
  1312. func (r userMessageJSON) RawJSON() string {
  1313. return r.raw
  1314. }
  1315. func (r UserMessage) implementsMessage() {}
  1316. type UserMessageRole string
  1317. const (
  1318. UserMessageRoleUser UserMessageRole = "user"
  1319. )
  1320. func (r UserMessageRole) IsKnown() bool {
  1321. switch r {
  1322. case UserMessageRoleUser:
  1323. return true
  1324. }
  1325. return false
  1326. }
  1327. type UserMessageTime struct {
  1328. Created float64 `json:"created,required"`
  1329. JSON userMessageTimeJSON `json:"-"`
  1330. }
  1331. // userMessageTimeJSON contains the JSON metadata for the struct [UserMessageTime]
  1332. type userMessageTimeJSON struct {
  1333. Created apijson.Field
  1334. raw string
  1335. ExtraFields map[string]apijson.Field
  1336. }
  1337. func (r *UserMessageTime) UnmarshalJSON(data []byte) (err error) {
  1338. return apijson.UnmarshalRoot(data, r)
  1339. }
  1340. func (r userMessageTimeJSON) RawJSON() string {
  1341. return r.raw
  1342. }
  1343. type SessionMessagesResponse struct {
  1344. Info Message `json:"info,required"`
  1345. Parts []Part `json:"parts,required"`
  1346. JSON sessionMessagesResponseJSON `json:"-"`
  1347. }
  1348. // sessionMessagesResponseJSON contains the JSON metadata for the struct
  1349. // [SessionMessagesResponse]
  1350. type sessionMessagesResponseJSON struct {
  1351. Info apijson.Field
  1352. Parts apijson.Field
  1353. raw string
  1354. ExtraFields map[string]apijson.Field
  1355. }
  1356. func (r *SessionMessagesResponse) UnmarshalJSON(data []byte) (err error) {
  1357. return apijson.UnmarshalRoot(data, r)
  1358. }
  1359. func (r sessionMessagesResponseJSON) RawJSON() string {
  1360. return r.raw
  1361. }
  1362. type SessionChatParams struct {
  1363. ModelID param.Field[string] `json:"modelID,required"`
  1364. Parts param.Field[[]SessionChatParamsPartUnion] `json:"parts,required"`
  1365. ProviderID param.Field[string] `json:"providerID,required"`
  1366. MessageID param.Field[string] `json:"messageID"`
  1367. Mode param.Field[string] `json:"mode"`
  1368. }
  1369. func (r SessionChatParams) MarshalJSON() (data []byte, err error) {
  1370. return apijson.MarshalRoot(r)
  1371. }
  1372. type SessionChatParamsPart struct {
  1373. Type param.Field[SessionChatParamsPartsType] `json:"type,required"`
  1374. ID param.Field[string] `json:"id"`
  1375. Filename param.Field[string] `json:"filename"`
  1376. Mime param.Field[string] `json:"mime"`
  1377. Synthetic param.Field[bool] `json:"synthetic"`
  1378. Text param.Field[string] `json:"text"`
  1379. Time param.Field[interface{}] `json:"time"`
  1380. URL param.Field[string] `json:"url"`
  1381. }
  1382. func (r SessionChatParamsPart) MarshalJSON() (data []byte, err error) {
  1383. return apijson.MarshalRoot(r)
  1384. }
  1385. func (r SessionChatParamsPart) implementsSessionChatParamsPartUnion() {}
  1386. // Satisfied by [TextPartInputParam], [FilePartInputParam],
  1387. // [SessionChatParamsPart].
  1388. type SessionChatParamsPartUnion interface {
  1389. implementsSessionChatParamsPartUnion()
  1390. }
  1391. type SessionChatParamsPartsType string
  1392. const (
  1393. SessionChatParamsPartsTypeText SessionChatParamsPartsType = "text"
  1394. SessionChatParamsPartsTypeFile SessionChatParamsPartsType = "file"
  1395. )
  1396. func (r SessionChatParamsPartsType) IsKnown() bool {
  1397. switch r {
  1398. case SessionChatParamsPartsTypeText, SessionChatParamsPartsTypeFile:
  1399. return true
  1400. }
  1401. return false
  1402. }
  1403. type SessionInitParams struct {
  1404. MessageID param.Field[string] `json:"messageID,required"`
  1405. ModelID param.Field[string] `json:"modelID,required"`
  1406. ProviderID param.Field[string] `json:"providerID,required"`
  1407. }
  1408. func (r SessionInitParams) MarshalJSON() (data []byte, err error) {
  1409. return apijson.MarshalRoot(r)
  1410. }
  1411. type SessionSummarizeParams struct {
  1412. ModelID param.Field[string] `json:"modelID,required"`
  1413. ProviderID param.Field[string] `json:"providerID,required"`
  1414. }
  1415. func (r SessionSummarizeParams) MarshalJSON() (data []byte, err error) {
  1416. return apijson.MarshalRoot(r)
  1417. }