@qvac/core 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist-lib/lib/assistant/history.d.ts +10 -1
  2. package/dist-lib/lib/assistant/history.js +36 -1
  3. package/dist-lib/lib/assistant/message.d.ts +2 -0
  4. package/dist-lib/lib/assistant/message.js +11 -0
  5. package/dist-lib/lib/assistant/skill-encode.js +27 -1
  6. package/dist-lib/lib/assistant.d.ts +5 -2
  7. package/dist-lib/lib/assistant.js +41 -8
  8. package/dist-lib/lib/core/skill-secrets.js +3 -6
  9. package/dist-lib/lib/core.d.ts +1 -0
  10. package/dist-lib/lib/core.js +51 -9
  11. package/dist-lib/lib/credential-pusher.d.ts +2 -3
  12. package/dist-lib/lib/credential-pusher.js +67 -39
  13. package/dist-lib/lib/integrations/index.d.ts +1 -2
  14. package/dist-lib/lib/integrations/index.js +0 -1
  15. package/dist-lib/lib/integrations/setup-routes.js +0 -15
  16. package/dist-lib/lib/oauth/flow-core.js +1 -1
  17. package/dist-lib/lib/oauth/flow.d.ts +4 -2
  18. package/dist-lib/lib/oauth/flow.js +3 -4
  19. package/dist-lib/lib/oauth/host.d.ts +3 -1
  20. package/dist-lib/lib/oauth/host.js +3 -1
  21. package/dist-lib/lib/oauth/keys.d.ts +21 -20
  22. package/dist-lib/lib/oauth/keys.js +59 -85
  23. package/dist-lib/lib/oauth/loopback.d.ts +2 -2
  24. package/dist-lib/lib/oauth/loopback.js +32 -19
  25. package/dist-lib/lib/oauth/loopback.stub.d.ts +2 -2
  26. package/dist-lib/lib/oauth/loopback.stub.js +2 -2
  27. package/dist-lib/lib/oauth/providers.d.ts +3 -5
  28. package/dist-lib/lib/oauth/providers.js +20 -67
  29. package/dist-lib/lib/oauth/redirect-types.d.ts +1 -0
  30. package/dist-lib/lib/oauth/registry.d.ts +10 -0
  31. package/dist-lib/lib/oauth/registry.js +25 -0
  32. package/dist-lib/lib/oauth/resolve.js +1 -1
  33. package/dist-lib/lib/oauth/token-exchange-core.js +2 -1
  34. package/dist-lib/lib/oauth/types.d.ts +1 -1
  35. package/dist-lib/lib/oauth.client.d.ts +3 -1
  36. package/dist-lib/lib/oauth.client.js +3 -1
  37. package/dist-lib/lib/oauth.d.ts +4 -7
  38. package/dist-lib/lib/oauth.js +4 -7
  39. package/dist-lib/lib/skill-types.d.ts +12 -0
  40. package/dist-lib/schema/engine.js +21 -1
  41. package/dist-lib/spec/hrpc/messages.js +114 -5
  42. package/dist-lib/spec/hyperschema/index.js +114 -5
  43. package/dist-lib/spec/hyperschema/schema.json +84 -1
  44. package/dist-lib/spec/hyperschema/types.d.ts +18 -1
  45. package/package.json +4 -4
  46. package/tui/app.mjs +98 -155
  47. package/tui/lib/save-file.mjs +1 -1
  48. package/dist-lib/lib/integrations/oauth-providers.d.ts +0 -14
  49. package/dist-lib/lib/integrations/oauth-providers.js +0 -116
  50. package/dist-lib/lib/oauth/asana.d.ts +0 -35
  51. package/dist-lib/lib/oauth/asana.js +0 -71
  52. package/dist-lib/lib/oauth/google.d.ts +0 -37
  53. package/dist-lib/lib/oauth/google.js +0 -77
  54. package/dist-lib/lib/oauth/notion.d.ts +0 -34
  55. package/dist-lib/lib/oauth/notion.js +0 -82
  56. package/dist-lib/lib/oauth/spotify.d.ts +0 -32
  57. package/dist-lib/lib/oauth/spotify.js +0 -74
  58. package/dist-lib/lib/oauth/verify.d.ts +0 -8
  59. package/dist-lib/lib/oauth/verify.js +0 -58
package/tui/app.mjs CHANGED
@@ -9,13 +9,9 @@ import { TOOLSETS } from '@qvac/harness/lib/tools/toolsets.ts'
9
9
  import os from 'os'
10
10
  import path from 'path'
11
11
  import process from 'process'
