config.go 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272
  1. // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
  2. package opencode
  3. import (
  4. "context"
  5. "net/http"
  6. "reflect"
  7. "github.com/sst/opencode-sdk-go/internal/apijson"
  8. "github.com/sst/opencode-sdk-go/internal/requestconfig"
  9. "github.com/sst/opencode-sdk-go/option"
  10. "github.com/tidwall/gjson"
  11. )
  12. // ConfigService contains methods and other services that help with interacting
  13. // with the opencode API.
  14. //
  15. // Note, unlike clients, this service does not read variables from the environment
  16. // automatically. You should not instantiate this service directly, and instead use
  17. // the [NewConfigService] method instead.
  18. type ConfigService struct {
  19. Options []option.RequestOption
  20. }
  21. // NewConfigService generates a new service that applies the given options to each
  22. // request. These options are applied after the parent client's options (if there
  23. // is one), and before any request-specific options.
  24. func NewConfigService(opts ...option.RequestOption) (r *ConfigService) {
  25. r = &ConfigService{}
  26. r.Options = opts
  27. return
  28. }
  29. // Get config info
  30. func (r *ConfigService) Get(ctx context.Context, opts ...option.RequestOption) (res *Config, err error) {
  31. opts = append(r.Options[:], opts...)
  32. path := "config"
  33. err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
  34. return
  35. }
  36. type Config struct {
  37. // JSON schema reference for configuration validation
  38. Schema string `json:"$schema"`
  39. // Agent configuration, see https://opencode.ai/docs/agent
  40. Agent ConfigAgent `json:"agent"`
  41. // @deprecated Use 'share' field instead. Share newly created sessions
  42. // automatically
  43. Autoshare bool `json:"autoshare"`
  44. // Automatically update to the latest version
  45. Autoupdate bool `json:"autoupdate"`
  46. // Disable providers that are loaded automatically
  47. DisabledProviders []string `json:"disabled_providers"`
  48. Experimental ConfigExperimental `json:"experimental"`
  49. Formatter map[string]ConfigFormatter `json:"formatter"`
  50. // Additional instruction files or patterns to include
  51. Instructions []string `json:"instructions"`
  52. // Custom keybind configurations
  53. Keybinds KeybindsConfig `json:"keybinds"`
  54. // @deprecated Always uses stretch layout.
  55. Layout ConfigLayout `json:"layout"`
  56. Lsp map[string]ConfigLsp `json:"lsp"`
  57. // MCP (Model Context Protocol) server configurations
  58. Mcp map[string]ConfigMcp `json:"mcp"`
  59. // @deprecated Use `agent` field instead.
  60. Mode ConfigMode `json:"mode"`
  61. // Model to use in the format of provider/model, eg anthropic/claude-2
  62. Model string `json:"model"`
  63. Permission ConfigPermission `json:"permission"`
  64. Plugin []string `json:"plugin"`
  65. // Custom provider configurations and model overrides
  66. Provider map[string]ConfigProvider `json:"provider"`
  67. // Control sharing behavior:'manual' allows manual sharing via commands, 'auto'
  68. // enables automatic sharing, 'disabled' disables all sharing
  69. Share ConfigShare `json:"share"`
  70. // Small model to use for tasks like title generation in the
  71. // format of provider/model
  72. SmallModel string `json:"small_model"`
  73. // Theme name to use for the interface
  74. Theme string `json:"theme"`
  75. // Custom username to display in conversations instead of system username
  76. Username string `json:"username"`
  77. JSON configJSON `json:"-"`
  78. }
  79. // configJSON contains the JSON metadata for the struct [Config]
  80. type configJSON struct {
  81. Schema apijson.Field
  82. Agent apijson.Field
  83. Autoshare apijson.Field
  84. Autoupdate apijson.Field
  85. DisabledProviders apijson.Field
  86. Experimental apijson.Field
  87. Formatter apijson.Field
  88. Instructions apijson.Field
  89. Keybinds apijson.Field
  90. Layout apijson.Field
  91. Lsp apijson.Field
  92. Mcp apijson.Field
  93. Mode apijson.Field
  94. Model apijson.Field
  95. Permission apijson.Field
  96. Plugin apijson.Field
  97. Provider apijson.Field
  98. Share apijson.Field
  99. SmallModel apijson.Field
  100. Theme apijson.Field
  101. Username apijson.Field
  102. raw string
  103. ExtraFields map[string]apijson.Field
  104. }
  105. func (r *Config) UnmarshalJSON(data []byte) (err error) {
  106. return apijson.UnmarshalRoot(data, r)
  107. }
  108. func (r configJSON) RawJSON() string {
  109. return r.raw
  110. }
  111. // Agent configuration, see https://opencode.ai/docs/agent
  112. type ConfigAgent struct {
  113. Build ConfigAgentBuild `json:"build"`
  114. General ConfigAgentGeneral `json:"general"`
  115. Plan ConfigAgentPlan `json:"plan"`
  116. ExtraFields map[string]ConfigAgent `json:"-,extras"`
  117. JSON configAgentJSON `json:"-"`
  118. }
  119. // configAgentJSON contains the JSON metadata for the struct [ConfigAgent]
  120. type configAgentJSON struct {
  121. Build apijson.Field
  122. General apijson.Field
  123. Plan apijson.Field
  124. raw string
  125. ExtraFields map[string]apijson.Field
  126. }
  127. func (r *ConfigAgent) UnmarshalJSON(data []byte) (err error) {
  128. return apijson.UnmarshalRoot(data, r)
  129. }
  130. func (r configAgentJSON) RawJSON() string {
  131. return r.raw
  132. }
  133. type ConfigAgentBuild struct {
  134. // Description of when to use the agent
  135. Description string `json:"description"`
  136. Disable bool `json:"disable"`
  137. Mode ConfigAgentBuildMode `json:"mode"`
  138. Model string `json:"model"`
  139. Prompt string `json:"prompt"`
  140. Temperature float64 `json:"temperature"`
  141. Tools map[string]bool `json:"tools"`
  142. TopP float64 `json:"top_p"`
  143. JSON configAgentBuildJSON `json:"-"`
  144. }
  145. // configAgentBuildJSON contains the JSON metadata for the struct
  146. // [ConfigAgentBuild]
  147. type configAgentBuildJSON struct {
  148. Description apijson.Field
  149. Disable apijson.Field
  150. Mode apijson.Field
  151. Model apijson.Field
  152. Prompt apijson.Field
  153. Temperature apijson.Field
  154. Tools apijson.Field
  155. TopP apijson.Field
  156. raw string
  157. ExtraFields map[string]apijson.Field
  158. }
  159. func (r *ConfigAgentBuild) UnmarshalJSON(data []byte) (err error) {
  160. return apijson.UnmarshalRoot(data, r)
  161. }
  162. func (r configAgentBuildJSON) RawJSON() string {
  163. return r.raw
  164. }
  165. type ConfigAgentBuildMode string
  166. const (
  167. ConfigAgentBuildModeSubagent ConfigAgentBuildMode = "subagent"
  168. ConfigAgentBuildModePrimary ConfigAgentBuildMode = "primary"
  169. ConfigAgentBuildModeAll ConfigAgentBuildMode = "all"
  170. )
  171. func (r ConfigAgentBuildMode) IsKnown() bool {
  172. switch r {
  173. case ConfigAgentBuildModeSubagent, ConfigAgentBuildModePrimary, ConfigAgentBuildModeAll:
  174. return true
  175. }
  176. return false
  177. }
  178. type ConfigAgentGeneral struct {
  179. // Description of when to use the agent
  180. Description string `json:"description"`
  181. Disable bool `json:"disable"`
  182. Mode ConfigAgentGeneralMode `json:"mode"`
  183. Model string `json:"model"`
  184. Prompt string `json:"prompt"`
  185. Temperature float64 `json:"temperature"`
  186. Tools map[string]bool `json:"tools"`
  187. TopP float64 `json:"top_p"`
  188. JSON configAgentGeneralJSON `json:"-"`
  189. }
  190. // configAgentGeneralJSON contains the JSON metadata for the struct
  191. // [ConfigAgentGeneral]
  192. type configAgentGeneralJSON struct {
  193. Description apijson.Field
  194. Disable apijson.Field
  195. Mode apijson.Field
  196. Model apijson.Field
  197. Prompt apijson.Field
  198. Temperature apijson.Field
  199. Tools apijson.Field
  200. TopP apijson.Field
  201. raw string
  202. ExtraFields map[string]apijson.Field
  203. }
  204. func (r *ConfigAgentGeneral) UnmarshalJSON(data []byte) (err error) {
  205. return apijson.UnmarshalRoot(data, r)
  206. }
  207. func (r configAgentGeneralJSON) RawJSON() string {
  208. return r.raw
  209. }
  210. type ConfigAgentGeneralMode string
  211. const (
  212. ConfigAgentGeneralModeSubagent ConfigAgentGeneralMode = "subagent"
  213. ConfigAgentGeneralModePrimary ConfigAgentGeneralMode = "primary"
  214. ConfigAgentGeneralModeAll ConfigAgentGeneralMode = "all"
  215. )
  216. func (r ConfigAgentGeneralMode) IsKnown() bool {
  217. switch r {
  218. case ConfigAgentGeneralModeSubagent, ConfigAgentGeneralModePrimary, ConfigAgentGeneralModeAll:
  219. return true
  220. }
  221. return false
  222. }
  223. type ConfigAgentPlan struct {
  224. // Description of when to use the agent
  225. Description string `json:"description"`
  226. Disable bool `json:"disable"`
  227. Mode ConfigAgentPlanMode `json:"mode"`
  228. Model string `json:"model"`
  229. Prompt string `json:"prompt"`
  230. Temperature float64 `json:"temperature"`
  231. Tools map[string]bool `json:"tools"`
  232. TopP float64 `json:"top_p"`
  233. JSON configAgentPlanJSON `json:"-"`
  234. }
  235. // configAgentPlanJSON contains the JSON metadata for the struct [ConfigAgentPlan]
  236. type configAgentPlanJSON struct {
  237. Description apijson.Field
  238. Disable apijson.Field
  239. Mode apijson.Field
  240. Model apijson.Field
  241. Prompt apijson.Field
  242. Temperature apijson.Field
  243. Tools apijson.Field
  244. TopP apijson.Field
  245. raw string
  246. ExtraFields map[string]apijson.Field
  247. }
  248. func (r *ConfigAgentPlan) UnmarshalJSON(data []byte) (err error) {
  249. return apijson.UnmarshalRoot(data, r)
  250. }
  251. func (r configAgentPlanJSON) RawJSON() string {
  252. return r.raw
  253. }
  254. type ConfigAgentPlanMode string
  255. const (
  256. ConfigAgentPlanModeSubagent ConfigAgentPlanMode = "subagent"
  257. ConfigAgentPlanModePrimary ConfigAgentPlanMode = "primary"
  258. ConfigAgentPlanModeAll ConfigAgentPlanMode = "all"
  259. )
  260. func (r ConfigAgentPlanMode) IsKnown() bool {
  261. switch r {
  262. case ConfigAgentPlanModeSubagent, ConfigAgentPlanModePrimary, ConfigAgentPlanModeAll:
  263. return true
  264. }
  265. return false
  266. }
  267. type ConfigExperimental struct {
  268. Hook ConfigExperimentalHook `json:"hook"`
  269. JSON configExperimentalJSON `json:"-"`
  270. }
  271. // configExperimentalJSON contains the JSON metadata for the struct
  272. // [ConfigExperimental]
  273. type configExperimentalJSON struct {
  274. Hook apijson.Field
  275. raw string
  276. ExtraFields map[string]apijson.Field
  277. }
  278. func (r *ConfigExperimental) UnmarshalJSON(data []byte) (err error) {
  279. return apijson.UnmarshalRoot(data, r)
  280. }
  281. func (r configExperimentalJSON) RawJSON() string {
  282. return r.raw
  283. }
  284. type ConfigExperimentalHook struct {
  285. FileEdited map[string][]ConfigExperimentalHookFileEdited `json:"file_edited"`
  286. SessionCompleted []ConfigExperimentalHookSessionCompleted `json:"session_completed"`
  287. JSON configExperimentalHookJSON `json:"-"`
  288. }
  289. // configExperimentalHookJSON contains the JSON metadata for the struct
  290. // [ConfigExperimentalHook]
  291. type configExperimentalHookJSON struct {
  292. FileEdited apijson.Field
  293. SessionCompleted apijson.Field
  294. raw string
  295. ExtraFields map[string]apijson.Field
  296. }
  297. func (r *ConfigExperimentalHook) UnmarshalJSON(data []byte) (err error) {
  298. return apijson.UnmarshalRoot(data, r)
  299. }
  300. func (r configExperimentalHookJSON) RawJSON() string {
  301. return r.raw
  302. }
  303. type ConfigExperimentalHookFileEdited struct {
  304. Command []string `json:"command,required"`
  305. Environment map[string]string `json:"environment"`
  306. JSON configExperimentalHookFileEditedJSON `json:"-"`
  307. }
  308. // configExperimentalHookFileEditedJSON contains the JSON metadata for the struct
  309. // [ConfigExperimentalHookFileEdited]
  310. type configExperimentalHookFileEditedJSON struct {
  311. Command apijson.Field
  312. Environment apijson.Field
  313. raw string
  314. ExtraFields map[string]apijson.Field
  315. }
  316. func (r *ConfigExperimentalHookFileEdited) UnmarshalJSON(data []byte) (err error) {
  317. return apijson.UnmarshalRoot(data, r)
  318. }
  319. func (r configExperimentalHookFileEditedJSON) RawJSON() string {
  320. return r.raw
  321. }
  322. type ConfigExperimentalHookSessionCompleted struct {
  323. Command []string `json:"command,required"`
  324. Environment map[string]string `json:"environment"`
  325. JSON configExperimentalHookSessionCompletedJSON `json:"-"`
  326. }
  327. // configExperimentalHookSessionCompletedJSON contains the JSON metadata for the
  328. // struct [ConfigExperimentalHookSessionCompleted]
  329. type configExperimentalHookSessionCompletedJSON struct {
  330. Command apijson.Field
  331. Environment apijson.Field
  332. raw string
  333. ExtraFields map[string]apijson.Field
  334. }
  335. func (r *ConfigExperimentalHookSessionCompleted) UnmarshalJSON(data []byte) (err error) {
  336. return apijson.UnmarshalRoot(data, r)
  337. }
  338. func (r configExperimentalHookSessionCompletedJSON) RawJSON() string {
  339. return r.raw
  340. }
  341. type ConfigFormatter struct {
  342. Command []string `json:"command"`
  343. Disabled bool `json:"disabled"`
  344. Environment map[string]string `json:"environment"`
  345. Extensions []string `json:"extensions"`
  346. JSON configFormatterJSON `json:"-"`
  347. }
  348. // configFormatterJSON contains the JSON metadata for the struct [ConfigFormatter]
  349. type configFormatterJSON struct {
  350. Command apijson.Field
  351. Disabled apijson.Field
  352. Environment apijson.Field
  353. Extensions apijson.Field
  354. raw string
  355. ExtraFields map[string]apijson.Field
  356. }
  357. func (r *ConfigFormatter) UnmarshalJSON(data []byte) (err error) {
  358. return apijson.UnmarshalRoot(data, r)
  359. }
  360. func (r configFormatterJSON) RawJSON() string {
  361. return r.raw
  362. }
  363. // @deprecated Always uses stretch layout.
  364. type ConfigLayout string
  365. const (
  366. ConfigLayoutAuto ConfigLayout = "auto"
  367. ConfigLayoutStretch ConfigLayout = "stretch"
  368. )
  369. func (r ConfigLayout) IsKnown() bool {
  370. switch r {
  371. case ConfigLayoutAuto, ConfigLayoutStretch:
  372. return true
  373. }
  374. return false
  375. }
  376. type ConfigLsp struct {
  377. // This field can have the runtime type of [[]string].
  378. Command interface{} `json:"command"`
  379. Disabled bool `json:"disabled"`
  380. // This field can have the runtime type of [map[string]string].
  381. Env interface{} `json:"env"`
  382. // This field can have the runtime type of [[]string].
  383. Extensions interface{} `json:"extensions"`
  384. // This field can have the runtime type of [map[string]interface{}].
  385. Initialization interface{} `json:"initialization"`
  386. JSON configLspJSON `json:"-"`
  387. union ConfigLspUnion
  388. }
  389. // configLspJSON contains the JSON metadata for the struct [ConfigLsp]
  390. type configLspJSON struct {
  391. Command apijson.Field
  392. Disabled apijson.Field
  393. Env apijson.Field
  394. Extensions apijson.Field
  395. Initialization apijson.Field
  396. raw string
  397. ExtraFields map[string]apijson.Field
  398. }
  399. func (r configLspJSON) RawJSON() string {
  400. return r.raw
  401. }
  402. func (r *ConfigLsp) UnmarshalJSON(data []byte) (err error) {
  403. *r = ConfigLsp{}
  404. err = apijson.UnmarshalRoot(data, &r.union)
  405. if err != nil {
  406. return err
  407. }
  408. return apijson.Port(r.union, &r)
  409. }
  410. // AsUnion returns a [ConfigLspUnion] interface which you can cast to the specific
  411. // types for more type safety.
  412. //
  413. // Possible runtime types of the union are [ConfigLspDisabled], [ConfigLspObject].
  414. func (r ConfigLsp) AsUnion() ConfigLspUnion {
  415. return r.union
  416. }
  417. // Union satisfied by [ConfigLspDisabled] or [ConfigLspObject].
  418. type ConfigLspUnion interface {
  419. implementsConfigLsp()
  420. }
  421. func init() {
  422. apijson.RegisterUnion(
  423. reflect.TypeOf((*ConfigLspUnion)(nil)).Elem(),
  424. "",
  425. apijson.UnionVariant{
  426. TypeFilter: gjson.JSON,
  427. Type: reflect.TypeOf(ConfigLspDisabled{}),
  428. },
  429. apijson.UnionVariant{
  430. TypeFilter: gjson.JSON,
  431. Type: reflect.TypeOf(ConfigLspObject{}),
  432. },
  433. )
  434. }
  435. type ConfigLspDisabled struct {
  436. Disabled ConfigLspDisabledDisabled `json:"disabled,required"`
  437. JSON configLspDisabledJSON `json:"-"`
  438. }
  439. // configLspDisabledJSON contains the JSON metadata for the struct
  440. // [ConfigLspDisabled]
  441. type configLspDisabledJSON struct {
  442. Disabled apijson.Field
  443. raw string
  444. ExtraFields map[string]apijson.Field
  445. }
  446. func (r *ConfigLspDisabled) UnmarshalJSON(data []byte) (err error) {
  447. return apijson.UnmarshalRoot(data, r)
  448. }
  449. func (r configLspDisabledJSON) RawJSON() string {
  450. return r.raw
  451. }
  452. func (r ConfigLspDisabled) implementsConfigLsp() {}
  453. type ConfigLspDisabledDisabled bool
  454. const (
  455. ConfigLspDisabledDisabledTrue ConfigLspDisabledDisabled = true
  456. )
  457. func (r ConfigLspDisabledDisabled) IsKnown() bool {
  458. switch r {
  459. case ConfigLspDisabledDisabledTrue:
  460. return true
  461. }
  462. return false
  463. }
  464. type ConfigLspObject struct {
  465. Command []string `json:"command,required"`
  466. Disabled bool `json:"disabled"`
  467. Env map[string]string `json:"env"`
  468. Extensions []string `json:"extensions"`
  469. Initialization map[string]interface{} `json:"initialization"`
  470. JSON configLspObjectJSON `json:"-"`
  471. }
  472. // configLspObjectJSON contains the JSON metadata for the struct [ConfigLspObject]
  473. type configLspObjectJSON struct {
  474. Command apijson.Field
  475. Disabled apijson.Field
  476. Env apijson.Field
  477. Extensions apijson.Field
  478. Initialization apijson.Field
  479. raw string
  480. ExtraFields map[string]apijson.Field
  481. }
  482. func (r *ConfigLspObject) UnmarshalJSON(data []byte) (err error) {
  483. return apijson.UnmarshalRoot(data, r)
  484. }
  485. func (r configLspObjectJSON) RawJSON() string {
  486. return r.raw
  487. }
  488. func (r ConfigLspObject) implementsConfigLsp() {}
  489. type ConfigMcp struct {
  490. // Type of MCP server connection
  491. Type ConfigMcpType `json:"type,required"`
  492. // This field can have the runtime type of [[]string].
  493. Command interface{} `json:"command"`
  494. // Enable or disable the MCP server on startup
  495. Enabled bool `json:"enabled"`
  496. // This field can have the runtime type of [map[string]string].
  497. Environment interface{} `json:"environment"`
  498. // This field can have the runtime type of [map[string]string].
  499. Headers interface{} `json:"headers"`
  500. // URL of the remote MCP server
  501. URL string `json:"url"`
  502. JSON configMcpJSON `json:"-"`
  503. union ConfigMcpUnion
  504. }
  505. // configMcpJSON contains the JSON metadata for the struct [ConfigMcp]
  506. type configMcpJSON struct {
  507. Type apijson.Field
  508. Command apijson.Field
  509. Enabled apijson.Field
  510. Environment apijson.Field
  511. Headers apijson.Field
  512. URL apijson.Field
  513. raw string
  514. ExtraFields map[string]apijson.Field
  515. }
  516. func (r configMcpJSON) RawJSON() string {
  517. return r.raw
  518. }
  519. func (r *ConfigMcp) UnmarshalJSON(data []byte) (err error) {
  520. *r = ConfigMcp{}
  521. err = apijson.UnmarshalRoot(data, &r.union)
  522. if err != nil {
  523. return err
  524. }
  525. return apijson.Port(r.union, &r)
  526. }
  527. // AsUnion returns a [ConfigMcpUnion] interface which you can cast to the specific
  528. // types for more type safety.
  529. //
  530. // Possible runtime types of the union are [McpLocalConfig], [McpRemoteConfig].
  531. func (r ConfigMcp) AsUnion() ConfigMcpUnion {
  532. return r.union
  533. }
  534. // Union satisfied by [McpLocalConfig] or [McpRemoteConfig].
  535. type ConfigMcpUnion interface {
  536. implementsConfigMcp()
  537. }
  538. func init() {
  539. apijson.RegisterUnion(
  540. reflect.TypeOf((*ConfigMcpUnion)(nil)).Elem(),
  541. "type",
  542. apijson.UnionVariant{
  543. TypeFilter: gjson.JSON,
  544. Type: reflect.TypeOf(McpLocalConfig{}),
  545. DiscriminatorValue: "local",
  546. },
  547. apijson.UnionVariant{
  548. TypeFilter: gjson.JSON,
  549. Type: reflect.TypeOf(McpRemoteConfig{}),
  550. DiscriminatorValue: "remote",
  551. },
  552. )
  553. }
  554. // Type of MCP server connection
  555. type ConfigMcpType string
  556. const (
  557. ConfigMcpTypeLocal ConfigMcpType = "local"
  558. ConfigMcpTypeRemote ConfigMcpType = "remote"
  559. )
  560. func (r ConfigMcpType) IsKnown() bool {
  561. switch r {
  562. case ConfigMcpTypeLocal, ConfigMcpTypeRemote:
  563. return true
  564. }
  565. return false
  566. }
  567. // @deprecated Use `agent` field instead.
  568. type ConfigMode struct {
  569. Build ConfigModeBuild `json:"build"`
  570. Plan ConfigModePlan `json:"plan"`
  571. ExtraFields map[string]ConfigMode `json:"-,extras"`
  572. JSON configModeJSON `json:"-"`
  573. }
  574. // configModeJSON contains the JSON metadata for the struct [ConfigMode]
  575. type configModeJSON struct {
  576. Build apijson.Field
  577. Plan apijson.Field
  578. raw string
  579. ExtraFields map[string]apijson.Field
  580. }
  581. func (r *ConfigMode) UnmarshalJSON(data []byte) (err error) {
  582. return apijson.UnmarshalRoot(data, r)
  583. }
  584. func (r configModeJSON) RawJSON() string {
  585. return r.raw
  586. }
  587. type ConfigModeBuild struct {
  588. // Description of when to use the agent
  589. Description string `json:"description"`
  590. Disable bool `json:"disable"`
  591. Mode ConfigModeBuildMode `json:"mode"`
  592. Model string `json:"model"`
  593. Prompt string `json:"prompt"`
  594. Temperature float64 `json:"temperature"`
  595. Tools map[string]bool `json:"tools"`
  596. TopP float64 `json:"top_p"`
  597. JSON configModeBuildJSON `json:"-"`
  598. }
  599. // configModeBuildJSON contains the JSON metadata for the struct [ConfigModeBuild]
  600. type configModeBuildJSON struct {
  601. Description apijson.Field
  602. Disable apijson.Field
  603. Mode apijson.Field
  604. Model apijson.Field
  605. Prompt apijson.Field
  606. Temperature apijson.Field
  607. Tools apijson.Field
  608. TopP apijson.Field
  609. raw string
  610. ExtraFields map[string]apijson.Field
  611. }
  612. func (r *ConfigModeBuild) UnmarshalJSON(data []byte) (err error) {
  613. return apijson.UnmarshalRoot(data, r)
  614. }
  615. func (r configModeBuildJSON) RawJSON() string {
  616. return r.raw
  617. }
  618. type ConfigModeBuildMode string
  619. const (
  620. ConfigModeBuildModeSubagent ConfigModeBuildMode = "subagent"
  621. ConfigModeBuildModePrimary ConfigModeBuildMode = "primary"
  622. ConfigModeBuildModeAll ConfigModeBuildMode = "all"
  623. )
  624. func (r ConfigModeBuildMode) IsKnown() bool {
  625. switch r {
  626. case ConfigModeBuildModeSubagent, ConfigModeBuildModePrimary, ConfigModeBuildModeAll:
  627. return true
  628. }
  629. return false
  630. }
  631. type ConfigModePlan struct {
  632. // Description of when to use the agent
  633. Description string `json:"description"`
  634. Disable bool `json:"disable"`
  635. Mode ConfigModePlanMode `json:"mode"`
  636. Model string `json:"model"`
  637. Prompt string `json:"prompt"`
  638. Temperature float64 `json:"temperature"`
  639. Tools map[string]bool `json:"tools"`
  640. TopP float64 `json:"top_p"`
  641. JSON configModePlanJSON `json:"-"`
  642. }
  643. // configModePlanJSON contains the JSON metadata for the struct [ConfigModePlan]
  644. type configModePlanJSON struct {
  645. Description apijson.Field
  646. Disable apijson.Field
  647. Mode apijson.Field
  648. Model apijson.Field
  649. Prompt apijson.Field
  650. Temperature apijson.Field
  651. Tools apijson.Field
  652. TopP apijson.Field
  653. raw string
  654. ExtraFields map[string]apijson.Field
  655. }
  656. func (r *ConfigModePlan) UnmarshalJSON(data []byte) (err error) {
  657. return apijson.UnmarshalRoot(data, r)
  658. }
  659. func (r configModePlanJSON) RawJSON() string {
  660. return r.raw
  661. }
  662. type ConfigModePlanMode string
  663. const (
  664. ConfigModePlanModeSubagent ConfigModePlanMode = "subagent"
  665. ConfigModePlanModePrimary ConfigModePlanMode = "primary"
  666. ConfigModePlanModeAll ConfigModePlanMode = "all"
  667. )
  668. func (r ConfigModePlanMode) IsKnown() bool {
  669. switch r {
  670. case ConfigModePlanModeSubagent, ConfigModePlanModePrimary, ConfigModePlanModeAll:
  671. return true
  672. }
  673. return false
  674. }
  675. type ConfigPermission struct {
  676. Bash ConfigPermissionBashUnion `json:"bash"`
  677. Edit ConfigPermissionEdit `json:"edit"`
  678. JSON configPermissionJSON `json:"-"`
  679. }
  680. // configPermissionJSON contains the JSON metadata for the struct
  681. // [ConfigPermission]
  682. type configPermissionJSON struct {
  683. Bash apijson.Field
  684. Edit apijson.Field
  685. raw string
  686. ExtraFields map[string]apijson.Field
  687. }
  688. func (r *ConfigPermission) UnmarshalJSON(data []byte) (err error) {
  689. return apijson.UnmarshalRoot(data, r)
  690. }
  691. func (r configPermissionJSON) RawJSON() string {
  692. return r.raw
  693. }
  694. // Union satisfied by [ConfigPermissionBashString] or [ConfigPermissionBashMap].
  695. type ConfigPermissionBashUnion interface {
  696. implementsConfigPermissionBashUnion()
  697. }
  698. func init() {
  699. apijson.RegisterUnion(
  700. reflect.TypeOf((*ConfigPermissionBashUnion)(nil)).Elem(),
  701. "",
  702. apijson.UnionVariant{
  703. TypeFilter: gjson.String,
  704. Type: reflect.TypeOf(ConfigPermissionBashString("")),
  705. },
  706. apijson.UnionVariant{
  707. TypeFilter: gjson.JSON,
  708. Type: reflect.TypeOf(ConfigPermissionBashMap{}),
  709. },
  710. )
  711. }
  712. type ConfigPermissionBashString string
  713. const (
  714. ConfigPermissionBashStringAsk ConfigPermissionBashString = "ask"
  715. ConfigPermissionBashStringAllow ConfigPermissionBashString = "allow"
  716. ConfigPermissionBashStringDeny ConfigPermissionBashString = "deny"
  717. )
  718. func (r ConfigPermissionBashString) IsKnown() bool {
  719. switch r {
  720. case ConfigPermissionBashStringAsk, ConfigPermissionBashStringAllow, ConfigPermissionBashStringDeny:
  721. return true
  722. }
  723. return false
  724. }
  725. func (r ConfigPermissionBashString) implementsConfigPermissionBashUnion() {}
  726. type ConfigPermissionBashMap map[string]ConfigPermissionBashMapItem
  727. func (r ConfigPermissionBashMap) implementsConfigPermissionBashUnion() {}
  728. type ConfigPermissionBashMapItem string
  729. const (
  730. ConfigPermissionBashMapAsk ConfigPermissionBashMapItem = "ask"
  731. ConfigPermissionBashMapAllow ConfigPermissionBashMapItem = "allow"
  732. ConfigPermissionBashMapDeny ConfigPermissionBashMapItem = "deny"
  733. )
  734. func (r ConfigPermissionBashMapItem) IsKnown() bool {
  735. switch r {
  736. case ConfigPermissionBashMapAsk, ConfigPermissionBashMapAllow, ConfigPermissionBashMapDeny:
  737. return true
  738. }
  739. return false
  740. }
  741. type ConfigPermissionEdit string
  742. const (
  743. ConfigPermissionEditAsk ConfigPermissionEdit = "ask"
  744. ConfigPermissionEditAllow ConfigPermissionEdit = "allow"
  745. ConfigPermissionEditDeny ConfigPermissionEdit = "deny"
  746. )
  747. func (r ConfigPermissionEdit) IsKnown() bool {
  748. switch r {
  749. case ConfigPermissionEditAsk, ConfigPermissionEditAllow, ConfigPermissionEditDeny:
  750. return true
  751. }
  752. return false
  753. }
  754. type ConfigProvider struct {
  755. Models map[string]ConfigProviderModel `json:"models,required"`
  756. ID string `json:"id"`
  757. API string `json:"api"`
  758. Env []string `json:"env"`
  759. Name string `json:"name"`
  760. Npm string `json:"npm"`
  761. Options ConfigProviderOptions `json:"options"`
  762. JSON configProviderJSON `json:"-"`
  763. }
  764. // configProviderJSON contains the JSON metadata for the struct [ConfigProvider]
  765. type configProviderJSON struct {
  766. Models apijson.Field
  767. ID apijson.Field
  768. API apijson.Field
  769. Env apijson.Field
  770. Name apijson.Field
  771. Npm apijson.Field
  772. Options apijson.Field
  773. raw string
  774. ExtraFields map[string]apijson.Field
  775. }
  776. func (r *ConfigProvider) UnmarshalJSON(data []byte) (err error) {
  777. return apijson.UnmarshalRoot(data, r)
  778. }
  779. func (r configProviderJSON) RawJSON() string {
  780. return r.raw
  781. }
  782. type ConfigProviderModel struct {
  783. ID string `json:"id"`
  784. Attachment bool `json:"attachment"`
  785. Cost ConfigProviderModelsCost `json:"cost"`
  786. Limit ConfigProviderModelsLimit `json:"limit"`
  787. Name string `json:"name"`
  788. Options map[string]interface{} `json:"options"`
  789. Reasoning bool `json:"reasoning"`
  790. ReleaseDate string `json:"release_date"`
  791. Temperature bool `json:"temperature"`
  792. ToolCall bool `json:"tool_call"`
  793. JSON configProviderModelJSON `json:"-"`
  794. }
  795. // configProviderModelJSON contains the JSON metadata for the struct
  796. // [ConfigProviderModel]
  797. type configProviderModelJSON struct {
  798. ID apijson.Field
  799. Attachment apijson.Field
  800. Cost apijson.Field
  801. Limit apijson.Field
  802. Name apijson.Field
  803. Options apijson.Field
  804. Reasoning apijson.Field
  805. ReleaseDate apijson.Field
  806. Temperature apijson.Field
  807. ToolCall apijson.Field
  808. raw string
  809. ExtraFields map[string]apijson.Field
  810. }
  811. func (r *ConfigProviderModel) UnmarshalJSON(data []byte) (err error) {
  812. return apijson.UnmarshalRoot(data, r)
  813. }
  814. func (r configProviderModelJSON) RawJSON() string {
  815. return r.raw
  816. }
  817. type ConfigProviderModelsCost struct {
  818. Input float64 `json:"input,required"`
  819. Output float64 `json:"output,required"`
  820. CacheRead float64 `json:"cache_read"`
  821. CacheWrite float64 `json:"cache_write"`
  822. JSON configProviderModelsCostJSON `json:"-"`
  823. }
  824. // configProviderModelsCostJSON contains the JSON metadata for the struct
  825. // [ConfigProviderModelsCost]
  826. type configProviderModelsCostJSON struct {
  827. Input apijson.Field
  828. Output apijson.Field
  829. CacheRead apijson.Field
  830. CacheWrite apijson.Field
  831. raw string
  832. ExtraFields map[string]apijson.Field
  833. }
  834. func (r *ConfigProviderModelsCost) UnmarshalJSON(data []byte) (err error) {
  835. return apijson.UnmarshalRoot(data, r)
  836. }
  837. func (r configProviderModelsCostJSON) RawJSON() string {
  838. return r.raw
  839. }
  840. type ConfigProviderModelsLimit struct {
  841. Context float64 `json:"context,required"`
  842. Output float64 `json:"output,required"`
  843. JSON configProviderModelsLimitJSON `json:"-"`
  844. }
  845. // configProviderModelsLimitJSON contains the JSON metadata for the struct
  846. // [ConfigProviderModelsLimit]
  847. type configProviderModelsLimitJSON struct {
  848. Context apijson.Field
  849. Output apijson.Field
  850. raw string
  851. ExtraFields map[string]apijson.Field
  852. }
  853. func (r *ConfigProviderModelsLimit) UnmarshalJSON(data []byte) (err error) {
  854. return apijson.UnmarshalRoot(data, r)
  855. }
  856. func (r configProviderModelsLimitJSON) RawJSON() string {
  857. return r.raw
  858. }
  859. type ConfigProviderOptions struct {
  860. APIKey string `json:"apiKey"`
  861. BaseURL string `json:"baseURL"`
  862. ExtraFields map[string]interface{} `json:"-,extras"`
  863. JSON configProviderOptionsJSON `json:"-"`
  864. }
  865. // configProviderOptionsJSON contains the JSON metadata for the struct
  866. // [ConfigProviderOptions]
  867. type configProviderOptionsJSON struct {
  868. APIKey apijson.Field
  869. BaseURL apijson.Field
  870. raw string
  871. ExtraFields map[string]apijson.Field
  872. }
  873. func (r *ConfigProviderOptions) UnmarshalJSON(data []byte) (err error) {
  874. return apijson.UnmarshalRoot(data, r)
  875. }
  876. func (r configProviderOptionsJSON) RawJSON() string {
  877. return r.raw
  878. }
  879. // Control sharing behavior:'manual' allows manual sharing via commands, 'auto'
  880. // enables automatic sharing, 'disabled' disables all sharing
  881. type ConfigShare string
  882. const (
  883. ConfigShareManual ConfigShare = "manual"
  884. ConfigShareAuto ConfigShare = "auto"
  885. ConfigShareDisabled ConfigShare = "disabled"
  886. )
  887. func (r ConfigShare) IsKnown() bool {
  888. switch r {
  889. case ConfigShareManual, ConfigShareAuto, ConfigShareDisabled:
  890. return true
  891. }
  892. return false
  893. }
  894. type KeybindsConfig struct {
  895. // Exit the application
  896. AppExit string `json:"app_exit,required"`
  897. // Show help dialog
  898. AppHelp string `json:"app_help,required"`
  899. // Open external editor
  900. EditorOpen string `json:"editor_open,required"`
  901. // Close file
  902. FileClose string `json:"file_close,required"`
  903. // Split/unified diff
  904. FileDiffToggle string `json:"file_diff_toggle,required"`
  905. // List files
  906. FileList string `json:"file_list,required"`
  907. // Search file
  908. FileSearch string `json:"file_search,required"`
  909. // Clear input field
  910. InputClear string `json:"input_clear,required"`
  911. // Insert newline in input
  912. InputNewline string `json:"input_newline,required"`
  913. // Paste from clipboard
  914. InputPaste string `json:"input_paste,required"`
  915. // Submit input
  916. InputSubmit string `json:"input_submit,required"`
  917. // Leader key for keybind combinations
  918. Leader string `json:"leader,required"`
  919. // Copy message
  920. MessagesCopy string `json:"messages_copy,required"`
  921. // Navigate to first message
  922. MessagesFirst string `json:"messages_first,required"`
  923. // Scroll messages down by half page
  924. MessagesHalfPageDown string `json:"messages_half_page_down,required"`
  925. // Scroll messages up by half page
  926. MessagesHalfPageUp string `json:"messages_half_page_up,required"`
  927. // Navigate to last message
  928. MessagesLast string `json:"messages_last,required"`
  929. // Toggle layout
  930. MessagesLayoutToggle string `json:"messages_layout_toggle,required"`
  931. // Navigate to next message
  932. MessagesNext string `json:"messages_next,required"`
  933. // Scroll messages down by one page
  934. MessagesPageDown string `json:"messages_page_down,required"`
  935. // Scroll messages up by one page
  936. MessagesPageUp string `json:"messages_page_up,required"`
  937. // Navigate to previous message
  938. MessagesPrevious string `json:"messages_previous,required"`
  939. // Redo message
  940. MessagesRedo string `json:"messages_redo,required"`
  941. // @deprecated use messages_undo. Revert message
  942. MessagesRevert string `json:"messages_revert,required"`
  943. // Undo message
  944. MessagesUndo string `json:"messages_undo,required"`
  945. // List available models
  946. ModelList string `json:"model_list,required"`
  947. // Create/update AGENTS.md
  948. ProjectInit string `json:"project_init,required"`
  949. // Compact the session
  950. SessionCompact string `json:"session_compact,required"`
  951. // Export session to editor
  952. SessionExport string `json:"session_export,required"`
  953. // Interrupt current session
  954. SessionInterrupt string `json:"session_interrupt,required"`
  955. // List all sessions
  956. SessionList string `json:"session_list,required"`
  957. // Create a new session
  958. SessionNew string `json:"session_new,required"`
  959. // Share current session
  960. SessionShare string `json:"session_share,required"`
  961. // Unshare current session
  962. SessionUnshare string `json:"session_unshare,required"`
  963. // Next agent
  964. SwitchAgent string `json:"switch_agent,required"`
  965. // Previous agent
  966. SwitchAgentReverse string `json:"switch_agent_reverse,required"`
  967. // @deprecated use switch_agent. Next mode
  968. SwitchMode string `json:"switch_mode,required"`
  969. // @deprecated use switch_agent_reverse. Previous mode
  970. SwitchModeReverse string `json:"switch_mode_reverse,required"`
  971. // List available themes
  972. ThemeList string `json:"theme_list,required"`
  973. // Toggle tool details
  974. ToolDetails string `json:"tool_details,required"`
  975. JSON keybindsConfigJSON `json:"-"`
  976. }
  977. // keybindsConfigJSON contains the JSON metadata for the struct [KeybindsConfig]
  978. type keybindsConfigJSON struct {
  979. AppExit apijson.Field
  980. AppHelp apijson.Field
  981. EditorOpen apijson.Field
  982. FileClose apijson.Field
  983. FileDiffToggle apijson.Field
  984. FileList apijson.Field
  985. FileSearch apijson.Field
  986. InputClear apijson.Field
  987. InputNewline apijson.Field
  988. InputPaste apijson.Field
  989. InputSubmit apijson.Field
  990. Leader apijson.Field
  991. MessagesCopy apijson.Field
  992. MessagesFirst apijson.Field
  993. MessagesHalfPageDown apijson.Field
  994. MessagesHalfPageUp apijson.Field
  995. MessagesLast apijson.Field
  996. MessagesLayoutToggle apijson.Field
  997. MessagesNext apijson.Field
  998. MessagesPageDown apijson.Field
  999. MessagesPageUp apijson.Field
  1000. MessagesPrevious apijson.Field
  1001. MessagesRedo apijson.Field
  1002. MessagesRevert apijson.Field
  1003. MessagesUndo apijson.Field
  1004. ModelList apijson.Field
  1005. ProjectInit apijson.Field
  1006. SessionCompact apijson.Field
  1007. SessionExport apijson.Field
  1008. SessionInterrupt apijson.Field
  1009. SessionList apijson.Field
  1010. SessionNew apijson.Field
  1011. SessionShare apijson.Field
  1012. SessionUnshare apijson.Field
  1013. SwitchAgent apijson.Field
  1014. SwitchAgentReverse apijson.Field
  1015. SwitchMode apijson.Field
  1016. SwitchModeReverse apijson.Field
  1017. ThemeList apijson.Field
  1018. ToolDetails apijson.Field
  1019. raw string
  1020. ExtraFields map[string]apijson.Field
  1021. }
  1022. func (r *KeybindsConfig) UnmarshalJSON(data []byte) (err error) {
  1023. return apijson.UnmarshalRoot(data, r)
  1024. }
  1025. func (r keybindsConfigJSON) RawJSON() string {
  1026. return r.raw
  1027. }
  1028. type McpLocalConfig struct {
  1029. // Command and arguments to run the MCP server
  1030. Command []string `json:"command,required"`
  1031. // Type of MCP server connection
  1032. Type McpLocalConfigType `json:"type,required"`
  1033. // Enable or disable the MCP server on startup
  1034. Enabled bool `json:"enabled"`
  1035. // Environment variables to set when running the MCP server
  1036. Environment map[string]string `json:"environment"`
  1037. JSON mcpLocalConfigJSON `json:"-"`
  1038. }
  1039. // mcpLocalConfigJSON contains the JSON metadata for the struct [McpLocalConfig]
  1040. type mcpLocalConfigJSON struct {
  1041. Command apijson.Field
  1042. Type apijson.Field
  1043. Enabled apijson.Field
  1044. Environment apijson.Field
  1045. raw string
  1046. ExtraFields map[string]apijson.Field
  1047. }
  1048. func (r *McpLocalConfig) UnmarshalJSON(data []byte) (err error) {
  1049. return apijson.UnmarshalRoot(data, r)
  1050. }
  1051. func (r mcpLocalConfigJSON) RawJSON() string {
  1052. return r.raw
  1053. }
  1054. func (r McpLocalConfig) implementsConfigMcp() {}
  1055. // Type of MCP server connection
  1056. type McpLocalConfigType string
  1057. const (
  1058. McpLocalConfigTypeLocal McpLocalConfigType = "local"
  1059. )
  1060. func (r McpLocalConfigType) IsKnown() bool {
  1061. switch r {
  1062. case McpLocalConfigTypeLocal:
  1063. return true
  1064. }
  1065. return false
  1066. }
  1067. type McpRemoteConfig struct {
  1068. // Type of MCP server connection
  1069. Type McpRemoteConfigType `json:"type,required"`
  1070. // URL of the remote MCP server
  1071. URL string `json:"url,required"`
  1072. // Enable or disable the MCP server on startup
  1073. Enabled bool `json:"enabled"`
  1074. // Headers to send with the request
  1075. Headers map[string]string `json:"headers"`
  1076. JSON mcpRemoteConfigJSON `json:"-"`
  1077. }
  1078. // mcpRemoteConfigJSON contains the JSON metadata for the struct [McpRemoteConfig]
  1079. type mcpRemoteConfigJSON struct {
  1080. Type apijson.Field
  1081. URL apijson.Field
  1082. Enabled apijson.Field
  1083. Headers apijson.Field
  1084. raw string
  1085. ExtraFields map[string]apijson.Field
  1086. }
  1087. func (r *McpRemoteConfig) UnmarshalJSON(data []byte) (err error) {
  1088. return apijson.UnmarshalRoot(data, r)
  1089. }
  1090. func (r mcpRemoteConfigJSON) RawJSON() string {
  1091. return r.raw
  1092. }
  1093. func (r McpRemoteConfig) implementsConfigMcp() {}
  1094. // Type of MCP server connection
  1095. type McpRemoteConfigType string
  1096. const (
  1097. McpRemoteConfigTypeRemote McpRemoteConfigType = "remote"
  1098. )
  1099. func (r McpRemoteConfigType) IsKnown() bool {
  1100. switch r {
  1101. case McpRemoteConfigTypeRemote:
  1102. return true
  1103. }
  1104. return false
  1105. }