Browse Source

chore: generate

opencode-agent[bot] 4 months ago
parent
commit
971383661a

+ 33 - 99
packages/opencode/migration/20260323234822_events/snapshot.json

@@ -2,9 +2,7 @@
   "version": "7",
   "dialect": "sqlite",
   "id": "f13dfa58-7fb4-47a2-8f6b-dc70258e14ed",
-  "prevIds": [
-    "37e1554d-af4c-43f2-aa7c-307fb49a315e"
-  ],
+  "prevIds": ["37e1554d-af4c-43f2-aa7c-307fb49a315e"],
   "ddl": [
     {
       "name": "account_state",
@@ -969,13 +967,9 @@
       "table": "event"
     },
     {
-      "columns": [
-        "active_account_id"
-      ],
+      "columns": ["active_account_id"],
       "tableTo": "account",
-      "columnsTo": [
-        "id"
-      ],
+      "columnsTo": ["id"],
       "onUpdate": "NO ACTION",
       "onDelete": "SET NULL",
       "nameExplicit": false,
@@ -984,13 +978,9 @@
       "table": "account_state"
     },
     {
-      "columns": [
-        "project_id"
-      ],
+      "columns": ["project_id"],
       "tableTo": "project",
-      "columnsTo": [
-        "id"
-      ],
+      "columnsTo": ["id"],
       "onUpdate": "NO ACTION",
       "onDelete": "CASCADE",
       "nameExplicit": false,
@@ -999,13 +989,9 @@
       "table": "workspace"
     },
     {
-      "columns": [
-        "session_id"
-      ],
+      "columns": ["session_id"],
       "tableTo": "session",
-      "columnsTo": [
-        "id"
-      ],
+      "columnsTo": ["id"],
       "onUpdate": "NO ACTION",
       "onDelete": "CASCADE",
       "nameExplicit": false,
@@ -1014,13 +1000,9 @@
       "table": "message"
     },
     {
-      "columns": [
-        "message_id"
-      ],
+      "columns": ["message_id"],
       "tableTo": "message",
-      "columnsTo": [
-        "id"
-      ],
+      "columnsTo": ["id"],
       "onUpdate": "NO ACTION",
       "onDelete": "CASCADE",
       "nameExplicit": false,
@@ -1029,13 +1011,9 @@
       "table": "part"
     },
     {
-      "columns": [
-        "project_id"
-      ],
+      "columns": ["project_id"],
       "tableTo": "project",
-      "columnsTo": [
-        "id"
-      ],
+      "columnsTo": ["id"],
       "onUpdate": "NO ACTION",
       "onDelete": "CASCADE",
       "nameExplicit": false,
@@ -1044,13 +1022,9 @@
       "table": "permission"
     },
     {
-      "columns": [
-        "project_id"
-      ],
+      "columns": ["project_id"],
       "tableTo": "project",
-      "columnsTo": [
-        "id"
-      ],
+      "columnsTo": ["id"],
       "onUpdate": "NO ACTION",
       "onDelete": "CASCADE",
       "nameExplicit": false,
@@ -1059,13 +1033,9 @@
       "table": "session"
     },
     {
-      "columns": [
-        "session_id"
-      ],
+      "columns": ["session_id"],
       "tableTo": "session",
-      "columnsTo": [
-        "id"
-      ],
+      "columnsTo": ["id"],
       "onUpdate": "NO ACTION",
       "onDelete": "CASCADE",
       "nameExplicit": false,
@@ -1074,13 +1044,9 @@
       "table": "todo"
     },
     {
-      "columns": [
-        "session_id"
-      ],
+      "columns": ["session_id"],
       "tableTo": "session",
-      "columnsTo": [
-        "id"
-      ],
+      "columnsTo": ["id"],
       "onUpdate": "NO ACTION",
       "onDelete": "CASCADE",
       "nameExplicit": false,
@@ -1089,13 +1055,9 @@
       "table": "session_share"
     },
     {
-      "columns": [
-        "aggregate_id"
-      ],
+      "columns": ["aggregate_id"],
       "tableTo": "event_sequence",
-      "columnsTo": [
-        "aggregate_id"
-      ],
+      "columnsTo": ["aggregate_id"],
       "onUpdate": "NO ACTION",
       "onDelete": "CASCADE",
       "nameExplicit": false,
@@ -1104,119 +1066,91 @@
       "table": "event"
     },
     {
-      "columns": [
-        "email",
-        "url"
-      ],
+      "columns": ["email", "url"],
       "nameExplicit": false,
       "name": "control_account_pk",
       "entityType": "pks",
       "table": "control_account"
     },
     {
-      "columns": [
-        "session_id",
-        "position"
-      ],
+      "columns": ["session_id", "position"],
       "nameExplicit": false,
       "name": "todo_pk",
       "entityType": "pks",
       "table": "todo"
     },
     {
-      "columns": [
-        "id"
-      ],
+      "columns": ["id"],
       "nameExplicit": false,
       "name": "account_state_pk",
       "table": "account_state",
       "entityType": "pks"
     },
     {
-      "columns": [
-        "id"
-      ],
+      "columns": ["id"],
       "nameExplicit": false,
       "name": "account_pk",
       "table": "account",
       "entityType": "pks"
     },
     {
-      "columns": [
-        "id"
-      ],
+      "columns": ["id"],
       "nameExplicit": false,
       "name": "workspace_pk",
       "table": "workspace",
       "entityType": "pks"
     },
     {
-      "columns": [
-        "id"
-      ],
+      "columns": ["id"],
       "nameExplicit": false,
       "name": "project_pk",
       "table": "project",
       "entityType": "pks"
     },
     {
-      "columns": [
-        "id"
-      ],
+      "columns": ["id"],
       "nameExplicit": false,
       "name": "message_pk",
       "table": "message",
       "entityType": "pks"
     },
     {
-      "columns": [
-        "id"
-      ],
+      "columns": ["id"],
       "nameExplicit": false,
       "name": "part_pk",
       "table": "part",
       "entityType": "pks"
     },
     {
-      "columns": [
-        "project_id"
-      ],
+      "columns": ["project_id"],
       "nameExplicit": false,
       "name": "permission_pk",
       "table": "permission",
       "entityType": "pks"
     },
     {
-      "columns": [
-        "id"
-      ],
+      "columns": ["id"],
       "nameExplicit": false,
       "name": "session_pk",
       "table": "session",
       "entityType": "pks"
     },
     {
-      "columns": [
-        "session_id"
-      ],
+      "columns": ["session_id"],
       "nameExplicit": false,
       "name": "session_share_pk",
       "table": "session_share",
       "entityType": "pks"
     },
     {
-      "columns": [
-        "aggregate_id"
-      ],
+      "columns": ["aggregate_id"],
       "nameExplicit": false,
       "name": "event_sequence_pk",
       "table": "event_sequence",
       "entityType": "pks"
     },
     {
-      "columns": [
-        "id"
-      ],
+      "columns": ["id"],
       "nameExplicit": false,
       "name": "event_pk",
       "table": "event",
@@ -1334,4 +1268,4 @@
     }
   ],
   "renames": []
