session.go 46 KB

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