GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(core): drop the separate new-account ChatGPT sign-in · anomalyco/opencode@2b97632

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages
    • app/src/providers/connect
      • dialog-machine.ts
    • core
      • src/plugin/provider
        • chatgpt.ts
      • test/plugin
        • provider-chatgpt.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/app/src/providers/connect/dialog-machine.ts‎

Copy file name to clipboardExpand all lines: packages/app/src/providers/connect/dialog-machine.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ function connectTransition(
720720
...next,
721721
chatgptWelcome:
722722
state.chatgptWelcome ||
723-
(state.provider === "openai" && method.type === "oauth" && method.id.startsWith("chatgpt-token-sharing")),
723+
(state.provider === "openai" && method.type === "oauth" && method.id === "chatgpt-token-sharing"),
724724
}
725725

726726
const notify: ProviderDialogEffect[] = [...effects, { type: "connected.notify", provider: state.provider }]
Collapse file

‎packages/core/src/plugin/provider/chatgpt.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/plugin/provider/chatgpt.ts
+5-17Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ const tokenSharingScope = "chatgpt.tokens.use.direct"
3131
const providerID = Provider.ID.openai
3232
const integrationID = Integration.ID.make("openai")
3333
const methodID = Integration.MethodID.make("chatgpt-token-sharing")
34-
const newAccountMethodID = Integration.MethodID.make("chatgpt-token-sharing-new")
3534
// Each issued client belongs to one ChatGPT account and workspace. Profiles outlive logout so signing in again reuses
3635
// the client instead of registering another app in the user's ChatGPT settings.
3736
const profilesKey = "chatgpt-profiles"
@@ -116,18 +115,13 @@ const decodeMetadata = Schema.decodeUnknownOption(
116115
}),
117116
)
118117