-}
+}

+ 25 - 27
packages/opencode/src/sync/README.md

@@ -1,13 +1,11 @@
-
-
 tl;dr All of these APIs work, are properly type-checked, and are sync events are backwards compatible with `Bus`:
 
 ```ts
 // The schema from `Updated` typechecks the object correctly
-SyncEvent.run(Updated, { sessionID: id, info: { title: "foo"} })
+SyncEvent.run(Updated, { sessionID: id, info: { title: "foo" } })
 
 // `subscribeAll` passes a generic sync event
-SyncEvent.subscribeAll(event => {
+SyncEvent.subscribeAll((event) => {
   // These will be type-checked correctly
   event.id
   event.seq
@@ -17,13 +15,13 @@ SyncEvent.subscribeAll(event => {
 })
 
 // This works, but you shouldn't publish sync event like this (should fail in the future)
-Bus.publish(Updated, { sessionID: id, info: { title: "foo"} })
+Bus.publish(Updated, { sessionID: id, info: { title: "foo" } })
 
-// Update event is fully type-checked 
-Bus.subscribe(Updated, event => event.properties.info.title)
+// Update event is fully type-checked
+Bus.subscribe(Updated, (event) => event.properties.info.title)
 
-// Update event is fully type-checked 
-client.subscribe("session.updated", evt => evt.properties.info.title)
+// Update event is fully type-checked
+client.subscribe("session.updated", (evt) => evt.properties.info.title)
 ```
 
 # Goal
