session.go 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434
  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. Permissions *SessionPermissionService
  25. }
  26. // NewSessionService generates a new service that applies the given options to each
  27. // request. These options are applied after the parent client's options (if there
  28. // is one), and before any request-specific options.
  29. func NewSessionService(opts ...option.RequestOption) (r *SessionService) {
  30. r = &SessionService{}
  31. r.Options = opts
  32. r.Permissions = NewSessionPermissionService(opts...)
  33. return
  34. }
  35. // Create a new session
  36. func (r *SessionService) New(ctx context.Context, body SessionNewParams, opts ...option.RequestOption) (res *Session, err error) {
  37. opts = append(r.Options[:], opts...)
  38. path := "session"
  39. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
  40. return
  41. }
  42. // Update session properties
  43. func (r *SessionService) Update(ctx context.Context, id string, body SessionUpdateParams, opts ...option.RequestOption) (res *Session, err error) {
  44. opts = append(r.Options[:], opts...)
  45. if id == "" {
  46. err = errors.New("missing required id parameter")
  47. return
  48. }
  49. path := fmt.Sprintf("session/%s", id)
  50. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, body, &res, opts...)
  51. return
  52. }
  53. // List all sessions
  54. func (r *SessionService) List(ctx context.Context, opts ...option.RequestOption) (res *[]Session, err error) {
  55. opts = append(r.Options[:], opts...)
  56. path := "session"
  57. err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
  58. return
  59. }
  60. // Delete a session and all its data
  61. func (r *SessionService) Delete(ctx context.Context, id string, opts ...option.RequestOption) (res *bool, err error) {
  62. opts = append(r.Options[:], opts...)
  63. if id == "" {
  64. err = errors.New("missing required id parameter")
  65. return
  66. }
  67. path := fmt.Sprintf("session/%s", id)
  68. err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
  69. return
  70. }
  71. // Abort a session
  72. func (r *SessionService) Abort(ctx context.Context, id string, opts ...option.RequestOption) (res *bool, err error) {
  73. opts = append(r.Options[:], opts...)
  74. if id == "" {
  75. err = errors.New("missing required id parameter")
  76. return
  77. }
  78. path := fmt.Sprintf("session/%s/abort", id)
  79. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
  80. return
  81. }
  82. // Create and send a new message to a session
  83. func (r *SessionService) Chat(ctx context.Context, id string, body SessionChatParams, opts ...option.RequestOption) (res *AssistantMessage, err error) {
  84. opts = append(r.Options[:], opts...)
  85. if id == "" {
  86. err = errors.New("missing required id parameter")
  87. return
  88. }
  89. path := fmt.Sprintf("session/%s/message", id)
  90. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
  91. return
  92. }
  93. // Get a session's children
  94. func (r *SessionService) Children(ctx context.Context, id string, opts ...option.RequestOption) (res *[]Session, err error) {
  95. opts = append(r.Options[:], opts...)
  96. if id == "" {
  97. err = errors.New("missing required id parameter")
  98. return
  99. }
  100. path := fmt.Sprintf("session/%s/children", id)
  101. err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
  102. return
  103. }
  104. // Get session
  105. func (r *SessionService) Get(ctx context.Context, id string, opts ...option.RequestOption) (res *Session, err error) {
  106. opts = append(r.Options[:], opts...)
  107. if id == "" {
  108. err = errors.New("missing required id parameter")
  109. return
  110. }
  111. path := fmt.Sprintf("session/%s", id)
  112. err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
  113. return
  114. }
  115. // Analyze the app and create an AGENTS.md file
  116. func (r *SessionService) Init(ctx context.Context, id string, body SessionInitParams, opts ...option.RequestOption) (res *bool, err error) {
  117. opts = append(r.Options[:], opts...)
  118. if id == "" {
  119. err = errors.New("missing required id parameter")
  120. return
  121. }
  122. path := fmt.Sprintf("session/%s/init", id)
  123. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
  124. return
  125. }
  126. // Get a message from a session
  127. func (r *SessionService) Message(ctx context.Context, id string, messageID string, opts ...option.RequestOption) (res *SessionMessageResponse, err error) {
  128. opts = append(r.Options[:], opts...)
  129. if id == "" {
  130. err = errors.New("missing required id parameter")
  131. return
  132. }
  133. if messageID == "" {
  134. err = errors.New("missing required messageID parameter")
  135. return
  136. }
  137. path := fmt.Sprintf("session/%s/message/%s", id, messageID)
  138. err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
  139. return
  140. }
  141. // List messages for a session
  142. func (r *SessionService) Messages(ctx context.Context, id string, opts ...option.RequestOption) (res *[]SessionMessagesResponse, err error) {
  143. opts = append(r.Options[:], opts...)
  144. if id == "" {
  145. err = errors.New("missing required id parameter")
  146. return
  147. }
  148. path := fmt.Sprintf("session/%s/message", id)
  149. err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
  150. return
  151. }
  152. // Revert a message
  153. func (r *SessionService) Revert(ctx context.Context, id string, body SessionRevertParams, opts ...option.RequestOption) (res *Session, err error) {
  154. opts = append(r.Options[:], opts...)
  155. if id == "" {
  156. err = errors.New("missing required id parameter")
  157. return
  158. }
  159. path := fmt.Sprintf("session/%s/revert", id)
  160. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
  161. return
  162. }
  163. // Share a session
  164. func (r *SessionService) Share(ctx context.Context, id string, opts ...option.RequestOption) (res *Session, err error) {
  165. opts = append(r.Options[:], opts...)
  166. if id == "" {
  167. err = errors.New("missing required id parameter")
  168. return
  169. }
  170. path := fmt.Sprintf("session/%s/share", id)
  171. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
  172. return
  173. }
  174. // Run a shell command
  175. func (r *SessionService) Shell(ctx context.Context, id string, body SessionShellParams, opts ...option.RequestOption) (res *AssistantMessage, err error) {
  176. opts = append(r.Options[:], opts...)
  177. if id == "" {
  178. err = errors.New("missing required id parameter")
  179. return
  180. }
  181. path := fmt.Sprintf("session/%s/shell", id)
  182. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
  183. return
  184. }
  185. // Summarize the session
  186. func (r *SessionService) Summarize(ctx context.Context, id string, body SessionSummarizeParams, opts ...option.RequestOption) (res *bool, err error) {
  187. opts = append(r.Options[:], opts...)
  188. if id == "" {
  189. err = errors.New("missing required id parameter")
  190. return
  191. }
  192. path := fmt.Sprintf("session/%s/summarize", id)
  193. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
  194. return
  195. }
  196. // Restore all reverted messages
  197. func (r *SessionService) Unrevert(ctx context.Context, id string, opts ...option.RequestOption) (res *Session, err error) {
  198. opts = append(r.Options[:], opts...)
  199. if id == "" {
  200. err = errors.New("missing required id parameter")
  201. return
  202. }
  203. path := fmt.Sprintf("session/%s/unrevert", id)
  204. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
  205. return
  206. }
  207. // Unshare the session
  208. func (r *SessionService) Unshare(ctx context.Context, id string, opts ...option.RequestOption) (res *Session, err error) {
  209. opts = append(r.Options[:], opts...)
  210. if id == "" {
  211. err = errors.New("missing required id parameter")
  212. return
  213. }
  214. path := fmt.Sprintf("session/%s/share", id)
  215. err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
  216. return
  217. }
  218. type AgentPart struct {
  219. ID string `json:"id,required"`
  220. MessageID string `json:"messageID,required"`
  221. Name string `json:"name,required"`
  222. SessionID string `json:"sessionID,required"`
  223. Type AgentPartType `json:"type,required"`
  224. Source AgentPartSource `json:"source"`
  225. JSON agentPartJSON `json:"-"`
  226. }
  227. // agentPartJSON contains the JSON metadata for the struct [AgentPart]
  228. type agentPartJSON struct {
  229. ID apijson.Field
  230. MessageID apijson.Field
  231. Name apijson.Field
  232. SessionID apijson.Field
  233. Type apijson.Field
  234. Source apijson.Field
  235. raw string
  236. ExtraFields map[string]apijson.Field
  237. }
  238. func (r *AgentPart) UnmarshalJSON(data []byte) (err error) {
  239. return apijson.UnmarshalRoot(data, r)
  240. }
  241. func (r agentPartJSON) RawJSON() string {
  242. return r.raw
  243. }
  244. func (r AgentPart) implementsPart() {}
  245. type AgentPartType string
  246. const (
  247. AgentPartTypeAgent AgentPartType = "agent"
  248. )
  249. func (r AgentPartType) IsKnown() bool {
  250. switch r {
  251. case AgentPartTypeAgent:
  252. return true
  253. }
  254. return false
  255. }
  256. type AgentPartSource struct {
  257. End int64 `json:"end,required"`
  258. Start int64 `json:"start,required"`
  259. Value string `json:"value,required"`
  260. JSON agentPartSourceJSON `json:"-"`
  261. }
  262. // agentPartSourceJSON contains the JSON metadata for the struct [AgentPartSource]
  263. type agentPartSourceJSON struct {
  264. End apijson.Field
  265. Start apijson.Field
  266. Value apijson.Field
  267. raw string
  268. ExtraFields map[string]apijson.Field
  269. }
  270. func (r *AgentPartSource) UnmarshalJSON(data []byte) (err error) {
  271. return apijson.UnmarshalRoot(data, r)
  272. }
  273. func (r agentPartSourceJSON) RawJSON() string {
  274. return r.raw
  275. }
  276. type AgentPartInputParam struct {
  277. Name param.Field[string] `json:"name,required"`
  278. Type param.Field[AgentPartInputType] `json:"type,required"`
  279. ID param.Field[string] `json:"id"`
  280. Source param.Field[AgentPartInputSourceParam] `json:"source"`
  281. }
  282. func (r AgentPartInputParam) MarshalJSON() (data []byte, err error) {
  283. return apijson.MarshalRoot(r)
  284. }
  285. func (r AgentPartInputParam) implementsSessionChatParamsPartUnion() {}
  286. type AgentPartInputType string
  287. const (
  288. AgentPartInputTypeAgent AgentPartInputType = "agent"
  289. )
  290. func (r AgentPartInputType) IsKnown() bool {
  291. switch r {
  292. case AgentPartInputTypeAgent:
  293. return true
  294. }
  295. return false
  296. }
  297. type AgentPartInputSourceParam struct {
  298. End param.Field[int64] `json:"end,required"`
  299. Start param.Field[int64] `json:"start,required"`
  300. Value param.Field[string] `json:"value,required"`
  301. }
  302. func (r AgentPartInputSourceParam) MarshalJSON() (data []byte, err error) {
  303. return apijson.MarshalRoot(r)
  304. }
  305. type AssistantMessage struct {
  306. ID string `json:"id,required"`
  307. Cost float64 `json:"cost,required"`
  308. Mode string `json:"mode,required"`
  309. ModelID string `json:"modelID,required"`
  310. Path AssistantMessagePath `json:"path,required"`
  311. ProviderID string `json:"providerID,required"`
  312. Role AssistantMessageRole `json:"role,required"`
  313. SessionID string `json:"sessionID,required"`
  314. System []string `json:"system,required"`
  315. Time AssistantMessageTime `json:"time,required"`
  316. Tokens AssistantMessageTokens `json:"tokens,required"`
  317. Error AssistantMessageError `json:"error"`
  318. Summary bool `json:"summary"`
  319. JSON assistantMessageJSON `json:"-"`
  320. }
  321. // assistantMessageJSON contains the JSON metadata for the struct
  322. // [AssistantMessage]
  323. type assistantMessageJSON struct {
  324. ID apijson.Field
  325. Cost apijson.Field
  326. Mode apijson.Field
  327. ModelID apijson.Field
  328. Path apijson.Field
  329. ProviderID apijson.Field
  330. Role apijson.Field
  331. SessionID apijson.Field
  332. System apijson.Field
  333. Time apijson.Field
  334. Tokens apijson.Field
  335. Error apijson.Field
  336. Summary apijson.Field
  337. raw string
  338. ExtraFields map[string]apijson.Field
  339. }
  340. func (r *AssistantMessage) UnmarshalJSON(data []byte) (err error) {
  341. return apijson.UnmarshalRoot(data, r)
  342. }
  343. func (r assistantMessageJSON) RawJSON() string {
  344. return r.raw
  345. }
  346. func (r AssistantMessage) implementsMessage() {}
  347. type AssistantMessagePath struct {
  348. Cwd string `json:"cwd,required"`
  349. Root string `json:"root,required"`
  350. JSON assistantMessagePathJSON `json:"-"`
  351. }
  352. // assistantMessagePathJSON contains the JSON metadata for the struct
  353. // [AssistantMessagePath]
  354. type assistantMessagePathJSON struct {
  355. Cwd apijson.Field
  356. Root apijson.Field
  357. raw string
  358. ExtraFields map[string]apijson.Field
  359. }
  360. func (r *AssistantMessagePath) UnmarshalJSON(data []byte) (err error) {
  361. return apijson.UnmarshalRoot(data, r)
  362. }
  363. func (r assistantMessagePathJSON) RawJSON() string {
  364. return r.raw
  365. }
  366. type AssistantMessageRole string
  367. const (
  368. AssistantMessageRoleAssistant AssistantMessageRole = "assistant"
  369. )
  370. func (r AssistantMessageRole) IsKnown() bool {
  371. switch r {
  372. case AssistantMessageRoleAssistant:
  373. return true
  374. }
  375. return false
  376. }
  377. type AssistantMessageTime struct {
  378. Created float64 `json:"created,required"`
  379. Completed float64 `json:"completed"`
  380. JSON assistantMessageTimeJSON `json:"-"`
  381. }
  382. // assistantMessageTimeJSON contains the JSON metadata for the struct
  383. // [AssistantMessageTime]
  384. type assistantMessageTimeJSON struct {
  385. Created apijson.Field
  386. Completed apijson.Field
  387. raw string
  388. ExtraFields map[string]apijson.Field
  389. }
  390. func (r *AssistantMessageTime) UnmarshalJSON(data []byte) (err error) {
  391. return apijson.UnmarshalRoot(data, r)
  392. }
  393. func (r assistantMessageTimeJSON) RawJSON() string {
  394. return r.raw
  395. }
  396. type AssistantMessageTokens struct {
  397. Cache AssistantMessageTokensCache `json:"cache,required"`
  398. Input float64 `json:"input,required"`
  399. Output float64 `json:"output,required"`
  400. Reasoning float64 `json:"reasoning,required"`
  401. JSON assistantMessageTokensJSON `json:"-"`
  402. }
  403. // assistantMessageTokensJSON contains the JSON metadata for the struct
  404. // [AssistantMessageTokens]
  405. type assistantMessageTokensJSON struct {
  406. Cache apijson.Field
  407. Input apijson.Field
  408. Output apijson.Field
  409. Reasoning apijson.Field
  410. raw string
  411. ExtraFields map[string]apijson.Field
  412. }
  413. func (r *AssistantMessageTokens) UnmarshalJSON(data []byte) (err error) {
  414. return apijson.UnmarshalRoot(data, r)
  415. }
  416. func (r assistantMessageTokensJSON) RawJSON() string {
  417. return r.raw
  418. }
  419. type AssistantMessageTokensCache struct {
  420. Read float64 `json:"read,required"`
  421. Write float64 `json:"write,required"`
  422. JSON assistantMessageTokensCacheJSON `json:"-"`
  423. }
  424. // assistantMessageTokensCacheJSON contains the JSON metadata for the struct
  425. // [AssistantMessageTokensCache]
  426. type assistantMessageTokensCacheJSON struct {
  427. Read apijson.Field
  428. Write apijson.Field
  429. raw string
  430. ExtraFields map[string]apijson.Field
  431. }
  432. func (r *AssistantMessageTokensCache) UnmarshalJSON(data []byte) (err error) {
  433. return apijson.UnmarshalRoot(data, r)
  434. }
  435. func (r assistantMessageTokensCacheJSON) RawJSON() string {
  436. return r.raw
  437. }
  438. type AssistantMessageError struct {
  439. // This field can have the runtime type of [shared.ProviderAuthErrorData],
  440. // [shared.UnknownErrorData], [interface{}].
  441. Data interface{} `json:"data,required"`
  442. Name AssistantMessageErrorName `json:"name,required"`
  443. JSON assistantMessageErrorJSON `json:"-"`
  444. union AssistantMessageErrorUnion
  445. }
  446. // assistantMessageErrorJSON contains the JSON metadata for the struct
  447. // [AssistantMessageError]
  448. type assistantMessageErrorJSON struct {
  449. Data apijson.Field
  450. Name apijson.Field
  451. raw string
  452. ExtraFields map[string]apijson.Field
  453. }
  454. func (r assistantMessageErrorJSON) RawJSON() string {
  455. return r.raw
  456. }
  457. func (r *AssistantMessageError) UnmarshalJSON(data []byte) (err error) {
  458. *r = AssistantMessageError{}
  459. err = apijson.UnmarshalRoot(data, &r.union)
  460. if err != nil {
  461. return err
  462. }
  463. return apijson.Port(r.union, &r)
  464. }
  465. // AsUnion returns a [AssistantMessageErrorUnion] interface which you can cast to
  466. // the specific types for more type safety.
  467. //
  468. // Possible runtime types of the union are [shared.ProviderAuthError],
  469. // [shared.UnknownError], [AssistantMessageErrorMessageOutputLengthError],
  470. // [shared.MessageAbortedError].
  471. func (r AssistantMessageError) AsUnion() AssistantMessageErrorUnion {
  472. return r.union
  473. }
  474. // Union satisfied by [shared.ProviderAuthError], [shared.UnknownError],
  475. // [AssistantMessageErrorMessageOutputLengthError] or [shared.MessageAbortedError].
  476. type AssistantMessageErrorUnion interface {
  477. ImplementsAssistantMessageError()
  478. }
  479. func init() {
  480. apijson.RegisterUnion(
  481. reflect.TypeOf((*AssistantMessageErrorUnion)(nil)).Elem(),
  482. "name",
  483. apijson.UnionVariant{
  484. TypeFilter: gjson.JSON,
  485. Type: reflect.TypeOf(shared.ProviderAuthError{}),
  486. DiscriminatorValue: "ProviderAuthError",
  487. },
  488. apijson.UnionVariant{
  489. TypeFilter: gjson.JSON,
  490. Type: reflect.TypeOf(shared.UnknownError{}),
  491. DiscriminatorValue: "UnknownError",
  492. },
  493. apijson.UnionVariant{
  494. TypeFilter: gjson.JSON,
  495. Type: reflect.TypeOf(AssistantMessageErrorMessageOutputLengthError{}),
  496. DiscriminatorValue: "MessageOutputLengthError",
  497. },
  498. apijson.UnionVariant{
  499. TypeFilter: gjson.JSON,
  500. Type: reflect.TypeOf(shared.MessageAbortedError{}),
  501. DiscriminatorValue: "MessageAbortedError",
  502. },
  503. )
  504. }
  505. type AssistantMessageErrorMessageOutputLengthError struct {
  506. Data interface{} `json:"data,required"`
  507. Name AssistantMessageErrorMessageOutputLengthErrorName `json:"name,required"`
  508. JSON assistantMessageErrorMessageOutputLengthErrorJSON `json:"-"`
  509. }
  510. // assistantMessageErrorMessageOutputLengthErrorJSON contains the JSON metadata for
  511. // the struct [AssistantMessageErrorMessageOutputLengthError]
  512. type assistantMessageErrorMessageOutputLengthErrorJSON struct {
  513. Data apijson.Field
  514. Name apijson.Field
  515. raw string
  516. ExtraFields map[string]apijson.Field
  517. }
  518. func (r *AssistantMessageErrorMessageOutputLengthError) UnmarshalJSON(data []byte) (err error) {
  519. return apijson.UnmarshalRoot(data, r)
  520. }
  521. func (r assistantMessageErrorMessageOutputLengthErrorJSON) RawJSON() string {
  522. return r.raw
  523. }
  524. func (r AssistantMessageErrorMessageOutputLengthError) ImplementsAssistantMessageError() {}
  525. type AssistantMessageErrorMessageOutputLengthErrorName string
  526. const (
  527. AssistantMessageErrorMessageOutputLengthErrorNameMessageOutputLengthError AssistantMessageErrorMessageOutputLengthErrorName = "MessageOutputLengthError"
  528. )
  529. func (r AssistantMessageErrorMessageOutputLengthErrorName) IsKnown() bool {
  530. switch r {
  531. case AssistantMessageErrorMessageOutputLengthErrorNameMessageOutputLengthError:
  532. return true
  533. }
  534. return false
  535. }
  536. type AssistantMessageErrorName string
  537. const (
  538. AssistantMessageErrorNameProviderAuthError AssistantMessageErrorName = "ProviderAuthError"
  539. AssistantMessageErrorNameUnknownError AssistantMessageErrorName = "UnknownError"
  540. AssistantMessageErrorNameMessageOutputLengthError AssistantMessageErrorName = "MessageOutputLengthError"
  541. AssistantMessageErrorNameMessageAbortedError AssistantMessageErrorName = "MessageAbortedError"
  542. )
  543. func (r AssistantMessageErrorName) IsKnown() bool {
  544. switch r {
  545. case AssistantMessageErrorNameProviderAuthError, AssistantMessageErrorNameUnknownError, AssistantMessageErrorNameMessageOutputLengthError, AssistantMessageErrorNameMessageAbortedError:
  546. return true
  547. }
  548. return false
  549. }
  550. type FilePart struct {
  551. ID string `json:"id,required"`
  552. MessageID string `json:"messageID,required"`
  553. Mime string `json:"mime,required"`
  554. SessionID string `json:"sessionID,required"`
  555. Type FilePartType `json:"type,required"`
  556. URL string `json:"url,required"`
  557. Filename string `json:"filename"`
  558. Source FilePartSource `json:"source"`
  559. JSON filePartJSON `json:"-"`
  560. }
  561. // filePartJSON contains the JSON metadata for the struct [FilePart]
  562. type filePartJSON struct {
  563. ID apijson.Field
  564. MessageID apijson.Field
  565. Mime apijson.Field
  566. SessionID apijson.Field
  567. Type apijson.Field
  568. URL apijson.Field
  569. Filename apijson.Field
  570. Source apijson.Field
  571. raw string
  572. ExtraFields map[string]apijson.Field
  573. }
  574. func (r *FilePart) UnmarshalJSON(data []byte) (err error) {
  575. return apijson.UnmarshalRoot(data, r)
  576. }
  577. func (r filePartJSON) RawJSON() string {
  578. return r.raw
  579. }
  580. func (r FilePart) implementsPart() {}
  581. type FilePartType string
  582. const (
  583. FilePartTypeFile FilePartType = "file"
  584. )
  585. func (r FilePartType) IsKnown() bool {
  586. switch r {
  587. case FilePartTypeFile:
  588. return true
  589. }
  590. return false
  591. }
  592. type FilePartInputParam struct {
  593. Mime param.Field[string] `json:"mime,required"`
  594. Type param.Field[FilePartInputType] `json:"type,required"`
  595. URL param.Field[string] `json:"url,required"`
  596. ID param.Field[string] `json:"id"`
  597. Filename param.Field[string] `json:"filename"`
  598. Source param.Field[FilePartSourceUnionParam] `json:"source"`
  599. }
  600. func (r FilePartInputParam) MarshalJSON() (data []byte, err error) {
  601. return apijson.MarshalRoot(r)
  602. }
  603. func (r FilePartInputParam) implementsSessionChatParamsPartUnion() {}
  604. type FilePartInputType string
  605. const (
  606. FilePartInputTypeFile FilePartInputType = "file"
  607. )
  608. func (r FilePartInputType) IsKnown() bool {
  609. switch r {
  610. case FilePartInputTypeFile:
  611. return true
  612. }
  613. return false
  614. }
  615. type FilePartSource struct {
  616. Path string `json:"path,required"`
  617. Text FilePartSourceText `json:"text,required"`
  618. Type FilePartSourceType `json:"type,required"`
  619. Kind int64 `json:"kind"`
  620. Name string `json:"name"`
  621. // This field can have the runtime type of [SymbolSourceRange].
  622. Range interface{} `json:"range"`
  623. JSON filePartSourceJSON `json:"-"`
  624. union FilePartSourceUnion
  625. }
  626. // filePartSourceJSON contains the JSON metadata for the struct [FilePartSource]
  627. type filePartSourceJSON struct {
  628. Path apijson.Field
  629. Text apijson.Field
  630. Type apijson.Field
  631. Kind apijson.Field
  632. Name apijson.Field
  633. Range apijson.Field
  634. raw string
  635. ExtraFields map[string]apijson.Field
  636. }
  637. func (r filePartSourceJSON) RawJSON() string {
  638. return r.raw
  639. }
  640. func (r *FilePartSource) UnmarshalJSON(data []byte) (err error) {
  641. *r = FilePartSource{}
  642. err = apijson.UnmarshalRoot(data, &r.union)
  643. if err != nil {
  644. return err
  645. }
  646. return apijson.Port(r.union, &r)
  647. }
  648. // AsUnion returns a [FilePartSourceUnion] interface which you can cast to the
  649. // specific types for more type safety.
  650. //
  651. // Possible runtime types of the union are [FileSource], [SymbolSource].
  652. func (r FilePartSource) AsUnion() FilePartSourceUnion {
  653. return r.union
  654. }
  655. // Union satisfied by [FileSource] or [SymbolSource].
  656. type FilePartSourceUnion interface {
  657. implementsFilePartSource()
  658. }
  659. func init() {
  660. apijson.RegisterUnion(
  661. reflect.TypeOf((*FilePartSourceUnion)(nil)).Elem(),
  662. "type",
  663. apijson.UnionVariant{
  664. TypeFilter: gjson.JSON,
  665. Type: reflect.TypeOf(FileSource{}),
  666. DiscriminatorValue: "file",
  667. },
  668. apijson.UnionVariant{
  669. TypeFilter: gjson.JSON,
  670. Type: reflect.TypeOf(SymbolSource{}),
  671. DiscriminatorValue: "symbol",
  672. },
  673. )
  674. }
  675. type FilePartSourceType string
  676. const (
  677. FilePartSourceTypeFile FilePartSourceType = "file"
  678. FilePartSourceTypeSymbol FilePartSourceType = "symbol"
  679. )
  680. func (r FilePartSourceType) IsKnown() bool {
  681. switch r {
  682. case FilePartSourceTypeFile, FilePartSourceTypeSymbol:
  683. return true
  684. }
  685. return false
  686. }
  687. type FilePartSourceParam struct {
  688. Path param.Field[string] `json:"path,required"`
  689. Text param.Field[FilePartSourceTextParam] `json:"text,required"`
  690. Type param.Field[FilePartSourceType] `json:"type,required"`
  691. Kind param.Field[int64] `json:"kind"`
  692. Name param.Field[string] `json:"name"`
  693. Range param.Field[interface{}] `json:"range"`
  694. }
  695. func (r FilePartSourceParam) MarshalJSON() (data []byte, err error) {
  696. return apijson.MarshalRoot(r)
  697. }
  698. func (r FilePartSourceParam) implementsFilePartSourceUnionParam() {}
  699. // Satisfied by [FileSourceParam], [SymbolSourceParam], [FilePartSourceParam].
  700. type FilePartSourceUnionParam interface {
  701. implementsFilePartSourceUnionParam()
  702. }
  703. type FilePartSourceText struct {
  704. End int64 `json:"end,required"`
  705. Start int64 `json:"start,required"`
  706. Value string `json:"value,required"`
  707. JSON filePartSourceTextJSON `json:"-"`
  708. }
  709. // filePartSourceTextJSON contains the JSON metadata for the struct
  710. // [FilePartSourceText]
  711. type filePartSourceTextJSON struct {
  712. End apijson.Field
  713. Start apijson.Field
  714. Value apijson.Field
  715. raw string
  716. ExtraFields map[string]apijson.Field
  717. }
  718. func (r *FilePartSourceText) UnmarshalJSON(data []byte) (err error) {
  719. return apijson.UnmarshalRoot(data, r)
  720. }
  721. func (r filePartSourceTextJSON) RawJSON() string {
  722. return r.raw
  723. }
  724. type FilePartSourceTextParam struct {
  725. End param.Field[int64] `json:"end,required"`
  726. Start param.Field[int64] `json:"start,required"`
  727. Value param.Field[string] `json:"value,required"`
  728. }
  729. func (r FilePartSourceTextParam) MarshalJSON() (data []byte, err error) {
  730. return apijson.MarshalRoot(r)
  731. }
  732. type FileSource struct {
  733. Path string `json:"path,required"`
  734. Text FilePartSourceText `json:"text,required"`
  735. Type FileSourceType `json:"type,required"`
  736. JSON fileSourceJSON `json:"-"`
  737. }
  738. // fileSourceJSON contains the JSON metadata for the struct [FileSource]
  739. type fileSourceJSON struct {
  740. Path apijson.Field
  741. Text apijson.Field
  742. Type apijson.Field
  743. raw string
  744. ExtraFields map[string]apijson.Field
  745. }
  746. func (r *FileSource) UnmarshalJSON(data []byte) (err error) {
  747. return apijson.UnmarshalRoot(data, r)
  748. }
  749. func (r fileSourceJSON) RawJSON() string {
  750. return r.raw
  751. }
  752. func (r FileSource) implementsFilePartSource() {}
  753. type FileSourceType string
  754. const (
  755. FileSourceTypeFile FileSourceType = "file"
  756. )
  757. func (r FileSourceType) IsKnown() bool {
  758. switch r {
  759. case FileSourceTypeFile:
  760. return true
  761. }
  762. return false
  763. }
  764. type FileSourceParam struct {
  765. Path param.Field[string] `json:"path,required"`
  766. Text param.Field[FilePartSourceTextParam] `json:"text,required"`
  767. Type param.Field[FileSourceType] `json:"type,required"`
  768. }
  769. func (r FileSourceParam) MarshalJSON() (data []byte, err error) {
  770. return apijson.MarshalRoot(r)
  771. }
  772. func (r FileSourceParam) implementsFilePartSourceUnionParam() {}
  773. type Message struct {
  774. ID string `json:"id,required"`
  775. Role MessageRole `json:"role,required"`
  776. SessionID string `json:"sessionID,required"`
  777. // This field can have the runtime type of [UserMessageTime],
  778. // [AssistantMessageTime].
  779. Time interface{} `json:"time,required"`
  780. Cost float64 `json:"cost"`
  781. // This field can have the runtime type of [AssistantMessageError].
  782. Error interface{} `json:"error"`
  783. Mode string `json:"mode"`
  784. ModelID string `json:"modelID"`
  785. // This field can have the runtime type of [AssistantMessagePath].
  786. Path interface{} `json:"path"`
  787. ProviderID string `json:"providerID"`
  788. Summary bool `json:"summary"`
  789. // This field can have the runtime type of [[]string].
  790. System interface{} `json:"system"`
  791. // This field can have the runtime type of [AssistantMessageTokens].
  792. Tokens interface{} `json:"tokens"`
  793. JSON messageJSON `json:"-"`
  794. union MessageUnion
  795. }
  796. // messageJSON contains the JSON metadata for the struct [Message]
  797. type messageJSON struct {
  798. ID apijson.Field
  799. Role apijson.Field
  800. SessionID apijson.Field
  801. Time apijson.Field
  802. Cost apijson.Field
  803. Error apijson.Field
  804. Mode apijson.Field
  805. ModelID apijson.Field
  806. Path apijson.Field
  807. ProviderID apijson.Field
  808. Summary apijson.Field
  809. System apijson.Field
  810. Tokens apijson.Field
  811. raw string
  812. ExtraFields map[string]apijson.Field
  813. }
  814. func (r messageJSON) RawJSON() string {
  815. return r.raw
  816. }
  817. func (r *Message) UnmarshalJSON(data []byte) (err error) {
  818. *r = Message{}
  819. err = apijson.UnmarshalRoot(data, &r.union)
  820. if err != nil {
  821. return err
  822. }
  823. return apijson.Port(r.union, &r)
  824. }
  825. // AsUnion returns a [MessageUnion] interface which you can cast to the specific
  826. // types for more type safety.
  827. //
  828. // Possible runtime types of the union are [UserMessage], [AssistantMessage].
  829. func (r Message) AsUnion() MessageUnion {
  830. return r.union
  831. }
  832. // Union satisfied by [UserMessage] or [AssistantMessage].
  833. type MessageUnion interface {
  834. implementsMessage()
  835. }
  836. func init() {
  837. apijson.RegisterUnion(
  838. reflect.TypeOf((*MessageUnion)(nil)).Elem(),
  839. "role",
  840. apijson.UnionVariant{
  841. TypeFilter: gjson.JSON,
  842. Type: reflect.TypeOf(UserMessage{}),
  843. DiscriminatorValue: "user",
  844. },
  845. apijson.UnionVariant{
  846. TypeFilter: gjson.JSON,
  847. Type: reflect.TypeOf(AssistantMessage{}),
  848. DiscriminatorValue: "assistant",
  849. },
  850. )
  851. }
  852. type MessageRole string
  853. const (
  854. MessageRoleUser MessageRole = "user"
  855. MessageRoleAssistant MessageRole = "assistant"
  856. )
  857. func (r MessageRole) IsKnown() bool {
  858. switch r {
  859. case MessageRoleUser, MessageRoleAssistant:
  860. return true
  861. }
  862. return false
  863. }
  864. type Part struct {
  865. ID string `json:"id,required"`
  866. MessageID string `json:"messageID,required"`
  867. SessionID string `json:"sessionID,required"`
  868. Type PartType `json:"type,required"`
  869. CallID string `json:"callID"`
  870. Cost float64 `json:"cost"`
  871. Filename string `json:"filename"`
  872. // This field can have the runtime type of [[]string].
  873. Files interface{} `json:"files"`
  874. Hash string `json:"hash"`
  875. // This field can have the runtime type of [map[string]interface{}].
  876. Metadata interface{} `json:"metadata"`
  877. Mime string `json:"mime"`
  878. Name string `json:"name"`
  879. Snapshot string `json:"snapshot"`
  880. // This field can have the runtime type of [FilePartSource], [AgentPartSource].
  881. Source interface{} `json:"source"`
  882. // This field can have the runtime type of [ToolPartState].
  883. State interface{} `json:"state"`
  884. Synthetic bool `json:"synthetic"`
  885. Text string `json:"text"`
  886. // This field can have the runtime type of [TextPartTime], [ReasoningPartTime].
  887. Time interface{} `json:"time"`
  888. // This field can have the runtime type of [StepFinishPartTokens].
  889. Tokens interface{} `json:"tokens"`
  890. Tool string `json:"tool"`
  891. URL string `json:"url"`
  892. JSON partJSON `json:"-"`
  893. union PartUnion
  894. }
  895. // partJSON contains the JSON metadata for the struct [Part]
  896. type partJSON struct {
  897. ID apijson.Field
  898. MessageID apijson.Field
  899. SessionID apijson.Field
  900. Type apijson.Field
  901. CallID apijson.Field
  902. Cost apijson.Field
  903. Filename apijson.Field
  904. Files apijson.Field
  905. Hash apijson.Field
  906. Metadata apijson.Field
  907. Mime apijson.Field
  908. Name apijson.Field
  909. Snapshot apijson.Field
  910. Source apijson.Field
  911. State apijson.Field
  912. Synthetic apijson.Field
  913. Text apijson.Field
  914. Time apijson.Field
  915. Tokens apijson.Field
  916. Tool apijson.Field
  917. URL apijson.Field
  918. raw string
  919. ExtraFields map[string]apijson.Field
  920. }
  921. func (r partJSON) RawJSON() string {
  922. return r.raw
  923. }
  924. func (r *Part) UnmarshalJSON(data []byte) (err error) {
  925. *r = Part{}
  926. err = apijson.UnmarshalRoot(data, &r.union)
  927. if err != nil {
  928. return err
  929. }
  930. return apijson.Port(r.union, &r)
  931. }
  932. // AsUnion returns a [PartUnion] interface which you can cast to the specific types
  933. // for more type safety.
  934. //
  935. // Possible runtime types of the union are [TextPart], [ReasoningPart], [FilePart],
  936. // [ToolPart], [StepStartPart], [StepFinishPart], [SnapshotPart], [PartPatchPart],
  937. // [AgentPart].
  938. func (r Part) AsUnion() PartUnion {
  939. return r.union
  940. }
  941. // Union satisfied by [TextPart], [ReasoningPart], [FilePart], [ToolPart],
  942. // [StepStartPart], [StepFinishPart], [SnapshotPart], [PartPatchPart] or
  943. // [AgentPart].
  944. type PartUnion interface {
  945. implementsPart()
  946. }
  947. func init() {
  948. apijson.RegisterUnion(
  949. reflect.TypeOf((*PartUnion)(nil)).Elem(),
  950. "type",
  951. apijson.UnionVariant{
  952. TypeFilter: gjson.JSON,
  953. Type: reflect.TypeOf(TextPart{}),
  954. DiscriminatorValue: "text",
  955. },
  956. apijson.UnionVariant{
  957. TypeFilter: gjson.JSON,
  958. Type: reflect.TypeOf(ReasoningPart{}),
  959. DiscriminatorValue: "reasoning",
  960. },
  961. apijson.UnionVariant{
  962. TypeFilter: gjson.JSON,
  963. Type: reflect.TypeOf(FilePart{}),
  964. DiscriminatorValue: "file",
  965. },
  966. apijson.UnionVariant{
  967. TypeFilter: gjson.JSON,
  968. Type: reflect.TypeOf(ToolPart{}),
  969. DiscriminatorValue: "tool",
  970. },
  971. apijson.UnionVariant{
  972. TypeFilter: gjson.JSON,
  973. Type: reflect.TypeOf(StepStartPart{}),
  974. DiscriminatorValue: "step-start",
  975. },
  976. apijson.UnionVariant{
  977. TypeFilter: gjson.JSON,
  978. Type: reflect.TypeOf(StepFinishPart{}),
  979. DiscriminatorValue: "step-finish",
  980. },
  981. apijson.UnionVariant{
  982. TypeFilter: gjson.JSON,
  983. Type: reflect.TypeOf(SnapshotPart{}),
  984. DiscriminatorValue: "snapshot",
  985. },
  986. apijson.UnionVariant{
  987. TypeFilter: gjson.JSON,
  988. Type: reflect.TypeOf(PartPatchPart{}),
  989. DiscriminatorValue: "patch",
  990. },
  991. apijson.UnionVariant{
  992. TypeFilter: gjson.JSON,
  993. Type: reflect.TypeOf(AgentPart{}),
  994. DiscriminatorValue: "agent",
  995. },
  996. )
  997. }
  998. type PartPatchPart struct {
  999. ID string `json:"id,required"`
  1000. Files []string `json:"files,required"`
  1001. Hash string `json:"hash,required"`
  1002. MessageID string `json:"messageID,required"`
  1003. SessionID string `json:"sessionID,required"`
  1004. Type PartPatchPartType `json:"type,required"`
  1005. JSON partPatchPartJSON `json:"-"`
  1006. }
  1007. // partPatchPartJSON contains the JSON metadata for the struct [PartPatchPart]
  1008. type partPatchPartJSON struct {
  1009. ID apijson.Field
  1010. Files apijson.Field
  1011. Hash apijson.Field
  1012. MessageID apijson.Field
  1013. SessionID apijson.Field
  1014. Type apijson.Field
  1015. raw string
  1016. ExtraFields map[string]apijson.Field
  1017. }
  1018. func (r *PartPatchPart) UnmarshalJSON(data []byte) (err error) {
  1019. return apijson.UnmarshalRoot(data, r)
  1020. }
  1021. func (r partPatchPartJSON) RawJSON() string {
  1022. return r.raw
  1023. }
  1024. func (r PartPatchPart) implementsPart() {}
  1025. type PartPatchPartType string
  1026. const (
  1027. PartPatchPartTypePatch PartPatchPartType = "patch"
  1028. )
  1029. func (r PartPatchPartType) IsKnown() bool {
  1030. switch r {
  1031. case PartPatchPartTypePatch:
  1032. return true
  1033. }
  1034. return false
  1035. }
  1036. type PartType string
  1037. const (
  1038. PartTypeText PartType = "text"
  1039. PartTypeReasoning PartType = "reasoning"
  1040. PartTypeFile PartType = "file"
  1041. PartTypeTool PartType = "tool"
  1042. PartTypeStepStart PartType = "step-start"
  1043. PartTypeStepFinish PartType = "step-finish"
  1044. PartTypeSnapshot PartType = "snapshot"
  1045. PartTypePatch PartType = "patch"
  1046. PartTypeAgent PartType = "agent"
  1047. )
  1048. func (r PartType) IsKnown() bool {
  1049. switch r {
  1050. case PartTypeText, PartTypeReasoning, PartTypeFile, PartTypeTool, PartTypeStepStart, PartTypeStepFinish, PartTypeSnapshot, PartTypePatch, PartTypeAgent:
  1051. return true
  1052. }
  1053. return false
  1054. }
  1055. type ReasoningPart struct {
  1056. ID string `json:"id,required"`
  1057. MessageID string `json:"messageID,required"`
  1058. SessionID string `json:"sessionID,required"`
  1059. Text string `json:"text,required"`
  1060. Time ReasoningPartTime `json:"time,required"`
  1061. Type ReasoningPartType `json:"type,required"`
  1062. Metadata map[string]interface{} `json:"metadata"`
  1063. JSON reasoningPartJSON `json:"-"`
  1064. }
  1065. // reasoningPartJSON contains the JSON metadata for the struct [ReasoningPart]
  1066. type reasoningPartJSON struct {
  1067. ID apijson.Field
  1068. MessageID apijson.Field
  1069. SessionID apijson.Field
  1070. Text apijson.Field
  1071. Time apijson.Field
  1072. Type apijson.Field
  1073. Metadata apijson.Field
  1074. raw string
  1075. ExtraFields map[string]apijson.Field
  1076. }
  1077. func (r *ReasoningPart) UnmarshalJSON(data []byte) (err error) {
  1078. return apijson.UnmarshalRoot(data, r)
  1079. }
  1080. func (r reasoningPartJSON) RawJSON() string {
  1081. return r.raw
  1082. }
  1083. func (r ReasoningPart) implementsPart() {}
  1084. type ReasoningPartTime struct {
  1085. Start float64 `json:"start,required"`
  1086. End float64 `json:"end"`
  1087. JSON reasoningPartTimeJSON `json:"-"`
  1088. }
  1089. // reasoningPartTimeJSON contains the JSON metadata for the struct
  1090. // [ReasoningPartTime]
  1091. type reasoningPartTimeJSON struct {
  1092. Start apijson.Field
  1093. End apijson.Field
  1094. raw string
  1095. ExtraFields map[string]apijson.Field
  1096. }
  1097. func (r *ReasoningPartTime) UnmarshalJSON(data []byte) (err error) {
  1098. return apijson.UnmarshalRoot(data, r)
  1099. }
  1100. func (r reasoningPartTimeJSON) RawJSON() string {
  1101. return r.raw
  1102. }
  1103. type ReasoningPartType string
  1104. const (
  1105. ReasoningPartTypeReasoning ReasoningPartType = "reasoning"
  1106. )
  1107. func (r ReasoningPartType) IsKnown() bool {
  1108. switch r {
  1109. case ReasoningPartTypeReasoning:
  1110. return true
  1111. }
  1112. return false
  1113. }
  1114. type Session struct {
  1115. ID string `json:"id,required"`
  1116. Time SessionTime `json:"time,required"`
  1117. Title string `json:"title,required"`
  1118. Version string `json:"version,required"`
  1119. ParentID string `json:"parentID"`
  1120. Revert SessionRevert `json:"revert"`
  1121. Share SessionShare `json:"share"`
  1122. JSON sessionJSON `json:"-"`
  1123. }
  1124. // sessionJSON contains the JSON metadata for the struct [Session]
  1125. type sessionJSON struct {
  1126. ID apijson.Field
  1127. Time apijson.Field
  1128. Title apijson.Field
  1129. Version apijson.Field
  1130. ParentID apijson.Field
  1131. Revert apijson.Field
  1132. Share apijson.Field
  1133. raw string
  1134. ExtraFields map[string]apijson.Field
  1135. }
  1136. func (r *Session) UnmarshalJSON(data []byte) (err error) {
  1137. return apijson.UnmarshalRoot(data, r)
  1138. }
  1139. func (r sessionJSON) RawJSON() string {
  1140. return r.raw
  1141. }
  1142. type SessionTime struct {
  1143. Created float64 `json:"created,required"`
  1144. Updated float64 `json:"updated,required"`
  1145. JSON sessionTimeJSON `json:"-"`
  1146. }
  1147. // sessionTimeJSON contains the JSON metadata for the struct [SessionTime]
  1148. type sessionTimeJSON struct {
  1149. Created apijson.Field
  1150. Updated apijson.Field
  1151. raw string
  1152. ExtraFields map[string]apijson.Field
  1153. }
  1154. func (r *SessionTime) UnmarshalJSON(data []byte) (err error) {
  1155. return apijson.UnmarshalRoot(data, r)
  1156. }
  1157. func (r sessionTimeJSON) RawJSON() string {
  1158. return r.raw
  1159. }
  1160. type SessionRevert struct {
  1161. MessageID string `json:"messageID,required"`
  1162. Diff string `json:"diff"`
  1163. PartID string `json:"partID"`
  1164. Snapshot string `json:"snapshot"`
  1165. JSON sessionRevertJSON `json:"-"`
  1166. }
  1167. // sessionRevertJSON contains the JSON metadata for the struct [SessionRevert]
  1168. type sessionRevertJSON struct {
  1169. MessageID apijson.Field
  1170. Diff apijson.Field
  1171. PartID apijson.Field
  1172. Snapshot apijson.Field
  1173. raw string
  1174. ExtraFields map[string]apijson.Field
  1175. }
  1176. func (r *SessionRevert) UnmarshalJSON(data []byte) (err error) {
  1177. return apijson.UnmarshalRoot(data, r)
  1178. }
  1179. func (r sessionRevertJSON) RawJSON() string {
  1180. return r.raw
  1181. }
  1182. type SessionShare struct {
  1183. URL string `json:"url,required"`
  1184. JSON sessionShareJSON `json:"-"`
  1185. }
  1186. // sessionShareJSON contains the JSON metadata for the struct [SessionShare]
  1187. type sessionShareJSON struct {
  1188. URL apijson.Field
  1189. raw string
  1190. ExtraFields map[string]apijson.Field
  1191. }
  1192. func (r *SessionShare) UnmarshalJSON(data []byte) (err error) {
  1193. return apijson.UnmarshalRoot(data, r)
  1194. }
  1195. func (r sessionShareJSON) RawJSON() string {
  1196. return r.raw
  1197. }
  1198. type SnapshotPart struct {
  1199. ID string `json:"id,required"`
  1200. MessageID string `json:"messageID,required"`
  1201. SessionID string `json:"sessionID,required"`
  1202. Snapshot string `json:"snapshot,required"`
  1203. Type SnapshotPartType `json:"type,required"`
  1204. JSON snapshotPartJSON `json:"-"`
  1205. }
  1206. // snapshotPartJSON contains the JSON metadata for the struct [SnapshotPart]
  1207. type snapshotPartJSON struct {
  1208. ID apijson.Field
  1209. MessageID apijson.Field
  1210. SessionID apijson.Field
  1211. Snapshot apijson.Field
  1212. Type apijson.Field
  1213. raw string
  1214. ExtraFields map[string]apijson.Field
  1215. }
  1216. func (r *SnapshotPart) UnmarshalJSON(data []byte) (err error) {
  1217. return apijson.UnmarshalRoot(data, r)
  1218. }
  1219. func (r snapshotPartJSON) RawJSON() string {
  1220. return r.raw
  1221. }
  1222. func (r SnapshotPart) implementsPart() {}
  1223. type SnapshotPartType string
  1224. const (
  1225. SnapshotPartTypeSnapshot SnapshotPartType = "snapshot"
  1226. )
  1227. func (r SnapshotPartType) IsKnown() bool {
  1228. switch r {
  1229. case SnapshotPartTypeSnapshot:
  1230. return true
  1231. }
  1232. return false
  1233. }
  1234. type StepFinishPart struct {
  1235. ID string `json:"id,required"`
  1236. Cost float64 `json:"cost,required"`
  1237. MessageID string `json:"messageID,required"`
  1238. SessionID string `json:"sessionID,required"`
  1239. Tokens StepFinishPartTokens `json:"tokens,required"`
  1240. Type StepFinishPartType `json:"type,required"`
  1241. JSON stepFinishPartJSON `json:"-"`
  1242. }
  1243. // stepFinishPartJSON contains the JSON metadata for the struct [StepFinishPart]
  1244. type stepFinishPartJSON struct {
  1245. ID apijson.Field
  1246. Cost apijson.Field
  1247. MessageID apijson.Field
  1248. SessionID apijson.Field
  1249. Tokens apijson.Field
  1250. Type apijson.Field
  1251. raw string
  1252. ExtraFields map[string]apijson.Field
  1253. }
  1254. func (r *StepFinishPart) UnmarshalJSON(data []byte) (err error) {
  1255. return apijson.UnmarshalRoot(data, r)
  1256. }
  1257. func (r stepFinishPartJSON) RawJSON() string {
  1258. return r.raw
  1259. }
  1260. func (r StepFinishPart) implementsPart() {}
  1261. type StepFinishPartTokens struct {
  1262. Cache StepFinishPartTokensCache `json:"cache,required"`
  1263. Input float64 `json:"input,required"`
  1264. Output float64 `json:"output,required"`
  1265. Reasoning float64 `json:"reasoning,required"`
  1266. JSON stepFinishPartTokensJSON `json:"-"`
  1267. }
  1268. // stepFinishPartTokensJSON contains the JSON metadata for the struct
  1269. // [StepFinishPartTokens]
  1270. type stepFinishPartTokensJSON struct {
  1271. Cache apijson.Field
  1272. Input apijson.Field
  1273. Output apijson.Field
  1274. Reasoning apijson.Field
  1275. raw string
  1276. ExtraFields map[string]apijson.Field
  1277. }
  1278. func (r *StepFinishPartTokens) UnmarshalJSON(data []byte) (err error) {
  1279. return apijson.UnmarshalRoot(data, r)
  1280. }
  1281. func (r stepFinishPartTokensJSON) RawJSON() string {
  1282. return r.raw
  1283. }
  1284. type StepFinishPartTokensCache struct {
  1285. Read float64 `json:"read,required"`
  1286. Write float64 `json:"write,required"`
  1287. JSON stepFinishPartTokensCacheJSON `json:"-"`
  1288. }
  1289. // stepFinishPartTokensCacheJSON contains the JSON metadata for the struct
  1290. // [StepFinishPartTokensCache]
  1291. type stepFinishPartTokensCacheJSON struct {
  1292. Read apijson.Field
  1293. Write apijson.Field
  1294. raw string
  1295. ExtraFields map[string]apijson.Field
  1296. }
  1297. func (r *StepFinishPartTokensCache) UnmarshalJSON(data []byte) (err error) {
  1298. return apijson.UnmarshalRoot(data, r)
  1299. }
  1300. func (r stepFinishPartTokensCacheJSON) RawJSON() string {
  1301. return r.raw
  1302. }
  1303. type StepFinishPartType string
  1304. const (
  1305. StepFinishPartTypeStepFinish StepFinishPartType = "step-finish"
  1306. )
  1307. func (r StepFinishPartType) IsKnown() bool {
  1308. switch r {
  1309. case StepFinishPartTypeStepFinish:
  1310. return true
  1311. }
  1312. return false
  1313. }
  1314. type StepStartPart struct {
  1315. ID string `json:"id,required"`
  1316. MessageID string `json:"messageID,required"`
  1317. SessionID string `json:"sessionID,required"`
  1318. Type StepStartPartType `json:"type,required"`
  1319. JSON stepStartPartJSON `json:"-"`
  1320. }
  1321. // stepStartPartJSON contains the JSON metadata for the struct [StepStartPart]
  1322. type stepStartPartJSON struct {
  1323. ID apijson.Field
  1324. MessageID apijson.Field
  1325. SessionID apijson.Field
  1326. Type apijson.Field
  1327. raw string
  1328. ExtraFields map[string]apijson.Field
  1329. }
  1330. func (r *StepStartPart) UnmarshalJSON(data []byte) (err error) {
  1331. return apijson.UnmarshalRoot(data, r)
  1332. }
  1333. func (r stepStartPartJSON) RawJSON() string {
  1334. return r.raw
  1335. }
  1336. func (r StepStartPart) implementsPart() {}
  1337. type StepStartPartType string
  1338. const (
  1339. StepStartPartTypeStepStart StepStartPartType = "step-start"
  1340. )
  1341. func (r StepStartPartType) IsKnown() bool {
  1342. switch r {
  1343. case StepStartPartTypeStepStart:
  1344. return true
  1345. }
  1346. return false
  1347. }
  1348. type SymbolSource struct {
  1349. Kind int64 `json:"kind,required"`
  1350. Name string `json:"name,required"`
  1351. Path string `json:"path,required"`
  1352. Range SymbolSourceRange `json:"range,required"`
  1353. Text FilePartSourceText `json:"text,required"`
  1354. Type SymbolSourceType `json:"type,required"`
  1355. JSON symbolSourceJSON `json:"-"`
  1356. }
  1357. // symbolSourceJSON contains the JSON metadata for the struct [SymbolSource]
  1358. type symbolSourceJSON struct {
  1359. Kind apijson.Field
  1360. Name apijson.Field
  1361. Path apijson.Field
  1362. Range apijson.Field
  1363. Text apijson.Field
  1364. Type apijson.Field
  1365. raw string
  1366. ExtraFields map[string]apijson.Field
  1367. }
  1368. func (r *SymbolSource) UnmarshalJSON(data []byte) (err error) {
  1369. return apijson.UnmarshalRoot(data, r)
  1370. }
  1371. func (r symbolSourceJSON) RawJSON() string {
  1372. return r.raw
  1373. }
  1374. func (r SymbolSource) implementsFilePartSource() {}
  1375. type SymbolSourceRange struct {
  1376. End SymbolSourceRangeEnd `json:"end,required"`
  1377. Start SymbolSourceRangeStart `json:"start,required"`
  1378. JSON symbolSourceRangeJSON `json:"-"`
  1379. }
  1380. // symbolSourceRangeJSON contains the JSON metadata for the struct
  1381. // [SymbolSourceRange]
  1382. type symbolSourceRangeJSON struct {
  1383. End apijson.Field
  1384. Start apijson.Field
  1385. raw string
  1386. ExtraFields map[string]apijson.Field
  1387. }
  1388. func (r *SymbolSourceRange) UnmarshalJSON(data []byte) (err error) {
  1389. return apijson.UnmarshalRoot(data, r)
  1390. }
  1391. func (r symbolSourceRangeJSON) RawJSON() string {
  1392. return r.raw
  1393. }
  1394. type SymbolSourceRangeEnd struct {
  1395. Character float64 `json:"character,required"`
  1396. Line float64 `json:"line,required"`
  1397. JSON symbolSourceRangeEndJSON `json:"-"`
  1398. }
  1399. // symbolSourceRangeEndJSON contains the JSON metadata for the struct
  1400. // [SymbolSourceRangeEnd]
  1401. type symbolSourceRangeEndJSON struct {
  1402. Character apijson.Field
  1403. Line apijson.Field
  1404. raw string
  1405. ExtraFields map[string]apijson.Field
  1406. }
  1407. func (r *SymbolSourceRangeEnd) UnmarshalJSON(data []byte) (err error) {
  1408. return apijson.UnmarshalRoot(data, r)
  1409. }
  1410. func (r symbolSourceRangeEndJSON) RawJSON() string {
  1411. return r.raw
  1412. }
  1413. type SymbolSourceRangeStart struct {
  1414. Character float64 `json:"character,required"`
  1415. Line float64 `json:"line,required"`
  1416. JSON symbolSourceRangeStartJSON `json:"-"`
  1417. }
  1418. // symbolSourceRangeStartJSON contains the JSON metadata for the struct
  1419. // [SymbolSourceRangeStart]
  1420. type symbolSourceRangeStartJSON struct {
  1421. Character apijson.Field
  1422. Line apijson.Field
  1423. raw string
  1424. ExtraFields map[string]apijson.Field
  1425. }
  1426. func (r *SymbolSourceRangeStart) UnmarshalJSON(data []byte) (err error) {
  1427. return apijson.UnmarshalRoot(data, r)
  1428. }
  1429. func (r symbolSourceRangeStartJSON) RawJSON() string {
  1430. return r.raw
  1431. }
  1432. type SymbolSourceType string
  1433. const (
  1434. SymbolSourceTypeSymbol SymbolSourceType = "symbol"
  1435. )
  1436. func (r SymbolSourceType) IsKnown() bool {
  1437. switch r {
  1438. case SymbolSourceTypeSymbol:
  1439. return true
  1440. }
  1441. return false
  1442. }
  1443. type SymbolSourceParam struct {
  1444. Kind param.Field[int64] `json:"kind,required"`
  1445. Name param.Field[string] `json:"name,required"`
  1446. Path param.Field[string] `json:"path,required"`
  1447. Range param.Field[SymbolSourceRangeParam] `json:"range,required"`
  1448. Text param.Field[FilePartSourceTextParam] `json:"text,required"`
  1449. Type param.Field[SymbolSourceType] `json:"type,required"`
  1450. }
  1451. func (r SymbolSourceParam) MarshalJSON() (data []byte, err error) {
  1452. return apijson.MarshalRoot(r)
  1453. }
  1454. func (r SymbolSourceParam) implementsFilePartSourceUnionParam() {}
  1455. type SymbolSourceRangeParam struct {
  1456. End param.Field[SymbolSourceRangeEndParam] `json:"end,required"`
  1457. Start param.Field[SymbolSourceRangeStartParam] `json:"start,required"`
  1458. }
  1459. func (r SymbolSourceRangeParam) MarshalJSON() (data []byte, err error) {
  1460. return apijson.MarshalRoot(r)
  1461. }
  1462. type SymbolSourceRangeEndParam struct {
  1463. Character param.Field[float64] `json:"character,required"`
  1464. Line param.Field[float64] `json:"line,required"`
  1465. }
  1466. func (r SymbolSourceRangeEndParam) MarshalJSON() (data []byte, err error) {
  1467. return apijson.MarshalRoot(r)
  1468. }
  1469. type SymbolSourceRangeStartParam struct {
  1470. Character param.Field[float64] `json:"character,required"`
  1471. Line param.Field[float64] `json:"line,required"`
  1472. }
  1473. func (r SymbolSourceRangeStartParam) MarshalJSON() (data []byte, err error) {
  1474. return apijson.MarshalRoot(r)
  1475. }
  1476. type TextPart struct {
  1477. ID string `json:"id,required"`
  1478. MessageID string `json:"messageID,required"`
  1479. SessionID string `json:"sessionID,required"`
  1480. Text string `json:"text,required"`
  1481. Type TextPartType `json:"type,required"`
  1482. Synthetic bool `json:"synthetic"`
  1483. Time TextPartTime `json:"time"`
  1484. JSON textPartJSON `json:"-"`
  1485. }
  1486. // textPartJSON contains the JSON metadata for the struct [TextPart]
  1487. type textPartJSON struct {
  1488. ID apijson.Field
  1489. MessageID apijson.Field
  1490. SessionID apijson.Field
  1491. Text apijson.Field
  1492. Type apijson.Field
  1493. Synthetic apijson.Field
  1494. Time apijson.Field
  1495. raw string
  1496. ExtraFields map[string]apijson.Field
  1497. }
  1498. func (r *TextPart) UnmarshalJSON(data []byte) (err error) {
  1499. return apijson.UnmarshalRoot(data, r)
  1500. }
  1501. func (r textPartJSON) RawJSON() string {
  1502. return r.raw
  1503. }
  1504. func (r TextPart) implementsPart() {}
  1505. type TextPartType string
  1506. const (
  1507. TextPartTypeText TextPartType = "text"
  1508. )
  1509. func (r TextPartType) IsKnown() bool {
  1510. switch r {
  1511. case TextPartTypeText:
  1512. return true
  1513. }
  1514. return false
  1515. }
  1516. type TextPartTime struct {
  1517. Start float64 `json:"start,required"`
  1518. End float64 `json:"end"`
  1519. JSON textPartTimeJSON `json:"-"`
  1520. }
  1521. // textPartTimeJSON contains the JSON metadata for the struct [TextPartTime]
  1522. type textPartTimeJSON struct {
  1523. Start apijson.Field
  1524. End apijson.Field
  1525. raw string
  1526. ExtraFields map[string]apijson.Field
  1527. }
  1528. func (r *TextPartTime) UnmarshalJSON(data []byte) (err error) {
  1529. return apijson.UnmarshalRoot(data, r)
  1530. }
  1531. func (r textPartTimeJSON) RawJSON() string {
  1532. return r.raw
  1533. }
  1534. type TextPartInputParam struct {
  1535. Text param.Field[string] `json:"text,required"`
  1536. Type param.Field[TextPartInputType] `json:"type,required"`
  1537. ID param.Field[string] `json:"id"`
  1538. Synthetic param.Field[bool] `json:"synthetic"`
  1539. Time param.Field[TextPartInputTimeParam] `json:"time"`
  1540. }
  1541. func (r TextPartInputParam) MarshalJSON() (data []byte, err error) {
  1542. return apijson.MarshalRoot(r)
  1543. }
  1544. func (r TextPartInputParam) implementsSessionChatParamsPartUnion() {}
  1545. type TextPartInputType string
  1546. const (
  1547. TextPartInputTypeText TextPartInputType = "text"
  1548. )
  1549. func (r TextPartInputType) IsKnown() bool {
  1550. switch r {
  1551. case TextPartInputTypeText:
  1552. return true
  1553. }
  1554. return false
  1555. }
  1556. type TextPartInputTimeParam struct {
  1557. Start param.Field[float64] `json:"start,required"`
  1558. End param.Field[float64] `json:"end"`
  1559. }
  1560. func (r TextPartInputTimeParam) MarshalJSON() (data []byte, err error) {
  1561. return apijson.MarshalRoot(r)
  1562. }
  1563. type ToolPart struct {
  1564. ID string `json:"id,required"`
  1565. CallID string `json:"callID,required"`
  1566. MessageID string `json:"messageID,required"`
  1567. SessionID string `json:"sessionID,required"`
  1568. State ToolPartState `json:"state,required"`
  1569. Tool string `json:"tool,required"`
  1570. Type ToolPartType `json:"type,required"`
  1571. JSON toolPartJSON `json:"-"`
  1572. }
  1573. // toolPartJSON contains the JSON metadata for the struct [ToolPart]
  1574. type toolPartJSON struct {
  1575. ID apijson.Field
  1576. CallID apijson.Field
  1577. MessageID apijson.Field
  1578. SessionID apijson.Field
  1579. State apijson.Field
  1580. Tool apijson.Field
  1581. Type apijson.Field
  1582. raw string
  1583. ExtraFields map[string]apijson.Field
  1584. }
  1585. func (r *ToolPart) UnmarshalJSON(data []byte) (err error) {
  1586. return apijson.UnmarshalRoot(data, r)
  1587. }
  1588. func (r toolPartJSON) RawJSON() string {
  1589. return r.raw
  1590. }
  1591. func (r ToolPart) implementsPart() {}
  1592. type ToolPartState struct {
  1593. Status ToolPartStateStatus `json:"status,required"`
  1594. Error string `json:"error"`
  1595. // This field can have the runtime type of [interface{}], [map[string]interface{}].
  1596. Input interface{} `json:"input"`
  1597. // This field can have the runtime type of [map[string]interface{}].
  1598. Metadata interface{} `json:"metadata"`
  1599. Output string `json:"output"`
  1600. // This field can have the runtime type of [ToolStateRunningTime],
  1601. // [ToolStateCompletedTime], [ToolStateErrorTime].
  1602. Time interface{} `json:"time"`
  1603. Title string `json:"title"`
  1604. JSON toolPartStateJSON `json:"-"`
  1605. union ToolPartStateUnion
  1606. }
  1607. // toolPartStateJSON contains the JSON metadata for the struct [ToolPartState]
  1608. type toolPartStateJSON struct {
  1609. Status apijson.Field
  1610. Error apijson.Field
  1611. Input apijson.Field
  1612. Metadata apijson.Field
  1613. Output apijson.Field
  1614. Time apijson.Field
  1615. Title apijson.Field
  1616. raw string
  1617. ExtraFields map[string]apijson.Field
  1618. }
  1619. func (r toolPartStateJSON) RawJSON() string {
  1620. return r.raw
  1621. }
  1622. func (r *ToolPartState) UnmarshalJSON(data []byte) (err error) {
  1623. *r = ToolPartState{}
  1624. err = apijson.UnmarshalRoot(data, &r.union)
  1625. if err != nil {
  1626. return err
  1627. }
  1628. return apijson.Port(r.union, &r)
  1629. }
  1630. // AsUnion returns a [ToolPartStateUnion] interface which you can cast to the
  1631. // specific types for more type safety.
  1632. //
  1633. // Possible runtime types of the union are [ToolStatePending], [ToolStateRunning],
  1634. // [ToolStateCompleted], [ToolStateError].
  1635. func (r ToolPartState) AsUnion() ToolPartStateUnion {
  1636. return r.union
  1637. }
  1638. // Union satisfied by [ToolStatePending], [ToolStateRunning], [ToolStateCompleted]
  1639. // or [ToolStateError].
  1640. type ToolPartStateUnion interface {
  1641. implementsToolPartState()
  1642. }
  1643. func init() {
  1644. apijson.RegisterUnion(
  1645. reflect.TypeOf((*ToolPartStateUnion)(nil)).Elem(),
  1646. "status",
  1647. apijson.UnionVariant{
  1648. TypeFilter: gjson.JSON,
  1649. Type: reflect.TypeOf(ToolStatePending{}),
  1650. DiscriminatorValue: "pending",
  1651. },
  1652. apijson.UnionVariant{
  1653. TypeFilter: gjson.JSON,
  1654. Type: reflect.TypeOf(ToolStateRunning{}),
  1655. DiscriminatorValue: "running",
  1656. },
  1657. apijson.UnionVariant{
  1658. TypeFilter: gjson.JSON,
  1659. Type: reflect.TypeOf(ToolStateCompleted{}),
  1660. DiscriminatorValue: "completed",
  1661. },
  1662. apijson.UnionVariant{
  1663. TypeFilter: gjson.JSON,
  1664. Type: reflect.TypeOf(ToolStateError{}),
  1665. DiscriminatorValue: "error",
  1666. },
  1667. )
  1668. }
  1669. type ToolPartStateStatus string
  1670. const (
  1671. ToolPartStateStatusPending ToolPartStateStatus = "pending"
  1672. ToolPartStateStatusRunning ToolPartStateStatus = "running"
  1673. ToolPartStateStatusCompleted ToolPartStateStatus = "completed"
  1674. ToolPartStateStatusError ToolPartStateStatus = "error"
  1675. )
  1676. func (r ToolPartStateStatus) IsKnown() bool {
  1677. switch r {
  1678. case ToolPartStateStatusPending, ToolPartStateStatusRunning, ToolPartStateStatusCompleted, ToolPartStateStatusError:
  1679. return true
  1680. }
  1681. return false
  1682. }
  1683. type ToolPartType string
  1684. const (
  1685. ToolPartTypeTool ToolPartType = "tool"
  1686. )
  1687. func (r ToolPartType) IsKnown() bool {
  1688. switch r {
  1689. case ToolPartTypeTool:
  1690. return true
  1691. }
  1692. return false
  1693. }
  1694. type ToolStateCompleted struct {
  1695. Input map[string]interface{} `json:"input,required"`
  1696. Metadata map[string]interface{} `json:"metadata,required"`
  1697. Output string `json:"output,required"`
  1698. Status ToolStateCompletedStatus `json:"status,required"`
  1699. Time ToolStateCompletedTime `json:"time,required"`
  1700. Title string `json:"title,required"`
  1701. JSON toolStateCompletedJSON `json:"-"`
  1702. }
  1703. // toolStateCompletedJSON contains the JSON metadata for the struct
  1704. // [ToolStateCompleted]
  1705. type toolStateCompletedJSON struct {
  1706. Input apijson.Field
  1707. Metadata apijson.Field
  1708. Output apijson.Field
  1709. Status apijson.Field
  1710. Time apijson.Field
  1711. Title apijson.Field
  1712. raw string
  1713. ExtraFields map[string]apijson.Field
  1714. }
  1715. func (r *ToolStateCompleted) UnmarshalJSON(data []byte) (err error) {
  1716. return apijson.UnmarshalRoot(data, r)
  1717. }
  1718. func (r toolStateCompletedJSON) RawJSON() string {
  1719. return r.raw
  1720. }
  1721. func (r ToolStateCompleted) implementsToolPartState() {}
  1722. type ToolStateCompletedStatus string
  1723. const (
  1724. ToolStateCompletedStatusCompleted ToolStateCompletedStatus = "completed"
  1725. )
  1726. func (r ToolStateCompletedStatus) IsKnown() bool {
  1727. switch r {
  1728. case ToolStateCompletedStatusCompleted:
  1729. return true
  1730. }
  1731. return false
  1732. }
  1733. type ToolStateCompletedTime struct {
  1734. End float64 `json:"end,required"`
  1735. Start float64 `json:"start,required"`
  1736. JSON toolStateCompletedTimeJSON `json:"-"`
  1737. }
  1738. // toolStateCompletedTimeJSON contains the JSON metadata for the struct
  1739. // [ToolStateCompletedTime]
  1740. type toolStateCompletedTimeJSON struct {
  1741. End apijson.Field
  1742. Start apijson.Field
  1743. raw string
  1744. ExtraFields map[string]apijson.Field
  1745. }
  1746. func (r *ToolStateCompletedTime) UnmarshalJSON(data []byte) (err error) {
  1747. return apijson.UnmarshalRoot(data, r)
  1748. }
  1749. func (r toolStateCompletedTimeJSON) RawJSON() string {
  1750. return r.raw
  1751. }
  1752. type ToolStateError struct {
  1753. Error string `json:"error,required"`
  1754. Input map[string]interface{} `json:"input,required"`
  1755. Status ToolStateErrorStatus `json:"status,required"`
  1756. Time ToolStateErrorTime `json:"time,required"`
  1757. Metadata map[string]interface{} `json:"metadata"`
  1758. JSON toolStateErrorJSON `json:"-"`
  1759. }
  1760. // toolStateErrorJSON contains the JSON metadata for the struct [ToolStateError]
  1761. type toolStateErrorJSON struct {
  1762. Error apijson.Field
  1763. Input apijson.Field
  1764. Status apijson.Field
  1765. Time apijson.Field
  1766. Metadata apijson.Field
  1767. raw string
  1768. ExtraFields map[string]apijson.Field
  1769. }
  1770. func (r *ToolStateError) UnmarshalJSON(data []byte) (err error) {
  1771. return apijson.UnmarshalRoot(data, r)
  1772. }
  1773. func (r toolStateErrorJSON) RawJSON() string {
  1774. return r.raw
  1775. }
  1776. func (r ToolStateError) implementsToolPartState() {}
  1777. type ToolStateErrorStatus string
  1778. const (
  1779. ToolStateErrorStatusError ToolStateErrorStatus = "error"
  1780. )
  1781. func (r ToolStateErrorStatus) IsKnown() bool {
  1782. switch r {
  1783. case ToolStateErrorStatusError:
  1784. return true
  1785. }
  1786. return false
  1787. }
  1788. type ToolStateErrorTime struct {
  1789. End float64 `json:"end,required"`
  1790. Start float64 `json:"start,required"`
  1791. JSON toolStateErrorTimeJSON `json:"-"`
  1792. }
  1793. // toolStateErrorTimeJSON contains the JSON metadata for the struct
  1794. // [ToolStateErrorTime]
  1795. type toolStateErrorTimeJSON struct {
  1796. End apijson.Field
  1797. Start apijson.Field
  1798. raw string
  1799. ExtraFields map[string]apijson.Field
  1800. }
  1801. func (r *ToolStateErrorTime) UnmarshalJSON(data []byte) (err error) {
  1802. return apijson.UnmarshalRoot(data, r)
  1803. }
  1804. func (r toolStateErrorTimeJSON) RawJSON() string {
  1805. return r.raw
  1806. }
  1807. type ToolStatePending struct {
  1808. Status ToolStatePendingStatus `json:"status,required"`
  1809. JSON toolStatePendingJSON `json:"-"`
  1810. }
  1811. // toolStatePendingJSON contains the JSON metadata for the struct
  1812. // [ToolStatePending]
  1813. type toolStatePendingJSON struct {
  1814. Status apijson.Field
  1815. raw string
  1816. ExtraFields map[string]apijson.Field
  1817. }
  1818. func (r *ToolStatePending) UnmarshalJSON(data []byte) (err error) {
  1819. return apijson.UnmarshalRoot(data, r)
  1820. }
  1821. func (r toolStatePendingJSON) RawJSON() string {
  1822. return r.raw
  1823. }
  1824. func (r ToolStatePending) implementsToolPartState() {}
  1825. type ToolStatePendingStatus string
  1826. const (
  1827. ToolStatePendingStatusPending ToolStatePendingStatus = "pending"
  1828. )
  1829. func (r ToolStatePendingStatus) IsKnown() bool {
  1830. switch r {
  1831. case ToolStatePendingStatusPending:
  1832. return true
  1833. }
  1834. return false
  1835. }
  1836. type ToolStateRunning struct {
  1837. Status ToolStateRunningStatus `json:"status,required"`
  1838. Time ToolStateRunningTime `json:"time,required"`
  1839. Input interface{} `json:"input"`
  1840. Metadata map[string]interface{} `json:"metadata"`
  1841. Title string `json:"title"`
  1842. JSON toolStateRunningJSON `json:"-"`
  1843. }
  1844. // toolStateRunningJSON contains the JSON metadata for the struct
  1845. // [ToolStateRunning]
  1846. type toolStateRunningJSON struct {
  1847. Status apijson.Field
  1848. Time apijson.Field
  1849. Input apijson.Field
  1850. Metadata apijson.Field
  1851. Title apijson.Field
  1852. raw string
  1853. ExtraFields map[string]apijson.Field
  1854. }
  1855. func (r *ToolStateRunning) UnmarshalJSON(data []byte) (err error) {
  1856. return apijson.UnmarshalRoot(data, r)
  1857. }
  1858. func (r toolStateRunningJSON) RawJSON() string {
  1859. return r.raw
  1860. }
  1861. func (r ToolStateRunning) implementsToolPartState() {}
  1862. type ToolStateRunningStatus string
  1863. const (
  1864. ToolStateRunningStatusRunning ToolStateRunningStatus = "running"
  1865. )
  1866. func (r ToolStateRunningStatus) IsKnown() bool {
  1867. switch r {
  1868. case ToolStateRunningStatusRunning:
  1869. return true
  1870. }
  1871. return false
  1872. }
  1873. type ToolStateRunningTime struct {
  1874. Start float64 `json:"start,required"`
  1875. JSON toolStateRunningTimeJSON `json:"-"`
  1876. }
  1877. // toolStateRunningTimeJSON contains the JSON metadata for the struct
  1878. // [ToolStateRunningTime]
  1879. type toolStateRunningTimeJSON struct {
  1880. Start apijson.Field
  1881. raw string
  1882. ExtraFields map[string]apijson.Field
  1883. }
  1884. func (r *ToolStateRunningTime) UnmarshalJSON(data []byte) (err error) {
  1885. return apijson.UnmarshalRoot(data, r)
  1886. }
  1887. func (r toolStateRunningTimeJSON) RawJSON() string {
  1888. return r.raw
  1889. }
  1890. type UserMessage struct {
  1891. ID string `json:"id,required"`
  1892. Role UserMessageRole `json:"role,required"`
  1893. SessionID string `json:"sessionID,required"`
  1894. Time UserMessageTime `json:"time,required"`
  1895. JSON userMessageJSON `json:"-"`
  1896. }
  1897. // userMessageJSON contains the JSON metadata for the struct [UserMessage]
  1898. type userMessageJSON struct {
  1899. ID apijson.Field
  1900. Role apijson.Field
  1901. SessionID apijson.Field
  1902. Time apijson.Field
  1903. raw string
  1904. ExtraFields map[string]apijson.Field
  1905. }
  1906. func (r *UserMessage) UnmarshalJSON(data []byte) (err error) {
  1907. return apijson.UnmarshalRoot(data, r)
  1908. }
  1909. func (r userMessageJSON) RawJSON() string {
  1910. return r.raw
  1911. }
  1912. func (r UserMessage) implementsMessage() {}
  1913. type UserMessageRole string
  1914. const (
  1915. UserMessageRoleUser UserMessageRole = "user"
  1916. )
  1917. func (r UserMessageRole) IsKnown() bool {
  1918. switch r {
  1919. case UserMessageRoleUser:
  1920. return true
  1921. }
  1922. return false
  1923. }
  1924. type UserMessageTime struct {
  1925. Created float64 `json:"created,required"`
  1926. JSON userMessageTimeJSON `json:"-"`
  1927. }
  1928. // userMessageTimeJSON contains the JSON metadata for the struct [UserMessageTime]
  1929. type userMessageTimeJSON struct {
  1930. Created apijson.Field
  1931. raw string
  1932. ExtraFields map[string]apijson.Field
  1933. }
  1934. func (r *UserMessageTime) UnmarshalJSON(data []byte) (err error) {
  1935. return apijson.UnmarshalRoot(data, r)
  1936. }
  1937. func (r userMessageTimeJSON) RawJSON() string {
  1938. return r.raw
  1939. }
  1940. type SessionMessageResponse struct {
  1941. Info Message `json:"info,required"`
  1942. Parts []Part `json:"parts,required"`
  1943. JSON sessionMessageResponseJSON `json:"-"`
  1944. }
  1945. // sessionMessageResponseJSON contains the JSON metadata for the struct
  1946. // [SessionMessageResponse]
  1947. type sessionMessageResponseJSON struct {
  1948. Info apijson.Field
  1949. Parts apijson.Field
  1950. raw string
  1951. ExtraFields map[string]apijson.Field
  1952. }
  1953. func (r *SessionMessageResponse) UnmarshalJSON(data []byte) (err error) {
  1954. return apijson.UnmarshalRoot(data, r)
  1955. }
  1956. func (r sessionMessageResponseJSON) RawJSON() string {
  1957. return r.raw
  1958. }
  1959. type SessionMessagesResponse struct {
  1960. Info Message `json:"info,required"`
  1961. Parts []Part `json:"parts,required"`
  1962. JSON sessionMessagesResponseJSON `json:"-"`
  1963. }
  1964. // sessionMessagesResponseJSON contains the JSON metadata for the struct
  1965. // [SessionMessagesResponse]
  1966. type sessionMessagesResponseJSON struct {
  1967. Info apijson.Field
  1968. Parts apijson.Field
  1969. raw string
  1970. ExtraFields map[string]apijson.Field
  1971. }
  1972. func (r *SessionMessagesResponse) UnmarshalJSON(data []byte) (err error) {
  1973. return apijson.UnmarshalRoot(data, r)
  1974. }
  1975. func (r sessionMessagesResponseJSON) RawJSON() string {
  1976. return r.raw
  1977. }
  1978. type SessionNewParams struct {
  1979. ParentID param.Field[string] `json:"parentID"`
  1980. Title param.Field[string] `json:"title"`
  1981. }
  1982. func (r SessionNewParams) MarshalJSON() (data []byte, err error) {
  1983. return apijson.MarshalRoot(r)
  1984. }
  1985. type SessionUpdateParams struct {
  1986. Title param.Field[string] `json:"title"`
  1987. }
  1988. func (r SessionUpdateParams) MarshalJSON() (data []byte, err error) {
  1989. return apijson.MarshalRoot(r)
  1990. }
  1991. type SessionChatParams struct {
  1992. ModelID param.Field[string] `json:"modelID,required"`
  1993. Parts param.Field[[]SessionChatParamsPartUnion] `json:"parts,required"`
  1994. ProviderID param.Field[string] `json:"providerID,required"`
  1995. Agent param.Field[string] `json:"agent"`
  1996. MessageID param.Field[string] `json:"messageID"`
  1997. System param.Field[string] `json:"system"`
  1998. Tools param.Field[map[string]bool] `json:"tools"`
  1999. }
  2000. func (r SessionChatParams) MarshalJSON() (data []byte, err error) {
  2001. return apijson.MarshalRoot(r)
  2002. }
  2003. type SessionChatParamsPart struct {
  2004. Type param.Field[SessionChatParamsPartsType] `json:"type,required"`
  2005. ID param.Field[string] `json:"id"`
  2006. Filename param.Field[string] `json:"filename"`
  2007. Mime param.Field[string] `json:"mime"`
  2008. Name param.Field[string] `json:"name"`
  2009. Source param.Field[interface{}] `json:"source"`
  2010. Synthetic param.Field[bool] `json:"synthetic"`
  2011. Text param.Field[string] `json:"text"`
  2012. Time param.Field[interface{}] `json:"time"`
  2013. URL param.Field[string] `json:"url"`
  2014. }
  2015. func (r SessionChatParamsPart) MarshalJSON() (data []byte, err error) {
  2016. return apijson.MarshalRoot(r)
  2017. }
  2018. func (r SessionChatParamsPart) implementsSessionChatParamsPartUnion() {}
  2019. // Satisfied by [TextPartInputParam], [FilePartInputParam], [AgentPartInputParam],
  2020. // [SessionChatParamsPart].
  2021. type SessionChatParamsPartUnion interface {
  2022. implementsSessionChatParamsPartUnion()
  2023. }
  2024. type SessionChatParamsPartsType string
  2025. const (
  2026. SessionChatParamsPartsTypeText SessionChatParamsPartsType = "text"
  2027. SessionChatParamsPartsTypeFile SessionChatParamsPartsType = "file"
  2028. SessionChatParamsPartsTypeAgent SessionChatParamsPartsType = "agent"
  2029. )
  2030. func (r SessionChatParamsPartsType) IsKnown() bool {
  2031. switch r {
  2032. case SessionChatParamsPartsTypeText, SessionChatParamsPartsTypeFile, SessionChatParamsPartsTypeAgent:
  2033. return true
  2034. }
  2035. return false
  2036. }
  2037. type SessionInitParams struct {
  2038. MessageID param.Field[string] `json:"messageID,required"`
  2039. ModelID param.Field[string] `json:"modelID,required"`
  2040. ProviderID param.Field[string] `json:"providerID,required"`
  2041. }
  2042. func (r SessionInitParams) MarshalJSON() (data []byte, err error) {
  2043. return apijson.MarshalRoot(r)
  2044. }
  2045. type SessionRevertParams struct {
  2046. MessageID param.Field[string] `json:"messageID,required"`
  2047. PartID param.Field[string] `json:"partID"`
  2048. }
  2049. func (r SessionRevertParams) MarshalJSON() (data []byte, err error) {
  2050. return apijson.MarshalRoot(r)
  2051. }
  2052. type SessionShellParams struct {
  2053. Agent param.Field[string] `json:"agent,required"`
  2054. Command param.Field[string] `json:"command,required"`
  2055. }
  2056. func (r SessionShellParams) MarshalJSON() (data []byte, err error) {
  2057. return apijson.MarshalRoot(r)
  2058. }
  2059. type SessionSummarizeParams struct {
  2060. ModelID param.Field[string] `json:"modelID,required"`
  2061. ProviderID param.Field[string] `json:"providerID,required"`
  2062. }
  2063. func (r SessionSummarizeParams) MarshalJSON() (data []byte, err error) {
  2064. return apijson.MarshalRoot(r)
  2065. }