119-
const signIn = (
120-
app: App.Info,
121-
savedClients: () => Effect.Effect<ReadonlyArray<string>>,
122-
storage: Context["storage"],
123-
newAccount = false,
124-
) =>
118+
const signIn = (app: App.Info, savedClients: () => Effect.Effect<ReadonlyArray<string>>, storage: Context["storage"]) =>
125119
({
126120
integrationID,
127121
method: {
128-
id: newAccount ? newAccountMethodID : methodID,
122+
id: methodID,
129123
type: "oauth",
130-
label: newAccount ? "Use a different ChatGPT account" : "Sign in with ChatGPT",
124+
label: "Sign in with ChatGPT",
131125
},
132126
authorize: () =>
133127
Effect.gen(function* () {
@@ -142,7 +136,7 @@ const signIn = (
142136
const expired = yield* expiredClients(storage)
143137
// A working saved account means this sign-in adds another one, which needs its own client.
144138
const adding = (yield* savedClients()).some((id) => !expired.includes(id))
145-
const savedID = newAccount || adding || typeof last !== "string" ? undefined : last
139+
const savedID = adding || typeof last !== "string" ? undefined : last
146140
const profile = savedID ? profiles?.[savedID] : undefined
147141
// `response` is the browser's pending callback request; a pasted redirect has none.
148142
const received = yield* Deferred.make<{ code: string; clientID?: string; response?: ServerResponse }, Error>()
@@ -222,7 +216,7 @@ const signIn = (
222216
if (profile && identity.subject !== profile.subject)
223217
return yield* Effect.fail(
224218
new Error(
225-
"ChatGPT signed in with a different account than this connection. Choose “Use a different ChatGPT account” instead.",
219+
"ChatGPT signed in with a different account than the one you last used. To add another account, connect your last account first, then choose Add account.",
226220
),
227221
)
228222
const saved = Option.getOrUndefined(decodeProfiles(yield* storage.get(profilesKey)))
@@ -281,8 +275,6 @@ export const ChatGPTPlugin = define({
281275
const credentials = yield* Credential.Service
282276
const loading = Semaphore.makeUnsafe(1)
283277
let chatgpt: Credential.OAuth | undefined
284-
// Offer a separate new-account sign-in once there is an account to switch away from.
285-
let known = false
286278
// let available: ReadonlyArray<RemoteModel> | undefined
287279
let source: Effect.Success<ReturnType<typeof ctx.integration.connection.active>>
288280

@@ -296,9 +288,6 @@ export const ChatGPTPlugin = define({
296288
const clientID = Option.getOrUndefined(decodeMetadata(chatgpt?.metadata))?.clientID
297289
if (clientID && (yield* ctx.storage.get(lastClientKey)) === undefined)
298290
yield* ctx.storage.set(lastClientKey, clientID)
299-
const wasKnown = known
300-
known = chatgpt !== undefined || typeof (yield* ctx.storage.get(lastClientKey)) === "string"
301-
if (known !== wasKnown) yield* ctx.integration.reload()
302291
// if (previous !== IntegrationConnection.key(source)) {
303292
// const metadata = Option.getOrUndefined(decodeMetadata(chatgpt?.metadata))
304293
// const stored = metadata ? yield* ctx.storage.get(modelCacheKey(metadata.clientID)) : undefined
@@ -319,7 +308,6 @@ export const ChatGPTPlugin = define({
319308
)
320309
yield* ctx.integration.transform((editor) => {
321310
editor.method.update(signIn(ctx.app, savedClients, ctx.storage))
322-
if (known) editor.method.update(signIn(ctx.app, savedClients, ctx.storage, true))
323311
})
324312
yield* Effect.forEach(
325313
yield* credentials.list(Integration.ID.make("openai")),
Collapse file

‎packages/core/test/plugin/provider-chatgpt.test.ts‎

Copy file name to clipboardExpand all lines: packages/core/test/plugin/provider-chatgpt.test.ts
+2-28Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -592,33 +592,11 @@ describe("ChatGPTPlugin", () => {
592592
expect(url.searchParams.has("agent_name_hint")).toBe(false)
593593
expect(url.searchParams.get("id_token_hint")).toBe("id-token")
594594
expect(url.searchParams.get("login_hint")).toBe("[email protected]")
595-
596-
const integrations = yield* Integration.Service
597-
const attempt = yield* integrations.oauth.connect({
598-
integrationID: Integration.ID.make("openai"),
599-
methodID: Integration.MethodID.make("chatgpt-token-sharing-new"),
600-
})
601-
yield* integrations.oauth.cancel({ integrationID: Integration.ID.make("openai"), attemptID: attempt.attemptID })
602-
const fresh = new URL(attempt.url)
603-
expect(fresh.searchParams.get("client_id")).toBe("dynamic_agent_client")
604-
expect(fresh.searchParams.get("agent_name_hint")).toBe("OpenCode")
605-
expect(fresh.searchParams.has("id_token_hint")).toBe(false)
606595
}),
607596
)
608597

609-
it.effect("offers a new-account sign-in only after an account is known", () =>
598+
it.effect("remembers the client of a connection made before profiles existed", () =>
610599
Effect.gen(function* () {
611-
yield* addPlugin()
612-
const integrations = yield* Integration.Service
613-
const ids = () =>
614-
integrations
615-
.get(Integration.ID.make("openai"))
616-
.pipe(
617-
Effect.map((item) =>
618-
item?.methods.map((method) => (method.type === "oauth" ? String(method.id) : undefined)),
619-
),
620-
)
621-
expect(yield* ids()).toEqual(["chatgpt-token-sharing"])
622600
const credentials = yield* Credential.Service
623601
yield* credentials.create({
624602
integrationID: Integration.ID.make("openai"),
@@ -631,11 +609,7 @@ describe("ChatGPTPlugin", () => {
631609
metadata: { clientID: "oaiapp_issued" },
632610
}),
633611
})
634-
yield* Effect.gen(function* () {
635-
const found = yield* ids()
636-
if (found?.length !== 2) return yield* Effect.fail("pending")
637-
}).pipe(Effect.retry(Schedule.spaced("10 millis")), Effect.timeout("2 seconds"))
638-
expect(yield* ids()).toEqual(["chatgpt-token-sharing", "chatgpt-token-sharing-new"])
612+
yield* addPlugin()
639613
const kv = yield* KV.Service
640614
expect(yield* PluginHost.storage(kv, ChatGPTPlugin.id).get("chatgpt-last-client")).toBe("oaiapp_issued")
641615
}),

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.