@@ -120,10 +118,10 @@ It's very important that types are correct when working with events. Event defin
 
 ```ts
 // The schema from `Updated` typechecks the object correctly
-SyncEvent.run(Updated, { sessionID: id, info: { title: "foo"} })
+SyncEvent.run(Updated, { sessionID: id, info: { title: "foo" } })
 
 // `subscribeAll` passes a generic sync event
-SyncEvent.subscribeAll(event => {
+SyncEvent.subscribeAll((event) => {
   // These will be type-checked correctly
   event.id
   event.seq
@@ -133,13 +131,13 @@ SyncEvent.subscribeAll(event => {
 })
 
 // This works, but you shouldn't publish sync event like this (should fail in the future)
-Bus.publish(Updated, { sessionID: id, info: { title: "foo"} })
+Bus.publish(Updated, { sessionID: id, info: { title: "foo" } })
 
-// Update event is fully type-checked 
-Bus.subscribe(Updated, event => event.properties.info.title)
+// Update event is fully type-checked
+Bus.subscribe(Updated, (event) => event.properties.info.title)
 
-// Update event is fully type-checked 
-client.subscribe("session.updated", evt => evt.properties.info.title)
+// Update event is fully type-checked
+client.subscribe("session.updated", (evt) => evt.properties.info.title)
 ```
 
 The last two examples look similar to `SyncEvent.run`, but they were the cause of a lot of grief. Those are existing APIs that we can't break, but we are passing in the new sync event definitions to these APIs, which sometimes have a different event shape.
