Przeglądaj źródła

chore: generate

opencode-agent[bot] 2 miesięcy temu
rodzic
commit
710e408709

+ 46 - 141
packages/core/migration/20260611035744_credential/snapshot.json

@@ -2,9 +2,7 @@
   "version": "7",
   "dialect": "sqlite",
   "id": "f25f9126-c7dc-4882-9ff4-af27e11d2da1",
-  "prevIds": [
-    "d1bfa125-b81e-4c61-9b6e-e74abf6e488f"
-  ],
+  "prevIds": ["d1bfa125-b81e-4c61-9b6e-e74abf6e488f"],
   "ddl": [
     {
       "name": "workspace",
@@ -1493,13 +1491,9 @@
       "table": "session_share"
     },
     {
-      "columns": [
-        "project_id"
-      ],
+      "columns": ["project_id"],
       "tableTo": "project",
-      "columnsTo": [
-        "id"
-      ],
+      "columnsTo": ["id"],
       "onUpdate": "NO ACTION",
       "onDelete": "CASCADE",
       "nameExplicit": false,
@@ -1508,13 +1502,9 @@
       "table": "workspace"
     },
     {
-      "columns": [
-        "active_account_id"
-      ],
+      "columns": ["active_account_id"],
       "tableTo": "account",
-      "columnsTo": [
-        "id"
-      ],
+      "columnsTo": ["id"],
       "onUpdate": "NO ACTION",
       "onDelete": "SET NULL",
       "nameExplicit": false,
@@ -1523,13 +1513,9 @@
       "table": "account_state"
     },
     {
-      "columns": [
-        "aggregate_id"
-      ],
+      "columns": ["aggregate_id"],
       "tableTo": "event_sequence",
-      "columnsTo": [
-        "aggregate_id"
-      ],
+      "columnsTo": ["aggregate_id"],
       "onUpdate": "NO ACTION",
       "onDelete": "CASCADE",
       "nameExplicit": false,
@@ -1538,13 +1524,9 @@
       "table": "event"
     },
     {
-      "columns": [
-        "project_id"
-      ],
+      "columns": ["project_id"],
       "tableTo": "project",
-      "columnsTo": [
-        "id"
-      ],
+      "columnsTo": ["id"],
       "onUpdate": "NO ACTION",
       "onDelete": "CASCADE",
       "nameExplicit": false,
@@ -1553,13 +1535,9 @@
       "table": "permission"
     },
     {
-      "columns": [
-        "project_id"
-      ],
+      "columns": ["project_id"],
       "tableTo": "project",
-      "columnsTo": [
-        "id"
-      ],
+      "columnsTo": ["id"],
       "onUpdate": "NO ACTION",
       "onDelete": "CASCADE",
       "nameExplicit": false,
@@ -1568,13 +1546,9 @@
       "table": "project_directory"
     },
     {
-      "columns": [
-        "session_id"
-      ],
+      "columns": ["session_id"],
       "tableTo": "session",
-      "columnsTo": [
-        "id"
-      ],
+      "columnsTo": ["id"],
       "onUpdate": "NO ACTION",
       "onDelete": "CASCADE",
       "nameExplicit": false,
@@ -1583,13 +1557,9 @@
       "table": "message"
     },
     {
-      "columns": [
-        "message_id"
-      ],
+      "columns": ["message_id"],
       "tableTo": "message",
-      "columnsTo": [
-        "id"
-      ],
+      "columnsTo": ["id"],
       "onUpdate": "NO ACTION",
       "onDelete": "CASCADE",
       "nameExplicit": false,
@@ -1598,13 +1568,9 @@
       "table": "part"
     },
     {
-      "columns": [
-        "session_id"
-      ],
+      "columns": ["session_id"],
       "tableTo": "session",
-      "columnsTo": [
-        "id"
-      ],
+      "columnsTo": ["id"],
       "onUpdate": "NO ACTION",
       "onDelete": "CASCADE",
       "nameExplicit": false,
@@ -1613,13 +1579,9 @@
       "table": "session_context_epoch"
     },
     {
-      "columns": [
-        "session_id"
-      ],
+      "columns": ["session_id"],
       "tableTo": "session",
-      "columnsTo": [
-        "id"
-      ],
+      "columnsTo": ["id"],
       "onUpdate": "NO ACTION",
       "onDelete": "CASCADE",
       "nameExplicit": false,
@@ -1628,13 +1590,9 @@
       "table": "session_input"
     },
     {
-      "columns": [
-        "session_id"
-      ],
+      "columns": ["session_id"],
       "tableTo": "session",
-      "columnsTo": [
-        "id"
-      ],
+      "columnsTo": ["id"],
       "onUpdate": "NO ACTION",
       "onDelete": "CASCADE",
       "nameExplicit": false,
@@ -1643,13 +1601,9 @@
       "table": "session_message"
     },
     {
-      "columns": [
-        "project_id"
-      ],
+      "columns": ["project_id"],
       "tableTo": "project",
-      "columnsTo": [
-        "id"
-      ],
+      "columnsTo": ["id"],
       "onUpdate": "NO ACTION",
       "onDelete": "CASCADE",
       "nameExplicit": false,
@@ -1658,13 +1612,9 @@
       "table": "session"
     },
     {
-      "columns": [
-        "session_id"
-      ],
+      "columns": ["session_id"],
       "tableTo": "session",
-      "columnsTo": [
-        "id"
-      ],
+      "columnsTo": ["id"],
       "onUpdate": "NO ACTION",
       "onDelete": "CASCADE",
       "nameExplicit": false,
@@ -1673,13 +1623,9 @@
       "table": "todo"
     },
     {
-      "columns": [
-        "session_id"
-      ],
+      "columns": ["session_id"],
       "tableTo": "session",
-      "columnsTo": [
-        "id"
-      ],
+      "columnsTo": ["id"],
       "onUpdate": "NO ACTION",
       "onDelete": "CASCADE",
       "nameExplicit": false,
@@ -1688,174 +1634,133 @@
       "table": "session_share"
     },
     {
-      "columns": [
-        "email",
-        "url"
-      ],
+      "columns": ["email", "url"],
       "nameExplicit": false,
       "name": "control_account_pk",
       "entityType": "pks",
       "table": "control_account"
     },
     {
-      "columns": [
-        "project_id",
-        "directory"
-      ],
+      "columns": ["project_id", "directory"],
       "nameExplicit": false,
       "name": "project_directory_pk",
       "entityType": "pks",
       "table": "project_directory"
     },
     {
-      "columns": [
-        "session_id",
-        "position"
-      ],
+      "columns": ["session_id", "position"],
       "nameExplicit": false,
       "name": "todo_pk",
       "entityType": "pks",
       "table": "todo"
     },
     {
-      "columns": [
-        "id"
-      ],
+      "columns": ["id"],
       "nameExplicit": false,
       "name": "workspace_pk",
       "table": "workspace",
       "entityType": "pks"
     },
     {
-      "columns": [
-        "name"
-      ],
+      "columns": ["name"],
       "nameExplicit": false,
       "name": "data_migration_pk",
       "table": "data_migration",
       "entityType": "pks"
     },
     {
-      "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": "credential_pk",
       "table": "credential",
       "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",
       "entityType": "pks"
     },
     {
-      "columns": [
-        "id"
-      ],
+      "columns": ["id"],
       "nameExplicit": false,
       "name": "permission_pk",
       "table": "permission",
       "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": [
-        "session_id"
-      ],
+      "columns": ["session_id"],
       "nameExplicit": false,
       "name": "session_context_epoch_pk",
       "table": "session_context_epoch",
       "entityType": "pks"
     },
     {
-      "columns": [
-        "id"
-      ],
+      "columns": ["id"],
       "nameExplicit": false,
       "name": "session_input_pk",
       "table": "session_input",
       "entityType": "pks"
     },
     {
-      "columns": [
-        "id"
-      ],
+      "columns": ["id"],
       "nameExplicit": false,
       "name": "session_message_pk",
       "table": "session_message",
       "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",

+ 3 - 1
packages/core/src/catalog.ts

@@ -236,7 +236,9 @@ export const layer = Layer.effect(
 
         all: Effect.fn("CatalogV2.provider.all")(function* () {
           const credentials = yield* active()
-          return Array.fromIterable(state.get().providers.values()).map((record) => project(record.provider, credentials))
+          return Array.fromIterable(state.get().providers.values()).map((record) =>
+            project(record.provider, credentials),
+          )
         }),
 
         available: Effect.fn("CatalogV2.provider.available")(function* () {

+ 6 - 10
packages/core/src/connector.ts

@@ -213,10 +213,7 @@ export interface Interface {
         readonly inputs: Inputs
         /** User-facing label for the credential created on completion. */
         readonly label?: string
-      }) => Effect.Effect<
-        Attempt,
-        AuthorizationError
-      >
+      }) => Effect.Effect<Attempt, AuthorizationError>
       /** Returns the current state of an OAuth attempt. */
       readonly status: (attemptID: AttemptID) => Effect.Effect<AttemptStatus>
       /** Completes the attempt and stores its credential. */
@@ -273,7 +270,8 @@ export const locationLayer = Layer.effect(
         list: () => Array.from(draft.connectors.values(), (entry) => entry.connector) as Info[],
         get: (id) => draft.connectors.get(id)?.connector as Info | undefined,
         update: (id, update) => {
-          const current = draft.connectors.get(id) ??
+          const current =
+            draft.connectors.get(id) ??
             castDraft({ connector: new Info({ id, name: id, methods: [] }), implementations: new Map() })
           if (!draft.connectors.has(id)) draft.connectors.set(id, current)
           update(current.connector)
@@ -282,7 +280,8 @@ export const locationLayer = Layer.effect(
         remove: (id) => draft.connectors.delete(id),
         method: {
           update: (implementation) => {
-            const current = draft.connectors.get(implementation.connectorID) ??
+            const current =
+              draft.connectors.get(implementation.connectorID) ??
               castDraft({
                 connector: new Info({ id: implementation.connectorID, name: implementation.connectorID, methods: [] }),
                 implementations: new Map<MethodID, Implementation>(),
@@ -318,10 +317,7 @@ export const locationLayer = Layer.effect(
       return error instanceof Error ? error.message : String(error)
     }
 
-    const settle = Effect.fnUntraced(function* (
-      attemptID: AttemptID,
-      exit: Exit.Exit<Credential.Value, unknown>,
-    ) {
+    const settle = Effect.fnUntraced(function* (attemptID: AttemptID, exit: Exit.Exit<Credential.Value, unknown>) {
       const now = yield* Clock.currentTimeMillis
       const result = yield* SynchronizedRef.modify(attempts, (current) => {
         const attempt = current.get(attemptID)

+ 29 - 15
packages/core/src/credential.ts

@@ -118,7 +118,11 @@ export const legacyImportLayer = Layer.effectDiscard(
       const id = ID.create()
       const connector = ConnectorSchema.ID.make(connectorID.replace(/\/+$/, ""))
       const methodID = ConnectorSchema.MethodID.make(
-        credential.type === "api" ? "api-key" : connector === ConnectorSchema.ID.make("openai") ? "chatgpt-browser" : "oauth",
+        credential.type === "api"
+          ? "api-key"
+          : connector === ConnectorSchema.ID.make("openai")
+            ? "chatgpt-browser"
+            : "oauth",
       )
       const next: Value =
         credential.type === "api"
@@ -206,9 +210,12 @@ export const layer = Layer.effect(
         return row ? info(row) : undefined
       }),
       all: Effect.fn("Credential.all")(function* () {
-        return (yield* db.select().from(CredentialTable).orderBy(asc(CredentialTable.time_created)).all().pipe(Effect.orDie)).map(
-          info,
-        )
+        return (yield* db
+          .select()
+          .from(CredentialTable)
+          .orderBy(asc(CredentialTable.time_created))
+          .all()
+          .pipe(Effect.orDie)).map(info)
       }),
       active: Effect.fn("Credential.active")(function* (connectorID) {
         const row = yield* db
@@ -220,19 +227,22 @@ export const layer = Layer.effect(
         return row ? info(row) : undefined
       }),
       activeAll: Effect.fn("Credential.activeAll")(function* () {
-        const rows = yield* db.select().from(CredentialTable).where(eq(CredentialTable.active, true)).all().pipe(Effect.orDie)
+        const rows = yield* db
+          .select()
+          .from(CredentialTable)
+          .where(eq(CredentialTable.active, true))
+          .all()
+          .pipe(Effect.orDie)
         return new Map(rows.map((row) => [row.connector_id, info(row)]))
       }),
       forConnector: Effect.fn("Credential.forConnector")(function* (connectorID) {
-        return (
-          yield* db
-            .select()
-            .from(CredentialTable)
-            .where(eq(CredentialTable.connector_id, connectorID))
-            .orderBy(asc(CredentialTable.time_created))
-            .all()
-            .pipe(Effect.orDie)
-        ).map(info)
+        return (yield* db
+          .select()
+          .from(CredentialTable)
+          .where(eq(CredentialTable.connector_id, connectorID))
+          .orderBy(asc(CredentialTable.time_created))
+          .all()
+          .pipe(Effect.orDie)).map(info)
       }),
       create: Effect.fn("Credential.create")(function* (input) {
         const credential = new Info({
@@ -298,7 +308,11 @@ export const layer = Layer.effect(
                 .orderBy(asc(CredentialTable.time_created))
                 .get()
               if (replacement) {
-                yield* tx.update(CredentialTable).set({ active: true }).where(eq(CredentialTable.id, replacement.id)).run()
+                yield* tx
+                  .update(CredentialTable)
+                  .set({ active: true })
+                  .where(eq(CredentialTable.id, replacement.id))
+                  .run()
               }
               return {
                 credential: info(row),

+ 3 - 1
packages/core/src/credential/sql.ts

@@ -16,6 +16,8 @@ export const CredentialTable = sqliteTable(
     ...Timestamps,
   },
   (table) => [
-    uniqueIndex("credential_connector_active_idx").on(table.connector_id).where(sql`${table.active} = 1`),
+    uniqueIndex("credential_connector_active_idx")
+      .on(table.connector_id)
+      .where(sql`${table.active} = 1`),
   ],
 )

+ 3 - 1
packages/core/src/database/migration/20260611035744_credential.ts

@@ -17,7 +17,9 @@ export default {
           \`time_updated\` integer NOT NULL
         );
       `)
-      yield* tx.run(`CREATE UNIQUE INDEX \`credential_connector_active_idx\` ON \`credential\` (\`connector_id\`) WHERE "credential"."active" = 1;`)
+      yield* tx.run(
+        `CREATE UNIQUE INDEX \`credential_connector_active_idx\` ON \`credential\` (\`connector_id\`) WHERE "credential"."active" = 1;`,
+      )
     })
   },
 } satisfies DatabaseMigration.Migration

+ 4 - 1
packages/core/src/plugin/provider/cloudflare-workers-ai.ts

@@ -28,7 +28,10 @@ export const CloudflareWorkersAIPlugin = PluginV2.define({
         if (!hasWorkersEndpoint(evt.model.api) && !accountId) return
         const mod = yield* Effect.promise(() => import("@ai-sdk/openai-compatible"))
         evt.sdk = mod.createOpenAICompatible(
-          sdkOptions({ ...evt.options, baseURL: evt.options.baseURL ?? (accountId ? workersEndpoint(accountId) : undefined) }) as any,
+          sdkOptions({
+            ...evt.options,
+            baseURL: evt.options.baseURL ?? (accountId ? workersEndpoint(accountId) : undefined),
+          }) as any,
         )
       }),
       "aisdk.language": Effect.fn(function* (evt) {

+ 2 - 1
packages/core/src/plugin/provider/openai-auth.ts

@@ -246,6 +246,7 @@ function claim(token: string) {
   }
 }
 
-const successPage = "<!doctype html><title>OpenCode</title><h1>Authorization successful</h1><p>You can close this window.</p>"
+const successPage =
+  "<!doctype html><title>OpenCode</title><h1>Authorization successful</h1><p>You can close this window.</p>"
 const errorPage = (message: string) =>
   `<!doctype html><title>OpenCode</title><h1>Authorization failed</h1><p>${message.replace(/[&<>"']/g, "")}</p>`

+ 4 - 6
packages/core/test/connector.test.ts

@@ -47,9 +47,7 @@ describe("Connector", () => {
       yield* connectors
         .update((editor) => editor.update(openai, (connector) => (connector.name = "OpenAI")))
         .pipe(Scope.provide(scope))
-      expect(yield* connectors.get(openai)).toEqual(
-        new Connector.Info({ id: openai, name: "OpenAI", methods: [] }),
-      )
+      expect(yield* connectors.get(openai)).toEqual(new Connector.Info({ id: openai, name: "OpenAI", methods: [] }))
 
       yield* Scope.close(scope, Exit.void)
       expect(yield* connectors.get(openai)).toBeUndefined()
@@ -313,9 +311,9 @@ describe("Connector", () => {
       )
 
       const attempt = yield* connectors.connect.oauth.begin({ connectorID, methodID, inputs: {} })
-      expect(yield* connectors.connect.oauth.complete({ attemptID: attempt.attemptID }).pipe(Effect.flip)).toBeInstanceOf(
-        Connector.CodeRequiredError,
-      )
+      expect(
+        yield* connectors.connect.oauth.complete({ attemptID: attempt.attemptID }).pipe(Effect.flip),
+      ).toBeInstanceOf(Connector.CodeRequiredError)
       expect(closed).toBe(false)
       yield* connectors.connect.oauth.cancel(attempt.attemptID)
       expect(closed).toBe(true)

+ 0 - 1
packages/core/test/credential.test.ts

@@ -203,5 +203,4 @@ describe("Credential", () => {
       ),
     ),
   )
-
 })

+ 2 - 7
packages/core/test/plugin/models-dev.test.ts

@@ -23,13 +23,8 @@ const locationLayer = Layer.succeed(
 )
 const plugins = PluginV2.layer.pipe(Layer.provide(events))
 const policy = Policy.layer.pipe(Layer.provide(locationLayer))
-const credentials = Credential.layer.pipe(
-  Layer.provide(Database.layerFromPath(":memory:")),
-  Layer.provide(events),
-)
-const catalog = Catalog.layer.pipe(
-  Layer.provide(Layer.mergeAll(events, locationLayer, plugins, policy, credentials)),
-)
+const credentials = Credential.layer.pipe(Layer.provide(Database.layerFromPath(":memory:")), Layer.provide(events))
+const catalog = Catalog.layer.pipe(Layer.provide(Layer.mergeAll(events, locationLayer, plugins, policy, credentials)))
 const connectors = Connector.locationLayer.pipe(Layer.provide(credentials), Layer.provide(events))
 const layer = Layer.mergeAll(catalog, connectors, credentials, events, locationLayer, plugins)
 const it = testEffect(layer)

+ 6 - 4
packages/core/test/plugin/provider-cloudflare-workers-ai.test.ts

@@ -152,10 +152,12 @@ describe("CloudflareWorkersAIPlugin", () => {
               provider.api = { type: "aisdk", package: "test-provider" }
             }),
           )
-          expect((yield* catalog.provider.get(ProviderV2.ID.make("cloudflare-workers-ai"))).request.body).toMatchObject({
-            apiKey: "account-key",
-            accountId: "account-acct",
-          })
+          expect((yield* catalog.provider.get(ProviderV2.ID.make("cloudflare-workers-ai"))).request.body).toMatchObject(
+            {
+              apiKey: "account-key",
+              accountId: "account-acct",
+            },
+          )
         }),
     ),
   )

Plik diff jest za duży
+ 495 - 274
packages/sdk/openapi.json


+ 12 - 11
packages/server/src/handlers/connector.ts

@@ -76,17 +76,18 @@ export const ConnectorHandler = HttpApiBuilder.group(Api, "server.connector", (h
         "connector.connect.oauth.complete",
         Effect.fn(function* (ctx) {
           const service = yield* Connector.Service
-          yield* service.connect.oauth
-            .complete({ attemptID: ctx.params.attemptID, code: ctx.payload.code })
-            .pipe(
-              Effect.mapError(
-                (error) =>
-                  new InvalidRequestError({
-                    message: error._tag === "Connector.CodeRequired" ? "Authorization code is required" : "Authentication failed",
-                    kind: error._tag === "Connector.CodeRequired" ? "connector_code_required" : "connector_authorization",
-                  }),
-              ),
-            )
+          yield* service.connect.oauth.complete({ attemptID: ctx.params.attemptID, code: ctx.payload.code }).pipe(
+            Effect.mapError(
+              (error) =>
+                new InvalidRequestError({
+                  message:
+                    error._tag === "Connector.CodeRequired"
+                      ? "Authorization code is required"
+                      : "Authentication failed",
+                  kind: error._tag === "Connector.CodeRequired" ? "connector_code_required" : "connector_authorization",
+                }),
+            ),
+          )
           return HttpApiSchema.NoContent.make()
         }),
       )

+ 1 - 4
packages/tui/src/context/data.tsx

@@ -425,10 +425,7 @@ export const { use: useData, provider: DataProvider } = createSimpleContext({
           break
         case "credential.switched": {
           const location = { directory: metadata.directory, workspaceID: metadata.workspace }
-          void Promise.allSettled([
-            result.location.model.refresh(location),
-            result.location.provider.refresh(location),
-          ])
+          void Promise.allSettled([result.location.model.refresh(location), result.location.provider.refresh(location)])
           break
         }
         case "connector.updated":

+ 5 - 1
packages/tui/test/fixture/tui-sdk.ts

@@ -60,7 +60,11 @@ export function createFetch(override?: FetchHandler) {
     if (url.pathname === "/experimental/console") return json({ consoleManagedProviders: [], switchableOrgCount: 0 })
     if (url.pathname === "/path") return json({ home: "", state: "", config: "", worktree, directory })
     if (url.pathname === "/api/location") return json({ directory, project: { id: "proj_test", directory: worktree } })
-    if (["/api/agent", "/api/model", "/api/provider", "/api/connector", "/api/command", "/api/skill"].includes(url.pathname))
+    if (
+      ["/api/agent", "/api/model", "/api/provider", "/api/connector", "/api/command", "/api/skill"].includes(
+        url.pathname,
+      )
+    )
       return json({
         location: { directory, project: { id: "proj_test", directory: worktree } },
         data: [],

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików