session.go 41 KB

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