@@ -153,7 +151,7 @@ const Update = SyncEvent.define({
   aggregate: "sessionID",
   schema: z.object({
     sessionID: SessionID.zod,
-    info: partialSchema(Info)
+    info: partialSchema(Info),
   }),
   busSchema: z.object({
     sessionID: SessionID.zod,
@@ -162,20 +160,20 @@ const Update = SyncEvent.define({
 })
 ```
 
-*Important*: the conversion done in `convertEvent` is not automatically type-checked with `busSchema`. It's very important they match, but because we need this at type-checking time this needs to live here.
+_Important_: the conversion done in `convertEvent` is not automatically type-checked with `busSchema`. It's very important they match, but because we need this at type-checking time this needs to live here.
 
 Internally, the way this works is `busSchema` is stored on a `properties` field which is what the bus system expects. Doing this made everything with `Bus` "just work". This is why you can pass a sync event to the bus APIs.
 
-*Alternatives*
+_Alternatives_
 
 These are some other paths I explored:
 
-* Providing a way to subscribe to individual sync events, and change all the instances of `Bus.subscribe` in our code to it. Then you are directly only working with sync events always.
-  * Two big problems. First, `Bus` is instance-scoped, and we'd need to make the sync event system instance-scoped too for backwards compat. If we didn't, those listeners would get calls for events they weren't expecting.
-  * Second, we can't change consumers of our SDK. So they still have to use the old events, and we might as well stick with them for consistency
-* Directly add sync event support to bus system
-  * I explored adding sync events to the bus, but due to backwards compat, it only made it more complicated (still need to support both shapes)
-* I explored a `convertSchema` function to convert the event schema at runtime so we didn't need `busSchema`
-  * Fatal flaw: we need type-checking done earlier. We can't do this at run-time. This worked for consumers of our SDK (because it gets generated TS types from the converted schema) but breaks for our internal usage of `Bus.subscribe` calls
+- Providing a way to subscribe to individual sync events, and change all the instances of `Bus.subscribe` in our code to it. Then you are directly only working with sync events always.
+  - Two big problems. First, `Bus` is instance-scoped, and we'd need to make the sync event system instance-scoped too for backwards compat. If we didn't, those listeners would get calls for events they weren't expecting.
+  - Second, we can't change consumers of our SDK. So they still have to use the old events, and we might as well stick with them for consistency
+- Directly add sync event support to bus system
+  - I explored adding sync events to the bus, but due to backwards compat, it only made it more complicated (still need to support both shapes)
+- I explored a `convertSchema` function to convert the event schema at runtime so we didn't need `busSchema`
+  - Fatal flaw: we need type-checking done earlier. We can't do this at run-time. This worked for consumers of our SDK (because it gets generated TS types from the converted schema) but breaks for our internal usage of `Bus.subscribe` calls
 
-I explored many other permutations of the above solutions. What we have today I think is the best balance of backwards compatibility while opening a path forward for the new events.
+I explored many other permutations of the above solutions. What we have today I think is the best balance of backwards compatibility while opening a path forward for the new events.

+ 18 - 18
packages/sdk/js/src/v2/gen/types.gen.ts

@@ -1068,36 +1068,36 @@ export type SyncEventSessionUpdated = {
   data: {
     sessionID: string
     info: {
-      id?: string
-      slug?: string
-      projectID?: string
-      workspaceID?: string
-      directory?: string
-      parentID?: string
-      summary?: {
+      id: string | null
+      slug: string | null
+      projectID: string | null
+      workspaceID: string | null
+      directory: string | null
+      parentID: string | null
+      summary: {
         additions: number
         deletions: number
         files: number
         diffs?: Array<FileDiff>
-      }
+      } | null
       share?: {
-        url?: string
+        url: string | null
       }
-      title?: string
-      version?: string
+      title: string | null
+      version: string | null
       time?: {
-        created?: number
-        updated?: number
-        compacting?: number
-        archived?: number
+        created: number | null
+        updated: number | null
+        compacting: number | null
+        archived: number | null
       }
-      permission?: PermissionRuleset
-      revert?: {
+      permission: PermissionRuleset | null
+      revert: {
         messageID: string
         partID?: string
         snapshot?: string
         diff?: string
-      }
+      } | null
     }
   }
 }

+ 180 - 53
packages/sdk/openapi.json

@@ -10048,102 +10048,229 @@
                 "type": "object",
                 "properties": {
                   "id": {
-                    "type": "string",
-                    "pattern": "^ses.*"
+                    "anyOf": [
+                      {
+                        "type": "string",
+                        "pattern": "^ses.*"
+                      },
+                      {
+                        "type": "null"
+                      }
+                    ]
                   },
                   "slug": {
-                    "type": "string"
+                    "anyOf": [
+                      {
+                        "type": "string"
+                      },
+                      {
+                        "type": "null"
+                      }
+                    ]
                   },
                   "projectID": {
-                    "type": "string"
+                    "anyOf": [
+                      {
+                        "type": "string"
+                      },
+                      {
+                        "type": "null"
+                      }
+                    ]
                   },
                   "workspaceID": {
-                    "type": "string",
-                    "pattern": "^wrk.*"
+                    "anyOf": [
+                      {
+                        "type": "string",
+                        "pattern": "^wrk.*"
+                      },
+                      {
+                        "type": "null"
+                      }
+                    ]
                   },
                   "directory": {
-                    "type": "string"
+                    "anyOf": [
+                      {
+                        "type": "string"
+                      },
+                      {
+                        "type": "null"
+                      }
+                    ]
                   },
                   "parentID": {
-                    "type": "string",
-                    "pattern": "^ses.*"
+                    "anyOf": [
+                      {
+                        "type": "string",
+                        "pattern": "^ses.*"
+                      },
+                      {
+                        "type": "null"
+                      }
+                    ]
                   },
                   "summary": {
-                    "type": "object",
-                    "properties": {
-                      "additions": {
-                        "type": "number"
-                      },
-                      "deletions": {
-                        "type": "number"
-                      },
-                      "files": {
-                        "type": "number"
+                    "anyOf": [
+                      {
+                        "type": "object",
+                        "properties": {
+                          "additions": {
+                            "type": "number"
+                          },
+                          "deletions": {
+                            "type": "number"
+                          },
+                          "files": {
+                            "type": "number"
+                          },
+                          "diffs": {
+                            "type": "array",
+                            "items": {
+                              "$ref": "#/components/schemas/FileDiff"
+                            }
+                          }
+                        },
+                        "required": ["additions", "deletions", "files"]
                       },
-                      "diffs": {
-                        "type": "array",
-                        "items": {
-                          "$ref": "#/components/schemas/FileDiff"
-                        }
+                      {
+                        "type": "null"
                       }
-                    },
-                    "required": ["additions", "deletions", "files"]
+                    ]
                   },
                   "share": {
                     "type": "object",
                     "properties": {
                       "url": {
-                        "type": "string"
+                        "anyOf": [
+                          {
+                            "type": "string"
+                          },
+                          {
+                            "type": "null"
+                          }
+                        ]
                       }
-                    }
+                    },
+                    "required": ["url"]
                   },
                   "title": {
-                    "type": "string"
+                    "anyOf": [
+                      {
+                        "type": "string"
+                      },
+                      {
+                        "type": "null"
+                      }
+                    ]
                   },
                   "version": {
-                    "type": "string"
+                    "anyOf": [
+                      {
+                        "type": "string"
+                      },
+                      {
+                        "type": "null"
+                      }
+                    ]
                   },
                   "time": {
                     "type": "object",
                     "properties": {
                       "created": {
-                        "type": "number"
+                        "anyOf": [
+                          {
+                            "type": "number"
+                          },
+                          {
+                            "type": "null"
+                          }
+                        ]
                       },
                       "updated": {
-                        "type": "number"
+                        "anyOf": [
+                          {
+                            "type": "number"
+                          },
+                          {
+                            "type": "null"
+                          }
+                        ]
                       },
                       "compacting": {
-                        "type": "number"
+                        "anyOf": [
+                          {
+                            "type": "number"
+                          },
+                          {
+                            "type": "null"
+                          }
+                        ]
                       },
                       "archived": {
-                        "type": "number"
+                        "anyOf": [
+                          {
+                            "type": "number"
+                          },
+                          {
+                            "type": "null"
+                          }
+                        ]
                       }
-                    }
+                    },
+                    "required": ["created", "updated", "compacting", "archived"]
                   },
                   "permission": {
-                    "$ref": "#/components/schemas/PermissionRuleset"
+                    "anyOf": [
+                      {
+                        "$ref": "#/components/schemas/PermissionRuleset"
+                      },
+                      {
+                        "type": "null"
+                      }
+                    ]
                   },
                   "revert": {
-                    "type": "object",
-                    "properties": {
-                      "messageID": {
-                        "type": "string",
-                        "pattern": "^msg.*"
-                      },
-                      "partID": {
-                        "type": "string",
-                        "pattern": "^prt.*"
-                      },
-                      "snapshot": {
-                        "type": "string"
+                    "anyOf": [
+                      {
+                        "type": "object",
+                        "properties": {
+                          "messageID": {
+                            "type": "string",
+                            "pattern": "^msg.*"
+                          },
+                          "partID": {
+                            "type": "string",
+                            "pattern": "^prt.*"
+                          },
+                          "snapshot": {
+                            "type": "string"
+                          },
+                          "diff": {
+                            "type": "string"
+                          }
+                        },
+                        "required": ["messageID"]
                       },
-                      "diff": {
-                        "type": "string"
+                      {
+                        "type": "null"
                       }
-                    },
-                    "required": ["messageID"]
+                    ]
                   }
-                }
+                },
+                "required": [
+                  "id",
+                  "slug",
+                  "projectID",
+                  "workspaceID",
+                  "directory",
+                  "parentID",
+                  "summary",
+                  "title",
+                  "version",
+                  "permission",
+                  "revert"
+                ]
               }
             },
             "required": ["sessionID", "info"]