Browse Source

feat: allow session permission updates (#22070)

Tommy D. Rossi 6 days ago
parent
commit
d62ec7776e

+ 8 - 0
packages/opencode/src/server/instance/session.ts

@@ -273,6 +273,7 @@ export const SessionRoutes = lazy(() =>
         "json",
         "json",
         z.object({
         z.object({
           title: z.string().optional(),
           title: z.string().optional(),
+          permission: Permission.Ruleset.optional(),
           time: z
           time: z
             .object({
             .object({
               archived: z.number().optional(),
               archived: z.number().optional(),
@@ -283,10 +284,17 @@ export const SessionRoutes = lazy(() =>
       async (c) => {
       async (c) => {
         const sessionID = c.req.valid("param").sessionID
         const sessionID = c.req.valid("param").sessionID
         const updates = c.req.valid("json")
         const updates = c.req.valid("json")
+        const current = await Session.get(sessionID)
 
 
         if (updates.title !== undefined) {
         if (updates.title !== undefined) {
           await Session.setTitle({ sessionID, title: updates.title })
           await Session.setTitle({ sessionID, title: updates.title })
         }
         }
+        if (updates.permission !== undefined) {
+          await Session.setPermission({
+            sessionID,
+            permission: Permission.merge(current.permission ?? [], updates.permission),
+          })
+        }
         if (updates.time?.archived !== undefined) {
         if (updates.time?.archived !== undefined) {
           await Session.setArchived({ sessionID, time: updates.time.archived })
           await Session.setArchived({ sessionID, time: updates.time.archived })
         }
         }

+ 5 - 0
packages/opencode/src/session/index.ts

@@ -708,6 +708,11 @@ export namespace Session {
     runPromise((svc) => svc.setArchived(input)),
     runPromise((svc) => svc.setArchived(input)),
   )
   )
 
 
+  export const setPermission = fn(
+    z.object({ sessionID: SessionID.zod, permission: Permission.Ruleset }),
+    (input) => runPromise((svc) => svc.setPermission(input)),
+  )
+
   export const setRevert = fn(
   export const setRevert = fn(
     z.object({ sessionID: SessionID.zod, revert: Info.shape.revert, summary: Info.shape.summary }),
     z.object({ sessionID: SessionID.zod, revert: Info.shape.revert, summary: Info.shape.summary }),
     (input) =>
     (input) =>

+ 2 - 0
packages/sdk/js/src/v2/gen/sdk.gen.ts

@@ -1725,6 +1725,7 @@ export class Session2 extends HeyApiClient {
       directory?: string
       directory?: string
       workspace?: string
       workspace?: string
       title?: string
       title?: string
+      permission?: PermissionRuleset
       time?: {
       time?: {
         archived?: number
         archived?: number
       }
       }
@@ -1740,6 +1741,7 @@ export class Session2 extends HeyApiClient {
             { in: "query", key: "directory" },
             { in: "query", key: "directory" },
             { in: "query", key: "workspace" },
             { in: "query", key: "workspace" },
             { in: "body", key: "title" },
             { in: "body", key: "title" },
+            { in: "body", key: "permission" },
             { in: "body", key: "time" },
             { in: "body", key: "time" },
           ],
           ],
         },
         },

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

@@ -3266,6 +3266,7 @@ export type SessionGetResponse = SessionGetResponses[keyof SessionGetResponses]
 export type SessionUpdateData = {
 export type SessionUpdateData = {
   body?: {
   body?: {
     title?: string
     title?: string
+    permission?: PermissionRuleset
     time?: {
     time?: {
       archived?: number
       archived?: number
     }
     }