session.go 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430
  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 *[]Message, 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. Parts []AssistantMessagePart `json:"parts,required"`
  140. Path AssistantMessagePath `json:"path,required"`
  141. ProviderID string `json:"providerID,required"`
  142. Role AssistantMessageRole `json:"role,required"`
  143. SessionID string `json:"sessionID,required"`
  144. System []string `json:"system,required"`
  145. Time AssistantMessageTime `json:"time,required"`
  146. Tokens AssistantMessageTokens `json:"tokens,required"`
  147. Error AssistantMessageError `json:"error"`
  148. Summary bool `json:"summary"`
  149. JSON assistantMessageJSON `json:"-"`
  150. }
  151. // assistantMessageJSON contains the JSON metadata for the struct
  152. // [AssistantMessage]
  153. type assistantMessageJSON struct {
  154. ID apijson.Field
  155. Cost apijson.Field
  156. ModelID apijson.Field
  157. Parts apijson.Field
  158. Path apijson.Field
  159. ProviderID apijson.Field
  160. Role apijson.Field
  161. SessionID apijson.Field
  162. System apijson.Field
  163. Time apijson.Field
  164. Tokens apijson.Field
  165. Error apijson.Field
  166. Summary apijson.Field
  167. raw string
  168. ExtraFields map[string]apijson.Field
  169. }
  170. func (r *AssistantMessage) UnmarshalJSON(data []byte) (err error) {
  171. return apijson.UnmarshalRoot(data, r)
  172. }
  173. func (r assistantMessageJSON) RawJSON() string {
  174. return r.raw
  175. }
  176. func (r AssistantMessage) implementsMessage() {}
  177. type AssistantMessagePath struct {
  178. Cwd string `json:"cwd,required"`
  179. Root string `json:"root,required"`
  180. JSON assistantMessagePathJSON `json:"-"`
  181. }
  182. // assistantMessagePathJSON contains the JSON metadata for the struct
  183. // [AssistantMessagePath]
  184. type assistantMessagePathJSON struct {
  185. Cwd apijson.Field
  186. Root apijson.Field
  187. raw string
  188. ExtraFields map[string]apijson.Field
  189. }
  190. func (r *AssistantMessagePath) UnmarshalJSON(data []byte) (err error) {
  191. return apijson.UnmarshalRoot(data, r)
  192. }
  193. func (r assistantMessagePathJSON) RawJSON() string {
  194. return r.raw
  195. }
  196. type AssistantMessageRole string
  197. const (
  198. AssistantMessageRoleAssistant AssistantMessageRole = "assistant"
  199. )
  200. func (r AssistantMessageRole) IsKnown() bool {
  201. switch r {
  202. case AssistantMessageRoleAssistant:
  203. return true
  204. }
  205. return false
  206. }
  207. type AssistantMessageTime struct {
  208. Created float64 `json:"created,required"`
  209. Completed float64 `json:"completed"`
  210. JSON assistantMessageTimeJSON `json:"-"`
  211. }
  212. // assistantMessageTimeJSON contains the JSON metadata for the struct
  213. // [AssistantMessageTime]
  214. type assistantMessageTimeJSON struct {
  215. Created apijson.Field
  216. Completed apijson.Field
  217. raw string
  218. ExtraFields map[string]apijson.Field
  219. }
  220. func (r *AssistantMessageTime) UnmarshalJSON(data []byte) (err error) {
  221. return apijson.UnmarshalRoot(data, r)
  222. }
  223. func (r assistantMessageTimeJSON) RawJSON() string {
  224. return r.raw
  225. }
  226. type AssistantMessageTokens struct {
  227. Cache AssistantMessageTokensCache `json:"cache,required"`
  228. Input float64 `json:"input,required"`
  229. Output float64 `json:"output,required"`
  230. Reasoning float64 `json:"reasoning,required"`
  231. JSON assistantMessageTokensJSON `json:"-"`
  232. }
  233. // assistantMessageTokensJSON contains the JSON metadata for the struct
  234. // [AssistantMessageTokens]
  235. type assistantMessageTokensJSON struct {
  236. Cache apijson.Field
  237. Input apijson.Field
  238. Output apijson.Field
  239. Reasoning apijson.Field
  240. raw string
  241. ExtraFields map[string]apijson.Field
  242. }
  243. func (r *AssistantMessageTokens) UnmarshalJSON(data []byte) (err error) {
  244. return apijson.UnmarshalRoot(data, r)
  245. }
  246. func (r assistantMessageTokensJSON) RawJSON() string {
  247. return r.raw
  248. }
  249. type AssistantMessageTokensCache struct {
  250. Read float64 `json:"read,required"`
  251. Write float64 `json:"write,required"`
  252. JSON assistantMessageTokensCacheJSON `json:"-"`
  253. }
  254. // assistantMessageTokensCacheJSON contains the JSON metadata for the struct
  255. // [AssistantMessageTokensCache]
  256. type assistantMessageTokensCacheJSON struct {
  257. Read apijson.Field
  258. Write apijson.Field
  259. raw string
  260. ExtraFields map[string]apijson.Field
  261. }
  262. func (r *AssistantMessageTokensCache) UnmarshalJSON(data []byte) (err error) {
  263. return apijson.UnmarshalRoot(data, r)
  264. }
  265. func (r assistantMessageTokensCacheJSON) RawJSON() string {
  266. return r.raw
  267. }
  268. type AssistantMessageError struct {
  269. // This field can have the runtime type of [shared.ProviderAuthErrorData],
  270. // [shared.UnknownErrorData], [interface{}].
  271. Data interface{} `json:"data,required"`
  272. Name AssistantMessageErrorName `json:"name,required"`
  273. JSON assistantMessageErrorJSON `json:"-"`
  274. union AssistantMessageErrorUnion
  275. }
  276. // assistantMessageErrorJSON contains the JSON metadata for the struct
  277. // [AssistantMessageError]
  278. type assistantMessageErrorJSON struct {
  279. Data apijson.Field
  280. Name apijson.Field
  281. raw string
  282. ExtraFields map[string]apijson.Field
  283. }
  284. func (r assistantMessageErrorJSON) RawJSON() string {
  285. return r.raw
  286. }
  287. func (r *AssistantMessageError) UnmarshalJSON(data []byte) (err error) {
  288. *r = AssistantMessageError{}
  289. err = apijson.UnmarshalRoot(data, &r.union)
  290. if err != nil {
  291. return err
  292. }
  293. return apijson.Port(r.union, &r)
  294. }
  295. // AsUnion returns a [AssistantMessageErrorUnion] interface which you can cast to
  296. // the specific types for more type safety.
  297. //
  298. // Possible runtime types of the union are [shared.ProviderAuthError],
  299. // [shared.UnknownError], [AssistantMessageErrorMessageOutputLengthError].
  300. func (r AssistantMessageError) AsUnion() AssistantMessageErrorUnion {
  301. return r.union
  302. }
  303. // Union satisfied by [shared.ProviderAuthError], [shared.UnknownError] or
  304. // [AssistantMessageErrorMessageOutputLengthError].
  305. type AssistantMessageErrorUnion interface {
  306. ImplementsAssistantMessageError()
  307. }
  308. func init() {
  309. apijson.RegisterUnion(
  310. reflect.TypeOf((*AssistantMessageErrorUnion)(nil)).Elem(),
  311. "name",
  312. apijson.UnionVariant{
  313. TypeFilter: gjson.JSON,
  314. Type: reflect.TypeOf(shared.ProviderAuthError{}),
  315. DiscriminatorValue: "ProviderAuthError",
  316. },
  317. apijson.UnionVariant{
  318. TypeFilter: gjson.JSON,
  319. Type: reflect.TypeOf(shared.UnknownError{}),
  320. DiscriminatorValue: "UnknownError",
  321. },
  322. apijson.UnionVariant{
  323. TypeFilter: gjson.JSON,
  324. Type: reflect.TypeOf(AssistantMessageErrorMessageOutputLengthError{}),
  325. DiscriminatorValue: "MessageOutputLengthError",
  326. },
  327. )
  328. }
  329. type AssistantMessageErrorMessageOutputLengthError struct {
  330. Data interface{} `json:"data,required"`
  331. Name AssistantMessageErrorMessageOutputLengthErrorName `json:"name,required"`
  332. JSON assistantMessageErrorMessageOutputLengthErrorJSON `json:"-"`
  333. }
  334. // assistantMessageErrorMessageOutputLengthErrorJSON contains the JSON metadata for
  335. // the struct [AssistantMessageErrorMessageOutputLengthError]
  336. type assistantMessageErrorMessageOutputLengthErrorJSON struct {
  337. Data apijson.Field
  338. Name apijson.Field
  339. raw string
  340. ExtraFields map[string]apijson.Field
  341. }
  342. func (r *AssistantMessageErrorMessageOutputLengthError) UnmarshalJSON(data []byte) (err error) {
  343. return apijson.UnmarshalRoot(data, r)
  344. }
  345. func (r assistantMessageErrorMessageOutputLengthErrorJSON) RawJSON() string {
  346. return r.raw
  347. }
  348. func (r AssistantMessageErrorMessageOutputLengthError) ImplementsAssistantMessageError() {}
  349. type AssistantMessageErrorMessageOutputLengthErrorName string
  350. const (
  351. AssistantMessageErrorMessageOutputLengthErrorNameMessageOutputLengthError AssistantMessageErrorMessageOutputLengthErrorName = "MessageOutputLengthError"
  352. )
  353. func (r AssistantMessageErrorMessageOutputLengthErrorName) IsKnown() bool {
  354. switch r {
  355. case AssistantMessageErrorMessageOutputLengthErrorNameMessageOutputLengthError:
  356. return true
  357. }
  358. return false
  359. }
  360. type AssistantMessageErrorName string
  361. const (
  362. AssistantMessageErrorNameProviderAuthError AssistantMessageErrorName = "ProviderAuthError"
  363. AssistantMessageErrorNameUnknownError AssistantMessageErrorName = "UnknownError"
  364. AssistantMessageErrorNameMessageOutputLengthError AssistantMessageErrorName = "MessageOutputLengthError"
  365. )
  366. func (r AssistantMessageErrorName) IsKnown() bool {
  367. switch r {
  368. case AssistantMessageErrorNameProviderAuthError, AssistantMessageErrorNameUnknownError, AssistantMessageErrorNameMessageOutputLengthError:
  369. return true
  370. }
  371. return false
  372. }
  373. type AssistantMessagePart struct {
  374. Type AssistantMessagePartType `json:"type,required"`
  375. ID string `json:"id"`
  376. // This field can have the runtime type of [ToolPartState].
  377. State interface{} `json:"state"`
  378. Text string `json:"text"`
  379. Tool string `json:"tool"`
  380. JSON assistantMessagePartJSON `json:"-"`
  381. union AssistantMessagePartUnion
  382. }
  383. // assistantMessagePartJSON contains the JSON metadata for the struct
  384. // [AssistantMessagePart]
  385. type assistantMessagePartJSON struct {
  386. Type apijson.Field
  387. ID apijson.Field
  388. State apijson.Field
  389. Text apijson.Field
  390. Tool apijson.Field
  391. raw string
  392. ExtraFields map[string]apijson.Field
  393. }
  394. func (r assistantMessagePartJSON) RawJSON() string {
  395. return r.raw
  396. }
  397. func (r *AssistantMessagePart) UnmarshalJSON(data []byte) (err error) {
  398. *r = AssistantMessagePart{}
  399. err = apijson.UnmarshalRoot(data, &r.union)
  400. if err != nil {
  401. return err
  402. }
  403. return apijson.Port(r.union, &r)
  404. }
  405. // AsUnion returns a [AssistantMessagePartUnion] interface which you can cast to
  406. // the specific types for more type safety.
  407. //
  408. // Possible runtime types of the union are [TextPart], [ToolPart], [StepStartPart].
  409. func (r AssistantMessagePart) AsUnion() AssistantMessagePartUnion {
  410. return r.union
  411. }
  412. // Union satisfied by [TextPart], [ToolPart] or [StepStartPart].
  413. type AssistantMessagePartUnion interface {
  414. implementsAssistantMessagePart()
  415. }
  416. func init() {
  417. apijson.RegisterUnion(
  418. reflect.TypeOf((*AssistantMessagePartUnion)(nil)).Elem(),
  419. "type",
  420. apijson.UnionVariant{
  421. TypeFilter: gjson.JSON,
  422. Type: reflect.TypeOf(TextPart{}),
  423. DiscriminatorValue: "text",
  424. },
  425. apijson.UnionVariant{
  426. TypeFilter: gjson.JSON,
  427. Type: reflect.TypeOf(ToolPart{}),
  428. DiscriminatorValue: "tool",
  429. },
  430. apijson.UnionVariant{
  431. TypeFilter: gjson.JSON,
  432. Type: reflect.TypeOf(StepStartPart{}),
  433. DiscriminatorValue: "step-start",
  434. },
  435. )
  436. }
  437. type AssistantMessagePartType string
  438. const (
  439. AssistantMessagePartTypeText AssistantMessagePartType = "text"
  440. AssistantMessagePartTypeTool AssistantMessagePartType = "tool"
  441. AssistantMessagePartTypeStepStart AssistantMessagePartType = "step-start"
  442. )
  443. func (r AssistantMessagePartType) IsKnown() bool {
  444. switch r {
  445. case AssistantMessagePartTypeText, AssistantMessagePartTypeTool, AssistantMessagePartTypeStepStart:
  446. return true
  447. }
  448. return false
  449. }
  450. type FilePart struct {
  451. Mime string `json:"mime,required"`
  452. Type FilePartType `json:"type,required"`
  453. URL string `json:"url,required"`
  454. Filename string `json:"filename"`
  455. JSON filePartJSON `json:"-"`
  456. }
  457. // filePartJSON contains the JSON metadata for the struct [FilePart]
  458. type filePartJSON struct {
  459. Mime apijson.Field
  460. Type apijson.Field
  461. URL apijson.Field
  462. Filename apijson.Field
  463. raw string
  464. ExtraFields map[string]apijson.Field
  465. }
  466. func (r *FilePart) UnmarshalJSON(data []byte) (err error) {
  467. return apijson.UnmarshalRoot(data, r)
  468. }
  469. func (r filePartJSON) RawJSON() string {
  470. return r.raw
  471. }
  472. func (r FilePart) implementsUserMessagePart() {}
  473. type FilePartType string
  474. const (
  475. FilePartTypeFile FilePartType = "file"
  476. )
  477. func (r FilePartType) IsKnown() bool {
  478. switch r {
  479. case FilePartTypeFile:
  480. return true
  481. }
  482. return false
  483. }
  484. type FilePartParam struct {
  485. Mime param.Field[string] `json:"mime,required"`
  486. Type param.Field[FilePartType] `json:"type,required"`
  487. URL param.Field[string] `json:"url,required"`
  488. Filename param.Field[string] `json:"filename"`
  489. }
  490. func (r FilePartParam) MarshalJSON() (data []byte, err error) {
  491. return apijson.MarshalRoot(r)
  492. }
  493. func (r FilePartParam) implementsUserMessagePartUnionParam() {}
  494. type Message struct {
  495. ID string `json:"id,required"`
  496. // This field can have the runtime type of [[]UserMessagePart],
  497. // [[]AssistantMessagePart].
  498. Parts interface{} `json:"parts,required"`
  499. Role MessageRole `json:"role,required"`
  500. SessionID string `json:"sessionID,required"`
  501. // This field can have the runtime type of [UserMessageTime],
  502. // [AssistantMessageTime].
  503. Time interface{} `json:"time,required"`
  504. Cost float64 `json:"cost"`
  505. // This field can have the runtime type of [AssistantMessageError].
  506. Error interface{} `json:"error"`
  507. ModelID string `json:"modelID"`
  508. // This field can have the runtime type of [AssistantMessagePath].
  509. Path interface{} `json:"path"`
  510. ProviderID string `json:"providerID"`
  511. Summary bool `json:"summary"`
  512. // This field can have the runtime type of [[]string].
  513. System interface{} `json:"system"`
  514. // This field can have the runtime type of [AssistantMessageTokens].
  515. Tokens interface{} `json:"tokens"`
  516. JSON messageJSON `json:"-"`
  517. union MessageUnion
  518. }
  519. // messageJSON contains the JSON metadata for the struct [Message]
  520. type messageJSON struct {
  521. ID apijson.Field
  522. Parts apijson.Field
  523. Role apijson.Field
  524. SessionID apijson.Field
  525. Time apijson.Field
  526. Cost apijson.Field
  527. Error apijson.Field
  528. ModelID apijson.Field
  529. Path apijson.Field
  530. ProviderID apijson.Field
  531. Summary apijson.Field
  532. System apijson.Field
  533. Tokens apijson.Field
  534. raw string
  535. ExtraFields map[string]apijson.Field
  536. }
  537. func (r messageJSON) RawJSON() string {
  538. return r.raw
  539. }
  540. func (r *Message) UnmarshalJSON(data []byte) (err error) {
  541. *r = Message{}
  542. err = apijson.UnmarshalRoot(data, &r.union)
  543. if err != nil {
  544. return err
  545. }
  546. return apijson.Port(r.union, &r)
  547. }
  548. // AsUnion returns a [MessageUnion] interface which you can cast to the specific
  549. // types for more type safety.
  550. //
  551. // Possible runtime types of the union are [UserMessage], [AssistantMessage].
  552. func (r Message) AsUnion() MessageUnion {
  553. return r.union
  554. }
  555. // Union satisfied by [UserMessage] or [AssistantMessage].
  556. type MessageUnion interface {
  557. implementsMessage()
  558. }
  559. func init() {
  560. apijson.RegisterUnion(
  561. reflect.TypeOf((*MessageUnion)(nil)).Elem(),
  562. "role",
  563. apijson.UnionVariant{
  564. TypeFilter: gjson.JSON,
  565. Type: reflect.TypeOf(UserMessage{}),
  566. DiscriminatorValue: "user",
  567. },
  568. apijson.UnionVariant{
  569. TypeFilter: gjson.JSON,
  570. Type: reflect.TypeOf(AssistantMessage{}),
  571. DiscriminatorValue: "assistant",
  572. },
  573. )
  574. }
  575. type MessageRole string
  576. const (
  577. MessageRoleUser MessageRole = "user"
  578. MessageRoleAssistant MessageRole = "assistant"
  579. )
  580. func (r MessageRole) IsKnown() bool {
  581. switch r {
  582. case MessageRoleUser, MessageRoleAssistant:
  583. return true
  584. }
  585. return false
  586. }
  587. type Session struct {
  588. ID string `json:"id,required"`
  589. Time SessionTime `json:"time,required"`
  590. Title string `json:"title,required"`
  591. Version string `json:"version,required"`
  592. ParentID string `json:"parentID"`
  593. Revert SessionRevert `json:"revert"`
  594. Share SessionShare `json:"share"`
  595. JSON sessionJSON `json:"-"`
  596. }
  597. // sessionJSON contains the JSON metadata for the struct [Session]
  598. type sessionJSON struct {
  599. ID apijson.Field
  600. Time apijson.Field
  601. Title apijson.Field
  602. Version apijson.Field
  603. ParentID apijson.Field
  604. Revert apijson.Field
  605. Share apijson.Field
  606. raw string
  607. ExtraFields map[string]apijson.Field
  608. }
  609. func (r *Session) UnmarshalJSON(data []byte) (err error) {
  610. return apijson.UnmarshalRoot(data, r)
  611. }
  612. func (r sessionJSON) RawJSON() string {
  613. return r.raw
  614. }
  615. type SessionTime struct {
  616. Created float64 `json:"created,required"`
  617. Updated float64 `json:"updated,required"`
  618. JSON sessionTimeJSON `json:"-"`
  619. }
  620. // sessionTimeJSON contains the JSON metadata for the struct [SessionTime]
  621. type sessionTimeJSON struct {
  622. Created apijson.Field
  623. Updated apijson.Field
  624. raw string
  625. ExtraFields map[string]apijson.Field
  626. }
  627. func (r *SessionTime) UnmarshalJSON(data []byte) (err error) {
  628. return apijson.UnmarshalRoot(data, r)
  629. }
  630. func (r sessionTimeJSON) RawJSON() string {
  631. return r.raw
  632. }
  633. type SessionRevert struct {
  634. MessageID string `json:"messageID,required"`
  635. Part float64 `json:"part,required"`
  636. Snapshot string `json:"snapshot"`
  637. JSON sessionRevertJSON `json:"-"`
  638. }
  639. // sessionRevertJSON contains the JSON metadata for the struct [SessionRevert]
  640. type sessionRevertJSON struct {
  641. MessageID apijson.Field
  642. Part apijson.Field
  643. Snapshot apijson.Field
  644. raw string
  645. ExtraFields map[string]apijson.Field
  646. }
  647. func (r *SessionRevert) UnmarshalJSON(data []byte) (err error) {
  648. return apijson.UnmarshalRoot(data, r)
  649. }
  650. func (r sessionRevertJSON) RawJSON() string {
  651. return r.raw
  652. }
  653. type SessionShare struct {
  654. URL string `json:"url,required"`
  655. JSON sessionShareJSON `json:"-"`
  656. }
  657. // sessionShareJSON contains the JSON metadata for the struct [SessionShare]
  658. type sessionShareJSON struct {
  659. URL apijson.Field
  660. raw string
  661. ExtraFields map[string]apijson.Field
  662. }
  663. func (r *SessionShare) UnmarshalJSON(data []byte) (err error) {
  664. return apijson.UnmarshalRoot(data, r)
  665. }
  666. func (r sessionShareJSON) RawJSON() string {
  667. return r.raw
  668. }
  669. type StepStartPart struct {
  670. Type StepStartPartType `json:"type,required"`
  671. JSON stepStartPartJSON `json:"-"`
  672. }
  673. // stepStartPartJSON contains the JSON metadata for the struct [StepStartPart]
  674. type stepStartPartJSON struct {
  675. Type apijson.Field
  676. raw string
  677. ExtraFields map[string]apijson.Field
  678. }
  679. func (r *StepStartPart) UnmarshalJSON(data []byte) (err error) {
  680. return apijson.UnmarshalRoot(data, r)
  681. }
  682. func (r stepStartPartJSON) RawJSON() string {
  683. return r.raw
  684. }
  685. func (r StepStartPart) implementsAssistantMessagePart() {}
  686. type StepStartPartType string
  687. const (
  688. StepStartPartTypeStepStart StepStartPartType = "step-start"
  689. )
  690. func (r StepStartPartType) IsKnown() bool {
  691. switch r {
  692. case StepStartPartTypeStepStart:
  693. return true
  694. }
  695. return false
  696. }
  697. type TextPart struct {
  698. Text string `json:"text,required"`
  699. Type TextPartType `json:"type,required"`
  700. JSON textPartJSON `json:"-"`
  701. }
  702. // textPartJSON contains the JSON metadata for the struct [TextPart]
  703. type textPartJSON struct {
  704. Text apijson.Field
  705. Type apijson.Field
  706. raw string
  707. ExtraFields map[string]apijson.Field
  708. }
  709. func (r *TextPart) UnmarshalJSON(data []byte) (err error) {
  710. return apijson.UnmarshalRoot(data, r)
  711. }
  712. func (r textPartJSON) RawJSON() string {
  713. return r.raw
  714. }
  715. func (r TextPart) implementsAssistantMessagePart() {}
  716. func (r TextPart) implementsUserMessagePart() {}
  717. type TextPartType string
  718. const (
  719. TextPartTypeText TextPartType = "text"
  720. )
  721. func (r TextPartType) IsKnown() bool {
  722. switch r {
  723. case TextPartTypeText:
  724. return true
  725. }
  726. return false
  727. }
  728. type TextPartParam struct {
  729. Text param.Field[string] `json:"text,required"`
  730. Type param.Field[TextPartType] `json:"type,required"`
  731. }
  732. func (r TextPartParam) MarshalJSON() (data []byte, err error) {
  733. return apijson.MarshalRoot(r)
  734. }
  735. func (r TextPartParam) implementsUserMessagePartUnionParam() {}
  736. type ToolPart struct {
  737. ID string `json:"id,required"`
  738. State ToolPartState `json:"state,required"`
  739. Tool string `json:"tool,required"`
  740. Type ToolPartType `json:"type,required"`
  741. JSON toolPartJSON `json:"-"`
  742. }
  743. // toolPartJSON contains the JSON metadata for the struct [ToolPart]
  744. type toolPartJSON struct {
  745. ID apijson.Field
  746. State apijson.Field
  747. Tool apijson.Field
  748. Type apijson.Field
  749. raw string
  750. ExtraFields map[string]apijson.Field
  751. }
  752. func (r *ToolPart) UnmarshalJSON(data []byte) (err error) {
  753. return apijson.UnmarshalRoot(data, r)
  754. }
  755. func (r toolPartJSON) RawJSON() string {
  756. return r.raw
  757. }
  758. func (r ToolPart) implementsAssistantMessagePart() {}
  759. type ToolPartState struct {
  760. Status ToolPartStateStatus `json:"status,required"`
  761. Error string `json:"error"`
  762. // This field can have the runtime type of [interface{}].
  763. Input interface{} `json:"input"`
  764. // This field can have the runtime type of [map[string]interface{}].
  765. Metadata interface{} `json:"metadata"`
  766. Output string `json:"output"`
  767. // This field can have the runtime type of [ToolStateRunningTime],
  768. // [ToolStateCompletedTime], [ToolStateErrorTime].
  769. Time interface{} `json:"time"`
  770. Title string `json:"title"`
  771. JSON toolPartStateJSON `json:"-"`
  772. union ToolPartStateUnion
  773. }
  774. // toolPartStateJSON contains the JSON metadata for the struct [ToolPartState]
  775. type toolPartStateJSON struct {
  776. Status apijson.Field
  777. Error apijson.Field
  778. Input apijson.Field
  779. Metadata apijson.Field
  780. Output apijson.Field
  781. Time apijson.Field
  782. Title apijson.Field
  783. raw string
  784. ExtraFields map[string]apijson.Field
  785. }
  786. func (r toolPartStateJSON) RawJSON() string {
  787. return r.raw
  788. }
  789. func (r *ToolPartState) UnmarshalJSON(data []byte) (err error) {
  790. *r = ToolPartState{}
  791. err = apijson.UnmarshalRoot(data, &r.union)
  792. if err != nil {
  793. return err
  794. }
  795. return apijson.Port(r.union, &r)
  796. }
  797. // AsUnion returns a [ToolPartStateUnion] interface which you can cast to the
  798. // specific types for more type safety.
  799. //
  800. // Possible runtime types of the union are [ToolStatePending], [ToolStateRunning],
  801. // [ToolStateCompleted], [ToolStateError].
  802. func (r ToolPartState) AsUnion() ToolPartStateUnion {
  803. return r.union
  804. }
  805. // Union satisfied by [ToolStatePending], [ToolStateRunning], [ToolStateCompleted]
  806. // or [ToolStateError].
  807. type ToolPartStateUnion interface {
  808. implementsToolPartState()
  809. }
  810. func init() {
  811. apijson.RegisterUnion(
  812. reflect.TypeOf((*ToolPartStateUnion)(nil)).Elem(),
  813. "status",
  814. apijson.UnionVariant{
  815. TypeFilter: gjson.JSON,
  816. Type: reflect.TypeOf(ToolStatePending{}),
  817. DiscriminatorValue: "pending",
  818. },
  819. apijson.UnionVariant{
  820. TypeFilter: gjson.JSON,
  821. Type: reflect.TypeOf(ToolStateRunning{}),
  822. DiscriminatorValue: "running",
  823. },
  824. apijson.UnionVariant{
  825. TypeFilter: gjson.JSON,
  826. Type: reflect.TypeOf(ToolStateCompleted{}),
  827. DiscriminatorValue: "completed",
  828. },
  829. apijson.UnionVariant{
  830. TypeFilter: gjson.JSON,
  831. Type: reflect.TypeOf(ToolStateError{}),
  832. DiscriminatorValue: "error",
  833. },
  834. )
  835. }
  836. type ToolPartStateStatus string
  837. const (
  838. ToolPartStateStatusPending ToolPartStateStatus = "pending"
  839. ToolPartStateStatusRunning ToolPartStateStatus = "running"
  840. ToolPartStateStatusCompleted ToolPartStateStatus = "completed"
  841. ToolPartStateStatusError ToolPartStateStatus = "error"
  842. )
  843. func (r ToolPartStateStatus) IsKnown() bool {
  844. switch r {
  845. case ToolPartStateStatusPending, ToolPartStateStatusRunning, ToolPartStateStatusCompleted, ToolPartStateStatusError:
  846. return true
  847. }
  848. return false
  849. }
  850. type ToolPartType string
  851. const (
  852. ToolPartTypeTool ToolPartType = "tool"
  853. )
  854. func (r ToolPartType) IsKnown() bool {
  855. switch r {
  856. case ToolPartTypeTool:
  857. return true
  858. }
  859. return false
  860. }
  861. type ToolStateCompleted struct {
  862. Metadata map[string]interface{} `json:"metadata,required"`
  863. Output string `json:"output,required"`
  864. Status ToolStateCompletedStatus `json:"status,required"`
  865. Time ToolStateCompletedTime `json:"time,required"`
  866. Title string `json:"title,required"`
  867. Input interface{} `json:"input"`
  868. JSON toolStateCompletedJSON `json:"-"`
  869. }
  870. // toolStateCompletedJSON contains the JSON metadata for the struct
  871. // [ToolStateCompleted]
  872. type toolStateCompletedJSON struct {
  873. Metadata apijson.Field
  874. Output apijson.Field
  875. Status apijson.Field
  876. Time apijson.Field
  877. Title apijson.Field
  878. Input apijson.Field
  879. raw string
  880. ExtraFields map[string]apijson.Field
  881. }
  882. func (r *ToolStateCompleted) UnmarshalJSON(data []byte) (err error) {
  883. return apijson.UnmarshalRoot(data, r)
  884. }
  885. func (r toolStateCompletedJSON) RawJSON() string {
  886. return r.raw
  887. }
  888. func (r ToolStateCompleted) implementsToolPartState() {}
  889. type ToolStateCompletedStatus string
  890. const (
  891. ToolStateCompletedStatusCompleted ToolStateCompletedStatus = "completed"
  892. )
  893. func (r ToolStateCompletedStatus) IsKnown() bool {
  894. switch r {
  895. case ToolStateCompletedStatusCompleted:
  896. return true
  897. }
  898. return false
  899. }
  900. type ToolStateCompletedTime struct {
  901. End float64 `json:"end,required"`
  902. Start float64 `json:"start,required"`
  903. JSON toolStateCompletedTimeJSON `json:"-"`
  904. }
  905. // toolStateCompletedTimeJSON contains the JSON metadata for the struct
  906. // [ToolStateCompletedTime]
  907. type toolStateCompletedTimeJSON struct {
  908. End apijson.Field
  909. Start apijson.Field
  910. raw string
  911. ExtraFields map[string]apijson.Field
  912. }
  913. func (r *ToolStateCompletedTime) UnmarshalJSON(data []byte) (err error) {
  914. return apijson.UnmarshalRoot(data, r)
  915. }
  916. func (r toolStateCompletedTimeJSON) RawJSON() string {
  917. return r.raw
  918. }
  919. type ToolStateError struct {
  920. Error string `json:"error,required"`
  921. Status ToolStateErrorStatus `json:"status,required"`
  922. Time ToolStateErrorTime `json:"time,required"`
  923. Input interface{} `json:"input"`
  924. JSON toolStateErrorJSON `json:"-"`
  925. }
  926. // toolStateErrorJSON contains the JSON metadata for the struct [ToolStateError]
  927. type toolStateErrorJSON struct {
  928. Error apijson.Field
  929. Status apijson.Field
  930. Time apijson.Field
  931. Input apijson.Field
  932. raw string
  933. ExtraFields map[string]apijson.Field
  934. }
  935. func (r *ToolStateError) UnmarshalJSON(data []byte) (err error) {
  936. return apijson.UnmarshalRoot(data, r)
  937. }
  938. func (r toolStateErrorJSON) RawJSON() string {
  939. return r.raw
  940. }
  941. func (r ToolStateError) implementsToolPartState() {}
  942. type ToolStateErrorStatus string
  943. const (
  944. ToolStateErrorStatusError ToolStateErrorStatus = "error"
  945. )
  946. func (r ToolStateErrorStatus) IsKnown() bool {
  947. switch r {
  948. case ToolStateErrorStatusError:
  949. return true
  950. }
  951. return false
  952. }
  953. type ToolStateErrorTime struct {
  954. End float64 `json:"end,required"`
  955. Start float64 `json:"start,required"`
  956. JSON toolStateErrorTimeJSON `json:"-"`
  957. }
  958. // toolStateErrorTimeJSON contains the JSON metadata for the struct
  959. // [ToolStateErrorTime]
  960. type toolStateErrorTimeJSON struct {
  961. End apijson.Field
  962. Start apijson.Field
  963. raw string
  964. ExtraFields map[string]apijson.Field
  965. }
  966. func (r *ToolStateErrorTime) UnmarshalJSON(data []byte) (err error) {
  967. return apijson.UnmarshalRoot(data, r)
  968. }
  969. func (r toolStateErrorTimeJSON) RawJSON() string {
  970. return r.raw
  971. }
  972. type ToolStatePending struct {
  973. Status ToolStatePendingStatus `json:"status,required"`
  974. JSON toolStatePendingJSON `json:"-"`
  975. }
  976. // toolStatePendingJSON contains the JSON metadata for the struct
  977. // [ToolStatePending]
  978. type toolStatePendingJSON struct {
  979. Status apijson.Field
  980. raw string
  981. ExtraFields map[string]apijson.Field
  982. }
  983. func (r *ToolStatePending) UnmarshalJSON(data []byte) (err error) {
  984. return apijson.UnmarshalRoot(data, r)
  985. }
  986. func (r toolStatePendingJSON) RawJSON() string {
  987. return r.raw
  988. }
  989. func (r ToolStatePending) implementsToolPartState() {}
  990. type ToolStatePendingStatus string
  991. const (
  992. ToolStatePendingStatusPending ToolStatePendingStatus = "pending"
  993. )
  994. func (r ToolStatePendingStatus) IsKnown() bool {
  995. switch r {
  996. case ToolStatePendingStatusPending:
  997. return true
  998. }
  999. return false
  1000. }
  1001. type ToolStateRunning struct {
  1002. Status ToolStateRunningStatus `json:"status,required"`
  1003. Time ToolStateRunningTime `json:"time,required"`
  1004. Input interface{} `json:"input"`
  1005. Metadata map[string]interface{} `json:"metadata"`
  1006. Title string `json:"title"`
  1007. JSON toolStateRunningJSON `json:"-"`
  1008. }
  1009. // toolStateRunningJSON contains the JSON metadata for the struct
  1010. // [ToolStateRunning]
  1011. type toolStateRunningJSON struct {
  1012. Status apijson.Field
  1013. Time apijson.Field
  1014. Input apijson.Field
  1015. Metadata apijson.Field
  1016. Title apijson.Field
  1017. raw string
  1018. ExtraFields map[string]apijson.Field
  1019. }
  1020. func (r *ToolStateRunning) UnmarshalJSON(data []byte) (err error) {
  1021. return apijson.UnmarshalRoot(data, r)
  1022. }
  1023. func (r toolStateRunningJSON) RawJSON() string {
  1024. return r.raw
  1025. }
  1026. func (r ToolStateRunning) implementsToolPartState() {}
  1027. type ToolStateRunningStatus string
  1028. const (
  1029. ToolStateRunningStatusRunning ToolStateRunningStatus = "running"
  1030. )
  1031. func (r ToolStateRunningStatus) IsKnown() bool {
  1032. switch r {
  1033. case ToolStateRunningStatusRunning:
  1034. return true
  1035. }
  1036. return false
  1037. }
  1038. type ToolStateRunningTime struct {
  1039. Start float64 `json:"start,required"`
  1040. JSON toolStateRunningTimeJSON `json:"-"`
  1041. }
  1042. // toolStateRunningTimeJSON contains the JSON metadata for the struct
  1043. // [ToolStateRunningTime]
  1044. type toolStateRunningTimeJSON struct {
  1045. Start apijson.Field
  1046. raw string
  1047. ExtraFields map[string]apijson.Field
  1048. }
  1049. func (r *ToolStateRunningTime) UnmarshalJSON(data []byte) (err error) {
  1050. return apijson.UnmarshalRoot(data, r)
  1051. }
  1052. func (r toolStateRunningTimeJSON) RawJSON() string {
  1053. return r.raw
  1054. }
  1055. type UserMessage struct {
  1056. ID string `json:"id,required"`
  1057. Parts []UserMessagePart `json:"parts,required"`
  1058. Role UserMessageRole `json:"role,required"`
  1059. SessionID string `json:"sessionID,required"`
  1060. Time UserMessageTime `json:"time,required"`
  1061. JSON userMessageJSON `json:"-"`
  1062. }
  1063. // userMessageJSON contains the JSON metadata for the struct [UserMessage]
  1064. type userMessageJSON struct {
  1065. ID apijson.Field
  1066. Parts apijson.Field
  1067. Role apijson.Field
  1068. SessionID apijson.Field
  1069. Time apijson.Field
  1070. raw string
  1071. ExtraFields map[string]apijson.Field
  1072. }
  1073. func (r *UserMessage) UnmarshalJSON(data []byte) (err error) {
  1074. return apijson.UnmarshalRoot(data, r)
  1075. }
  1076. func (r userMessageJSON) RawJSON() string {
  1077. return r.raw
  1078. }
  1079. func (r UserMessage) implementsMessage() {}
  1080. type UserMessageRole string
  1081. const (
  1082. UserMessageRoleUser UserMessageRole = "user"
  1083. )
  1084. func (r UserMessageRole) IsKnown() bool {
  1085. switch r {
  1086. case UserMessageRoleUser:
  1087. return true
  1088. }
  1089. return false
  1090. }
  1091. type UserMessageTime struct {
  1092. Created float64 `json:"created,required"`
  1093. JSON userMessageTimeJSON `json:"-"`
  1094. }
  1095. // userMessageTimeJSON contains the JSON metadata for the struct [UserMessageTime]
  1096. type userMessageTimeJSON struct {
  1097. Created apijson.Field
  1098. raw string
  1099. ExtraFields map[string]apijson.Field
  1100. }
  1101. func (r *UserMessageTime) UnmarshalJSON(data []byte) (err error) {
  1102. return apijson.UnmarshalRoot(data, r)
  1103. }
  1104. func (r userMessageTimeJSON) RawJSON() string {
  1105. return r.raw
  1106. }
  1107. type UserMessagePart struct {
  1108. Type UserMessagePartType `json:"type,required"`
  1109. Filename string `json:"filename"`
  1110. Mime string `json:"mime"`
  1111. Text string `json:"text"`
  1112. URL string `json:"url"`
  1113. JSON userMessagePartJSON `json:"-"`
  1114. union UserMessagePartUnion
  1115. }
  1116. // userMessagePartJSON contains the JSON metadata for the struct [UserMessagePart]
  1117. type userMessagePartJSON struct {
  1118. Type apijson.Field
  1119. Filename apijson.Field
  1120. Mime apijson.Field
  1121. Text apijson.Field
  1122. URL apijson.Field
  1123. raw string
  1124. ExtraFields map[string]apijson.Field
  1125. }
  1126. func (r userMessagePartJSON) RawJSON() string {
  1127. return r.raw
  1128. }
  1129. func (r *UserMessagePart) UnmarshalJSON(data []byte) (err error) {
  1130. *r = UserMessagePart{}
  1131. err = apijson.UnmarshalRoot(data, &r.union)
  1132. if err != nil {
  1133. return err
  1134. }
  1135. return apijson.Port(r.union, &r)
  1136. }
  1137. // AsUnion returns a [UserMessagePartUnion] interface which you can cast to the
  1138. // specific types for more type safety.
  1139. //
  1140. // Possible runtime types of the union are [TextPart], [FilePart].
  1141. func (r UserMessagePart) AsUnion() UserMessagePartUnion {
  1142. return r.union
  1143. }
  1144. // Union satisfied by [TextPart] or [FilePart].
  1145. type UserMessagePartUnion interface {
  1146. implementsUserMessagePart()
  1147. }
  1148. func init() {
  1149. apijson.RegisterUnion(
  1150. reflect.TypeOf((*UserMessagePartUnion)(nil)).Elem(),
  1151. "type",
  1152. apijson.UnionVariant{
  1153. TypeFilter: gjson.JSON,
  1154. Type: reflect.TypeOf(TextPart{}),
  1155. DiscriminatorValue: "text",
  1156. },
  1157. apijson.UnionVariant{
  1158. TypeFilter: gjson.JSON,
  1159. Type: reflect.TypeOf(FilePart{}),
  1160. DiscriminatorValue: "file",
  1161. },
  1162. )
  1163. }
  1164. type UserMessagePartType string
  1165. const (
  1166. UserMessagePartTypeText UserMessagePartType = "text"
  1167. UserMessagePartTypeFile UserMessagePartType = "file"
  1168. )
  1169. func (r UserMessagePartType) IsKnown() bool {
  1170. switch r {
  1171. case UserMessagePartTypeText, UserMessagePartTypeFile:
  1172. return true
  1173. }
  1174. return false
  1175. }
  1176. type UserMessagePartParam struct {
  1177. Type param.Field[UserMessagePartType] `json:"type,required"`
  1178. Filename param.Field[string] `json:"filename"`
  1179. Mime param.Field[string] `json:"mime"`
  1180. Text param.Field[string] `json:"text"`
  1181. URL param.Field[string] `json:"url"`
  1182. }
  1183. func (r UserMessagePartParam) MarshalJSON() (data []byte, err error) {
  1184. return apijson.MarshalRoot(r)
  1185. }
  1186. func (r UserMessagePartParam) implementsUserMessagePartUnionParam() {}
  1187. // Satisfied by [TextPartParam], [FilePartParam], [UserMessagePartParam].
  1188. type UserMessagePartUnionParam interface {
  1189. implementsUserMessagePartUnionParam()
  1190. }
  1191. type SessionChatParams struct {
  1192. ModelID param.Field[string] `json:"modelID,required"`
  1193. Parts param.Field[[]UserMessagePartUnionParam] `json:"parts,required"`
  1194. ProviderID param.Field[string] `json:"providerID,required"`
  1195. }
  1196. func (r SessionChatParams) MarshalJSON() (data []byte, err error) {
  1197. return apijson.MarshalRoot(r)
  1198. }
  1199. type SessionInitParams struct {
  1200. ModelID param.Field[string] `json:"modelID,required"`
  1201. ProviderID param.Field[string] `json:"providerID,required"`
  1202. }
  1203. func (r SessionInitParams) MarshalJSON() (data []byte, err error) {
  1204. return apijson.MarshalRoot(r)
  1205. }
  1206. type SessionSummarizeParams struct {
  1207. ModelID param.Field[string] `json:"modelID,required"`
  1208. ProviderID param.Field[string] `json:"providerID,required"`
  1209. }
  1210. func (r SessionSummarizeParams) MarshalJSON() (data []byte, err error) {
  1211. return apijson.MarshalRoot(r)
  1212. }