12
- import {
13
- ASANA_MCP_CREDENTIAL_KEY,
14
- NOTION_MCP_CREDENTIAL_KEY,
15
- oauthKeySpec,
16
- scopedKey,
17
- SPOTIFY_CREDENTIAL_KEY
18
- } from '../dist-lib/lib/oauth/keys.js'
12
+ import { scopedKey } from '../dist-lib/lib/oauth/keys.js'
13
+ import { oauthSpecs } from '../dist-lib/lib/oauth/registry.js'
14
+ import { settingConfigKey } from '../dist-lib/lib/credential-pusher.js'
19
15
  import {
20
16
  COMPACTION_MIN_CTX_SIZE,
21
17
  contextOptionsForModel,
@@ -42,6 +38,7 @@ import { compactionTriggerRatio } from '../dist-lib/lib/compaction.js'
42
38
  import { rememberSelection } from './lib/selection.mjs'
43
39
  import {
44
40
  configureActions,
41
+ connectSlug,
45
42
  isReady,
46
43
  setupAction,
47
44
  setupActions,
@@ -245,20 +242,7 @@ const COMMANDS = [
245
242
  },
246
243
  { name: 'meshes', desc: 'list the meshes this device belongs to', palette: true },
247
244
  { name: 'cred', desc: 'set a credential value for this agent' },
248
- {
249
- name: 'connect',
250
- desc: 'OAuth-connect a skill for this agent',
251
- sub: [
252
- { name: 'gmail', desc: 'Google OAuth (needs GOOGLE_OAUTH_CLIENT_ID + _SECRET)' },
253
- { name: 'google-calendar', desc: 'Google OAuth (needs GOOGLE_OAUTH_CLIENT_ID + _SECRET)' },
254
- { name: 'google-docs', desc: 'Google OAuth (needs GOOGLE_OAUTH_CLIENT_ID + _SECRET)' },
255
- { name: 'google-drive', desc: 'Google OAuth (needs GOOGLE_OAUTH_CLIENT_ID + _SECRET)' },
256
- { name: 'google-sheets', desc: 'Google OAuth (needs GOOGLE_OAUTH_CLIENT_ID + _SECRET)' },
257
- { name: 'spotify', desc: 'Spotify OAuth, PKCE only (needs SPOTIFY_OAUTH_CLIENT_ID)' },
258
- { name: 'notion', desc: 'Notion MCP OAuth, PKCE + dynamic registration (no env)' },
259
- { name: 'asana', desc: 'Asana MCP OAuth, PKCE (needs ASANA_OAUTH_CLIENT_ID + _SECRET)' }
260
- ]
261
- },
245
+ { name: 'connect', desc: 'OAuth-connect a skill for this agent', palette: true },
262
246
  {
263
247
  name: 'my-device',
264
248
  desc: 'CPU/GPU inventory for this device (manufacturer, cores, drivers, …)'
@@ -1738,10 +1722,8 @@ export class ChatApp {
1738
1722
  ' /image [model <choice> | steps <n> | size <WxH> | reset] — the agent’s image-generation defaults',
1739
1723
  '',
1740
1724
  'Connections — a skill that needs an account or a token (Menu ▸ Agent ▸ Connections lists them with their state)',
1741
- ' /connect gmail|google-calendar|google-docs|google-drive|google-sheets — connect one Google skill (needs GOOGLE_OAUTH_CLIENT_ID + GOOGLE_OAUTH_CLIENT_SECRET)',
1742
- ' /connect spotify — OAuth-connect Spotify via PKCE (needs SPOTIFY_OAUTH_CLIENT_ID; no secret)',
1743
- ' /connect notion — OAuth-connect Notion MCP via PKCE + dynamic registration (no env, no secret)',
1744
- ' /connect asana — OAuth-connect Asana MCP via PKCE (needs ASANA_OAUTH_CLIENT_ID + ASANA_OAUTH_CLIENT_SECRET)',
1725
+ ' /connect <skill> — OAuth-connect a skill that declares one (the Connections page lists them)',
1726
+ ' the client app credentials come from <PROVIDER>_OAUTH_CLIENT_ID and <PROVIDER>_OAUTH_CLIENT_SECRET; a skill that registers its own client needs neither',
1745
1727
  '',
1746
1728
  'Voice',
1747
1729
  ' /speak <text> — synthesize speech (TTS) to a WAV file in the save dir',
@@ -2092,7 +2074,7 @@ export class ChatApp {
2092
2074
  const bytes = Buffer.concat(pieces)
2093
2075
  if (!bytes.length) return `empty download for ${att.fileName}`
2094
2076
  const ext = { 'image/jpeg': '.jpg', 'image/png': '.png' }[att.mimeType]
2095
- const file = await saveUniqueFile(this._saveDir, att.fileName, bytes, ext ?? '')
2077
+ const file = await saveUniqueFile(this._saveDir, att.fileName, bytes, ext)
2096
2078
  if (file) return `saved ${att.fileName} (${bytes.length}B) to ${file}`
2097
2079
  return `not saved: 100 files named ${att.fileName} already exist in ${this._saveDir}`
2098
2080
  })
@@ -2213,134 +2195,103 @@ export class ChatApp {
2213
2195
  }
2214
2196
 
2215
2197
  if (cmd === 'connect') {
2216
- const [provider = ''] = rest
2217
- // Each Google skill has its own key, scopes and app: `connect gmail`, `connect google-docs`.
2218
- const googleSpec = oauthKeySpec(`${provider.replaceAll('-', '_')}_access_token`)
2219
- if (googleSpec?.provider === 'google') {
2220
- const clientId = process.env.GOOGLE_OAUTH_CLIENT_ID
2221
- const clientSecret = process.env.GOOGLE_OAUTH_CLIENT_SECRET
2222
- if (!clientId || !clientSecret) {
2223
- return notice('set GOOGLE_OAUTH_CLIENT_ID and GOOGLE_OAUTH_CLIENT_SECRET, then retry')
2198
+ const [slug = ''] = rest
2199
+ if (!slug) return notice('usage: /connect <skill> — Menu ▸ Agent ▸ Connections lists them')
2200
+ return run(async () => {
2201
+ let skills
2202
+ try {
2203
+ skills = this._skills ? await this._skills(agent.id, agent.modelName) : []
2204
+ } catch (error) {
2205
+ return `could not read the skill catalog: ${error?.message ?? error}`
2224
2206
  }
2225
- return run(async () => {
2226
- const { connectGoogle } = await import('../dist-lib/lib/oauth.js')
2227
- const tokens = await connectGoogle({
2228
- clientId,
2229
- clientSecret,
2230
- credentialKey: googleSpec.credentialKey,
2231
- openUrl: (url) => {
2232
- this.status = fg.dim.render(`authorize in your browser: ${url}`)
2233
- this._render()
2234
- openInBrowser(url)
2235
- }
2236
- })
2237
- await engine.configSet({
2238
- key: credKey(agent.id, googleSpec.credentialKey),
2239
- value: tokens.accessToken
2240
- })
2241
- await engine.configSet({
2242
- key: credKey(agent.id, googleSpec.stateKey),
2243
- value: JSON.stringify({
2244
- refreshToken: tokens.refreshToken,
2245
- expiresAt: tokens.expiresAt,
2246
- clientId,
2247
- clientSecret
2248
- })
2249
- })
2250
- return `${provider} connected for agent ${agent.name} — token stored, auto-refreshes on use`
2251
- })
2252
- }
2253
- if (provider === 'spotify') {
2254
- const clientId = process.env.SPOTIFY_OAUTH_CLIENT_ID
2255
- if (!clientId) {
2256
- return notice('set SPOTIFY_OAUTH_CLIENT_ID, then retry')
2207
+ const matches = oauthSpecs(skills ?? []).filter(
2208
+ (candidate) => connectSlug(candidate.credentialKey) === slug
2209
+ )
2210
+ if (matches.length === 0) {
2211
+ return `no connectable skill named ${slug} — Menu ▸ Agent ▸ Connections`
2257
2212
  }
2258
- return run(async () => {
2259
- const { connectSpotify, SPOTIFY_OAUTH_STATE_KEY } = await import('../dist-lib/lib/oauth.js')
2260
- const tokens = await connectSpotify({
2261
- clientId,
2262
- openUrl: (url) => {
2263
- this.status = fg.dim.render(`authorize in your browser: ${url}`)
2264
- this._render()
2265
- openInBrowser(url)
2266
- }
2267
- })
2268
- await engine.configSet({
2269
- key: credKey(agent.id, SPOTIFY_CREDENTIAL_KEY),
2270
- value: tokens.accessToken
2271
- })
2272
- await engine.configSet({
2273
- key: credKey(agent.id, SPOTIFY_OAUTH_STATE_KEY),
2274
- value: JSON.stringify({
2275
- refreshToken: tokens.refreshToken,
2276
- expiresAt: tokens.expiresAt,
2277
- clientId
2278
- })
2279
- })
2280
- return `spotify connected for agent ${agent.name} — token stored, auto-refreshes on use`
2281
- })
2282
- }
2283
- if (provider === 'notion') {
2284
- return run(async () => {
2285
- const { connectNotion, NOTION_OAUTH_STATE_KEY } = await import('../dist-lib/lib/oauth.js')
2286
- const tokens = await connectNotion({
2287
- openUrl: (url) => {
2288
- this.status = fg.dim.render(`authorize in your browser: ${url}`)
2289
- this._render()
2290
- openInBrowser(url)
2291
- }
2292
- })
2293
- await engine.configSet({
2294
- key: credKey(agent.id, NOTION_MCP_CREDENTIAL_KEY),
2295
- value: tokens.accessToken
2296
- })
2297
- await engine.configSet({
2298
- key: credKey(agent.id, NOTION_OAUTH_STATE_KEY),
2299
- value: JSON.stringify({
2300
- refreshToken: tokens.refreshToken,
2301
- expiresAt: tokens.expiresAt,
2302
- clientId: tokens.clientId
2303
- })
2304
- })
2305
- return `notion connected for agent ${agent.name} — token stored, auto-refreshes on use`
2306
- })
2307
- }
2308
- if (provider === 'asana') {
2309
- const clientId = process.env.ASANA_OAUTH_CLIENT_ID
2310
- const clientSecret = process.env.ASANA_OAUTH_CLIENT_SECRET
2311
- if (!clientId || !clientSecret) {
2312
- return notice('set ASANA_OAUTH_CLIENT_ID and ASANA_OAUTH_CLIENT_SECRET, then retry')
2213
+ if (matches.length > 1) {
2214
+ const keys = matches.map((m) => m.credentialKey).join(', ')
2215
+ return `${slug} is ambiguous — matches ${keys}, use the full credential key`
2313
2216
  }
2314
- return run(async () => {
2315
- const { connectAsana, ASANA_OAUTH_STATE_KEY } = await import('../dist-lib/lib/oauth.js')
2316
- const tokens = await connectAsana({
2217
+ const [spec] = matches
2218
+ // the setup fields are stored per declaring skill, and a `secret` one lands in the
2219
+ // credential namespace rather than the settings one (see lib/core/skill-secrets.ts)
2220
+ const owner = (skills ?? []).find((skill) =>
2221
+ (skill.setup?.routes ?? []).some((route) => route.credentialKey === spec.credentialKey)
2222
+ )
2223
+ const ownerRoute = (owner?.setup?.routes ?? []).find(
2224
+ (route) => route.credentialKey === spec.credentialKey
2225
+ )
2226
+ const storedField = async (name) => {
2227
+ const field = (ownerRoute?.fields ?? []).find((entry) => entry.key === name)
2228
+ if (!field || !owner) return ''
2229
+ const key =
2230
+ field.secret === true
2231
+ ? credKey(agent.id, field.key)
2232
+ : settingConfigKey(agent.id, owner.name, field.key)
2233
+ const { value } = await engine.configGet({ key })
2234
+ return typeof value === 'string' ? value : ''
2235
+ }
2236
+ const env = spec.provider.toUpperCase().replaceAll('-', '_')
2237
+ const idVar = `${env}_OAUTH_CLIENT_ID`
2238
+ const secretVar = `${env}_OAUTH_CLIENT_SECRET`
2239
+ const needsSecret = spec.tokenAuth !== 'pkce-only'
2240
+ const clientId = (await storedField('clientId')) || process.env[idVar] || ''
2241
+ const clientSecret = (await storedField('clientSecret')) || process.env[secretVar] || ''
2242
+ // registrationEndpoint implies pkce-only (keys.ts specFromRoute), so a DCR skill never
2243
+ // reaches the secret check below demanding one it has no use for
2244
+ if (!clientId && !spec.registrationEndpoint) {
2245
+ return needsSecret
2246
+ ? `set ${idVar} and ${secretVar}, then retry`
2247
+ : `set ${idVar}, then retry`
2248
+ }
2249
+ if (needsSecret && !clientSecret) return `set ${idVar} and ${secretVar}, then retry`
2250
+
2251
+ const { buildProviderConfig, runOAuthFlow } = await import('../dist-lib/lib/oauth.js')
2252
+ let registeredClientId = ''
2253
+ const tokens = await runOAuthFlow(
2254
+ buildProviderConfig(spec, {
2317
2255
  clientId,
2318
- clientSecret,
2256
+ ...(needsSecret ? { clientSecret } : {})
2257
+ }),
2258
+ {
2319
2259
  openUrl: (url) => {
2320
2260
  this.status = fg.dim.render(`authorize in your browser: ${url}`)
2321
2261
  this._render()
2322
2262
  openInBrowser(url)
2263
+ },
2264
+ getClientId: async () => {
2265
+ // a prior run may have registered a client already — read it back from state
2266
+ // instead of re-registering a fresh one at the provider every /connect
2267
+ const { value } = await engine.configGet({ key: credKey(agent.id, spec.stateKey) })
2268
+ try {
2269
+ const state = typeof value === 'string' ? JSON.parse(value) : null
2270
+ return state?.clientId || undefined
2271
+ } catch {
2272
+ return undefined
2273
+ }
2274
+ },
2275
+ saveClientId: async (id) => {
2276
+ registeredClientId = id
2323
2277
  }
2278
+ }
2279
+ )
2280
+ await engine.configSet({
2281
+ key: credKey(agent.id, spec.credentialKey),
2282
+ value: tokens.accessToken
2283
+ })
2284
+ await engine.configSet({
2285
+ key: credKey(agent.id, spec.stateKey),
2286
+ value: JSON.stringify({
2287
+ refreshToken: tokens.refreshToken,
2288
+ expiresAt: tokens.expiresAt,
2289
+ clientId: clientId || registeredClientId,
2290
+ ...(needsSecret ? { clientSecret } : {})
2324
2291
  })
2325
- await engine.configSet({
2326
- key: credKey(agent.id, ASANA_MCP_CREDENTIAL_KEY),
2327
- value: tokens.accessToken
2328
- })
2329
- await engine.configSet({
2330
- key: credKey(agent.id, ASANA_OAUTH_STATE_KEY),
2331
- value: JSON.stringify({
2332
- refreshToken: tokens.refreshToken,
2333
- expiresAt: tokens.expiresAt,
2334
- clientId,
2335
- clientSecret
2336
- })
2337
- })
2338
- return `asana connected for agent ${agent.name} — token stored, auto-refreshes on use`
2339
2292
  })
2340
- }
2341
- return notice(
2342
- 'usage: /connect gmail|google-calendar|google-docs|google-drive|google-sheets|spotify|notion|asana'
2343
- )
2293
+ return `${slug} connected for agent ${agent.name} — token stored, auto-refreshes on use`
2294
+ })
2344
2295
  }
2345
2296
 
2346
2297
  if (cmd === 'cred') {
@@ -3237,23 +3188,15 @@ export class ChatApp {
3237
3188
  }
3238
3189
  }
3239
3190
 
3191
+ // The fallback page when the engine cannot report skills: which skills are connectable is
3192
+ // theirs to declare, so all this can offer is the command itself.
3240
3193
  _connectMenu() {
3241
3194
  return {
3242
3195
  title: 'Connections',
3243
3196
  cursor: 0,
3244
3197
  entries: [
3245
- { label: 'Connect Gmail', hint: 'OAuth Gmail', command: '/connect gmail' },
3246
- {
3247
- label: 'Connect Google Calendar',
3248
- hint: 'OAuth Calendar',
3249
- command: '/connect google-calendar'
3250
- },
3251
- { label: 'Connect Google Docs', hint: 'OAuth Docs', command: '/connect google-docs' },
3252
- { label: 'Connect Google Drive', hint: 'OAuth Drive', command: '/connect google-drive' },
3253
- { label: 'Connect Google Sheets', hint: 'OAuth Sheets', command: '/connect google-sheets' },
3254
- { label: 'Connect Spotify', hint: 'OAuth Spotify (PKCE)', command: '/connect spotify' },
3255
- { label: 'Connect Notion', hint: 'OAuth Notion MCP', command: '/connect notion' },
3256
- { label: 'Connect Asana', hint: 'OAuth Asana MCP', command: '/connect asana' }
3198
+ { label: 'Connect a skill…', hint: '/connect <skill>', prefill: '/connect ' },
3199
+ { label: 'Set a credential…', hint: '/cred <key> <value>', prefill: '/cred ' }
3257
3200
  ]
3258
3201
  }
3259
3202
  }
@@ -44,7 +44,7 @@ async function claimUniqueFile(dir, fileName, extension, source) {
44
44
  const safe = !sanitized || sanitized === '.' || sanitized === '..' ? 'download' : sanitized
45
45
  const dot = safe.lastIndexOf('.')
46
46
  const base = (dot > 0 ? safe.slice(0, dot) : safe) || 'download'
47
- const ext = extension === undefined ? (dot > 0 ? safe.slice(dot) : '') : extension
47
+ const ext = dot > 0 ? safe.slice(dot) : (extension ?? '')
48
48
 
49
49
  for (let n = 0; n < 100; n++) {
50
50
  const file = path.join(dir, `${base}${n ? `-${n + 1}` : ''}${ext}`)
@@ -1,14 +0,0 @@
1
- import type { OAuthProvider } from '../oauth/types.ts';
2
- import type { SkillSetupField } from '../skill-types.ts';
3
- export type OAuthIntegrationConfig = {
4
- readonly provider: OAuthProvider;
5
- readonly credentialKey: string;
6
- readonly label: string;
7
- readonly description: string;
8
- readonly helpUrl?: string | undefined;
9
- readonly fields?: ReadonlyArray<SkillSetupField> | undefined;
10
- readonly guide?: ReadonlyArray<string> | undefined;
11
- readonly configGuide?: ReadonlyArray<string> | undefined;
12
- };
13
- export declare const OAUTH_PROVIDERS: ReadonlyArray<OAuthIntegrationConfig>;
14
- export declare function resolveOAuthProviderByCredentialKey(credentialKey: string): OAuthIntegrationConfig | null;
@@ -1,116 +0,0 @@
1
- import { ASANA_MCP_CREDENTIAL_KEY, GMAIL_CREDENTIAL_KEY, GOOGLE_CALENDAR_CREDENTIAL_KEY, GOOGLE_DOCS_CREDENTIAL_KEY, GOOGLE_DRIVE_CREDENTIAL_KEY, GOOGLE_SHEETS_CREDENTIAL_KEY, NOTION_MCP_CREDENTIAL_KEY, SPOTIFY_CREDENTIAL_KEY } from '../oauth/keys.js';
2
- const OAUTH_CLIENT_FIELDS = [
3
- {
4
- key: 'clientId',
5
- label: 'Client ID',
6
- placeholder: 'OAuth client ID from your app'
7
- },
8
- { key: 'clientSecret', label: 'Client Secret', secret: true }
9
- ];
10
- function googleConfig(input) {
11
- return {
12
- provider: 'google',
13
- credentialKey: input.credentialKey,
14
- label: input.label,
15
- description: input.description,
16
- fields: OAUTH_CLIENT_FIELDS,
17
- guide: [
18
- `Click Connect and approve access in the browser. Approving grants ${input.grants} only.`,
19
- 'Each Google skill is connected separately, with its own app and its own approval.'
20
- ],
21
- configGuide: [
22
- `[Open Google Cloud Console](https://console.cloud.google.com/flows/enableapi?apiid=${input.api}) to enable the ${input.label} API`,
23
- '[Open OAuth clients](https://console.cloud.google.com/auth/clients) to create an OAuth client — choose "Desktop app" as the type',
24
- '[Open OAuth audience](https://console.cloud.google.com/auth/audience) and add your Google account as a test user'
25
- ]
26
- };
27
- }
28
- const GOOGLE_CONFIGS = [
29
- googleConfig({
30
- credentialKey: GMAIL_CREDENTIAL_KEY,
31
- label: 'Gmail',
32
- description: 'Read, search, send, and manage Gmail messages and labels',
33
- api: 'gmail.googleapis.com',
34
- grants: 'access to your Gmail'
35
- }),
36
- googleConfig({
37
- credentialKey: GOOGLE_CALENDAR_CREDENTIAL_KEY,
38
- label: 'Google Calendar',
39
- description: 'List, create, update, and delete Google Calendar events',
40
- api: 'calendar-json.googleapis.com',
41
- grants: 'access to your calendars'
42
- }),
43
- googleConfig({
44
- credentialKey: GOOGLE_DOCS_CREDENTIAL_KEY,
45
- label: 'Google Docs',
46
- description: 'Create, read, and edit Google Docs documents',
47
- api: 'docs.googleapis.com,drive.googleapis.com',
48
- grants: 'access to your documents and Drive files'
49
- }),
50
- googleConfig({
51
- credentialKey: GOOGLE_DRIVE_CREDENTIAL_KEY,
52
- label: 'Google Drive',
53
- description: 'Search, list, and manage Google Drive files and folders',
54
- api: 'drive.googleapis.com',
55
- grants: 'access to your Drive files'
56
- }),
57
- googleConfig({
58
- credentialKey: GOOGLE_SHEETS_CREDENTIAL_KEY,
59
- label: 'Google Sheets',
60
- description: 'Create, read, and update Google Sheets spreadsheets',
61
- api: 'sheets.googleapis.com,drive.googleapis.com',
62
- grants: 'access to your spreadsheets and Drive files'
63
- })
64
- ];
65
- const SPOTIFY_FIELDS = [
66
- {
67
- key: 'clientId',
68
- label: 'Client ID',
69
- placeholder: 'From your app at developer.spotify.com'
70
- }
71
- ];
72
- const SPOTIFY_CONFIG = {
73
- provider: 'spotify',
74
- credentialKey: SPOTIFY_CREDENTIAL_KEY,
75
- label: 'Spotify',
76
- description: 'Search, library, and playback control — playback requires Spotify Premium',
77
- helpUrl: 'https://developer.spotify.com/dashboard',
78
- fields: SPOTIFY_FIELDS,
79
- guide: [
80
- 'Search and library browsing work with any Spotify account; controlling playback (play, pause, skip) requires Spotify Premium and an open Spotify app on a device.',
81
- 'Create your own app at https://developer.spotify.com/dashboard (Spotify requires the app owner to hold a Premium subscription).',
82
- 'In the app settings, add these exact Redirect URIs: http://127.0.0.1:18974/callback (desktop) and, for mobile, the Redirect URI shown in this connect form (the scheme varies per build, e.g. qvac://oauth-callback or qvac-dev://oauth-callback).',
83
- 'Paste the Client ID above and click Connect, then approve access in the browser. No Client Secret is needed — Workbench uses PKCE.'
84
- ]
85
- };
86
- const ASANA_CONFIG = {
87
- provider: 'asana',
88
- credentialKey: ASANA_MCP_CREDENTIAL_KEY,
89
- label: 'Asana',
90
- description: 'Tasks, projects, and comments',
91
- helpUrl: 'https://app.asana.com/0/my-apps',
92
- fields: OAUTH_CLIENT_FIELDS,
93
- configGuide: [
94
- '[Open the Asana developer console](https://app.asana.com/0/my-apps) and create an MCP app',
95
- 'In OAuth settings, add the exact redirect URI shown below',
96
- 'In "Manage distribution", allow the workspace you want this connection to access'
97
- ]
98
- };
99
- const NOTION_CONFIG = {
100
- provider: 'notion',
101
- credentialKey: NOTION_MCP_CREDENTIAL_KEY,
102
- label: 'Notion',
103
- description: 'Pages, databases, and blocks',
104
- guide: [
105
- "Click Connect and approve access in the browser — Workbench uses Notion's hosted MCP OAuth, so no app credentials are needed."
106
- ]
107
- };
108
- export const OAUTH_PROVIDERS = [
109
- ...GOOGLE_CONFIGS,
110
- SPOTIFY_CONFIG,
111
- ASANA_CONFIG,
112
- NOTION_CONFIG
113
- ];
114
- export function resolveOAuthProviderByCredentialKey(credentialKey) {
115
- return OAUTH_PROVIDERS.find((config) => config.credentialKey === credentialKey) ?? null;
116
- }
@@ -1,35 +0,0 @@
1
- import { type ConfigEngine, type Fetch, type OAuthTokens } from './common.ts';
2
- export declare const ASANA_MCP_CREDENTIAL_KEY = "asana_mcp_access_token";
3
- export declare const ASANA_OAUTH_STATE_KEY = "asana_oauth";
4
- export declare const ASANA_OAUTH_PORT = 18981;
5
- export type AsanaTokens = OAuthTokens;
6
- export declare function buildAsanaAuthUrl(opts: {
7
- clientId: string;
8
- state: string;
9
- challenge: string;
10
- }): string;
11
- export declare function exchangeAsanaCode(opts: {
12
- clientId: string;
13
- clientSecret: string;
14
- code: string;
15
- verifier: string;
16
- fetch?: Fetch;
17
- }): Promise<AsanaTokens>;
18
- export declare function refreshAsanaToken(opts: {
19
- clientId: string;
20
- clientSecret: string;
21
- refreshToken: string;
22
- fetch?: Fetch;
23
- }): Promise<AsanaTokens>;
24
- export declare function connectAsana(opts: {
25
- clientId: string;
26
- clientSecret: string;
27
- openUrl: (url: string) => unknown;
28
- fetch?: Fetch;
29
- timeoutMs?: number;
30
- }): Promise<AsanaTokens>;
31
- export declare function resolveAsanaCredential(opts: {
32
- engine: ConfigEngine;
33
- agentId?: string;
34
- fetch?: Fetch;
35
- }): Promise<string | null>;
@@ -1,71 +0,0 @@
1
- import { URLSearchParams } from 'url';
2
- import defaultFetch from '#fetch';
3
- import { runBrowserConnect } from './browser-connect.js';
4
- import { oauthRedirectUri, tokenRequest } from './common.js';
5
- import { resolveOAuthCredential } from './resolve.js';
6
- export const ASANA_MCP_CREDENTIAL_KEY = 'asana_mcp_access_token';
7
- export const ASANA_OAUTH_STATE_KEY = 'asana_oauth';
8
- export const ASANA_OAUTH_PORT = 18981;
9
- const REDIRECT_URI = oauthRedirectUri(ASANA_OAUTH_PORT);
10
- const AUTH_URL = 'https://app.asana.com/-/oauth_authorize';
11
- const TOKEN_URL = 'https://app.asana.com/-/oauth_token';
12
- const MCP_RESOURCE = 'https://mcp.asana.com/v2';
13
- export function buildAsanaAuthUrl(opts) {
14
- const params = new URLSearchParams({
15
- response_type: 'code',
16
- client_id: opts.clientId,
17
- redirect_uri: REDIRECT_URI,
18
- resource: MCP_RESOURCE,
19
- state: opts.state,
20
- code_challenge: opts.challenge,
21
- code_challenge_method: 'S256'
22
- });
23
- return `${AUTH_URL}?${params.toString()}`;
24
- }
25
- export async function exchangeAsanaCode(opts) {
26
- return tokenRequest(opts.fetch ?? defaultFetch, TOKEN_URL, new URLSearchParams({
27
- grant_type: 'authorization_code',
28
- code: opts.code,
29
- redirect_uri: REDIRECT_URI,
30
- client_id: opts.clientId,
31
- client_secret: opts.clientSecret,
32
- code_verifier: opts.verifier
33
- }), 'Asana');
34
- }
35
- export async function refreshAsanaToken(opts) {
36
- const tokens = await tokenRequest(opts.fetch ?? defaultFetch, TOKEN_URL, new URLSearchParams({
37
- grant_type: 'refresh_token',
38
- refresh_token: opts.refreshToken,
39
- client_id: opts.clientId,
40
- client_secret: opts.clientSecret
41
- }), 'Asana');
42
- return { ...tokens, refreshToken: tokens.refreshToken ?? opts.refreshToken };
43
- }
44
- export async function connectAsana(opts) {
45
- return runBrowserConnect({
46
- port: ASANA_OAUTH_PORT,
47
- timeoutMs: opts.timeoutMs,
48
- openUrl: opts.openUrl,
49
- buildAuthUrl: ({ state, challenge }) => buildAsanaAuthUrl({ clientId: opts.clientId, state, challenge }),
50
- exchange: ({ code, verifier }) => exchangeAsanaCode({
51
- clientId: opts.clientId,
52
- clientSecret: opts.clientSecret,
53
- code,
54
- verifier,
55
- fetch: opts.fetch
56
- })
57
- });
58
- }
59
- export async function resolveAsanaCredential(opts) {
60
- return resolveOAuthCredential({
61
- ...opts,
62
- credentialKey: ASANA_MCP_CREDENTIAL_KEY,
63
- stateKey: ASANA_OAUTH_STATE_KEY,
64
- requireClientSecret: true,
65
- refresh: async ({ clientId, clientSecret, refreshToken, fetch }) => {
66
- if (!clientSecret)
67
- throw new Error('Asana refresh requires clientSecret');
68
- return refreshAsanaToken({ clientId, clientSecret, refreshToken, fetch });
69
- }
70
- });
71
- }
@@ -1,37 +0,0 @@
1
- import { type ConfigEngine, type Fetch, type OAuthTokens } from './common.ts';
2
- export declare const GOOGLE_OAUTH_PORT: number;
3
- export type GoogleTokens = OAuthTokens;
4
- export declare function buildGoogleAuthUrl(opts: {
5
- clientId: string;
6
- state: string;
7
- challenge: string;
8
- credentialKey: string;
9
- }): string;
10
- export declare function exchangeGoogleCode(opts: {
11
- clientId: string;
12
- clientSecret: string;
13
- code: string;
14
- verifier: string;
15
- fetch?: Fetch;
16
- }): Promise<GoogleTokens>;
17
- export declare function refreshGoogleToken(opts: {
18
- clientId: string;
19
- clientSecret: string;
20
- refreshToken: string;
21
- fetch?: Fetch;
22
- }): Promise<GoogleTokens>;
23
- export declare function connectGoogle(opts: {
24
- clientId: string;
25
- clientSecret: string;
26
- credentialKey: string;
27
- openUrl: (url: string) => unknown;
28
- fetch?: Fetch;
29
- timeoutMs?: number;
30
- }): Promise<GoogleTokens>;
31
- export declare function resolveGoogleCredential(opts: {
32
- engine: ConfigEngine;
33
- agentId?: string;
34
- fetch?: Fetch;
35
- credentialKey: string;
36
- stateKey: string;
37
- }): Promise<string | null>;