@qvac/core 0.3.1 → 0.3.3

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 (61) hide show
  1. package/README.md +4 -4
  2. package/dist-lib/lib/assistant/history.d.ts +10 -1
  3. package/dist-lib/lib/assistant/history.js +36 -1
  4. package/dist-lib/lib/assistant/message.d.ts +2 -0
  5. package/dist-lib/lib/assistant/message.js +11 -0
  6. package/dist-lib/lib/assistant/skill-encode.js +27 -1
  7. package/dist-lib/lib/assistant.d.ts +5 -2
  8. package/dist-lib/lib/assistant.js +41 -8
  9. package/dist-lib/lib/core/chat-activity.js +2 -8
  10. package/dist-lib/lib/core/skill-secrets.js +3 -6
  11. package/dist-lib/lib/core.d.ts +1 -0
  12. package/dist-lib/lib/core.js +51 -9
  13. package/dist-lib/lib/credential-pusher.d.ts +2 -3
  14. package/dist-lib/lib/credential-pusher.js +67 -39
  15. package/dist-lib/lib/integrations/index.d.ts +1 -2
  16. package/dist-lib/lib/integrations/index.js +0 -1
  17. package/dist-lib/lib/integrations/setup-routes.js +0 -15
  18. package/dist-lib/lib/oauth/flow-core.js +1 -1
  19. package/dist-lib/lib/oauth/flow.d.ts +4 -2
  20. package/dist-lib/lib/oauth/flow.js +3 -4
  21. package/dist-lib/lib/oauth/host.d.ts +3 -1
  22. package/dist-lib/lib/oauth/host.js +3 -1
  23. package/dist-lib/lib/oauth/keys.d.ts +21 -20
  24. package/dist-lib/lib/oauth/keys.js +59 -85
  25. package/dist-lib/lib/oauth/loopback.d.ts +2 -2
  26. package/dist-lib/lib/oauth/loopback.js +32 -19
  27. package/dist-lib/lib/oauth/loopback.stub.d.ts +2 -2
  28. package/dist-lib/lib/oauth/loopback.stub.js +2 -2
  29. package/dist-lib/lib/oauth/providers.d.ts +3 -5
  30. package/dist-lib/lib/oauth/providers.js +20 -67
  31. package/dist-lib/lib/oauth/redirect-types.d.ts +1 -0
  32. package/dist-lib/lib/oauth/registry.d.ts +10 -0
  33. package/dist-lib/lib/oauth/registry.js +25 -0
  34. package/dist-lib/lib/oauth/resolve.js +1 -1
  35. package/dist-lib/lib/oauth/token-exchange-core.js +2 -1
  36. package/dist-lib/lib/oauth/types.d.ts +1 -1
  37. package/dist-lib/lib/oauth.client.d.ts +3 -1
  38. package/dist-lib/lib/oauth.client.js +3 -1
  39. package/dist-lib/lib/oauth.d.ts +4 -7
  40. package/dist-lib/lib/oauth.js +4 -7
  41. package/dist-lib/lib/skill-types.d.ts +12 -0
  42. package/dist-lib/schema/engine.js +21 -1
  43. package/dist-lib/spec/hrpc/messages.js +114 -5
  44. package/dist-lib/spec/hyperschema/index.js +114 -5
  45. package/dist-lib/spec/hyperschema/schema.json +84 -1
  46. package/dist-lib/spec/hyperschema/types.d.ts +18 -1
  47. package/package.json +4 -4
  48. package/tui/app.mjs +98 -155
  49. package/tui/lib/save-file.mjs +1 -1
  50. package/dist-lib/lib/integrations/oauth-providers.d.ts +0 -14
  51. package/dist-lib/lib/integrations/oauth-providers.js +0 -116
  52. package/dist-lib/lib/oauth/asana.d.ts +0 -35
  53. package/dist-lib/lib/oauth/asana.js +0 -71
  54. package/dist-lib/lib/oauth/google.d.ts +0 -37
  55. package/dist-lib/lib/oauth/google.js +0 -77
  56. package/dist-lib/lib/oauth/notion.d.ts +0 -34
  57. package/dist-lib/lib/oauth/notion.js +0 -82
  58. package/dist-lib/lib/oauth/spotify.d.ts +0 -32
  59. package/dist-lib/lib/oauth/spotify.js +0 -74
  60. package/dist-lib/lib/oauth/verify.d.ts +0 -8
  61. package/dist-lib/lib/oauth/verify.js +0 -58
@@ -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>;
@@ -1,77 +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 { OAUTH_PROVIDER_PORTS, oauthKeySpec } from './keys.js';
6
- import { resolveOAuthCredential } from './resolve.js';
7
- export const GOOGLE_OAUTH_PORT = OAUTH_PROVIDER_PORTS.google;
8
- const REDIRECT_URI = oauthRedirectUri(GOOGLE_OAUTH_PORT);
9
- const AUTH_URL = 'https://accounts.google.com/o/oauth2/v2/auth';
10
- const TOKEN_URL = 'https://oauth2.googleapis.com/token';
11
- function scopesFor(credentialKey) {
12
- return oauthKeySpec(credentialKey)?.scopes ?? [];
13
- }
14
- export function buildGoogleAuthUrl(opts) {
15
- const params = new URLSearchParams({
16
- response_type: 'code',
17
- client_id: opts.clientId,
18
- redirect_uri: REDIRECT_URI,
19
- scope: scopesFor(opts.credentialKey).join(' '),
20
- state: opts.state,
21
- code_challenge: opts.challenge,
22
- code_challenge_method: 'S256',
23
- access_type: 'offline',
24
- prompt: 'consent'
25
- });
26
- return `${AUTH_URL}?${params.toString()}`;
27
- }
28
- export async function exchangeGoogleCode(opts) {
29
- return tokenRequest(opts.fetch ?? defaultFetch, TOKEN_URL, new URLSearchParams({
30
- grant_type: 'authorization_code',
31
- code: opts.code,
32
- redirect_uri: REDIRECT_URI,
33
- client_id: opts.clientId,
34
- client_secret: opts.clientSecret,
35
- code_verifier: opts.verifier
36
- }), 'Google');
37
- }
38
- export async function refreshGoogleToken(opts) {
39
- const tokens = await tokenRequest(opts.fetch ?? defaultFetch, TOKEN_URL, new URLSearchParams({
40
- grant_type: 'refresh_token',
41
- refresh_token: opts.refreshToken,
42
- client_id: opts.clientId,
43
- client_secret: opts.clientSecret
44
- }), 'Google');
45
- return { ...tokens, refreshToken: tokens.refreshToken ?? opts.refreshToken };
46
- }
47
- export async function connectGoogle(opts) {
48
- return runBrowserConnect({
49
- port: GOOGLE_OAUTH_PORT,
50
- timeoutMs: opts.timeoutMs,
51
- openUrl: opts.openUrl,
52
- buildAuthUrl: ({ state, challenge }) => buildGoogleAuthUrl({
53
- clientId: opts.clientId,
54
- state,
55
- challenge,
56
- credentialKey: opts.credentialKey
57
- }),
58
- exchange: ({ code, verifier }) => exchangeGoogleCode({
59
- clientId: opts.clientId,
60
- clientSecret: opts.clientSecret,
61
- code,
62
- verifier,
63
- fetch: opts.fetch
64
- })
65
- });
66
- }
67
- export async function resolveGoogleCredential(opts) {
68
- return resolveOAuthCredential({
69
- ...opts,
70
- requireClientSecret: true,
71
- refresh: async ({ clientId, clientSecret, refreshToken, fetch }) => {
72
- if (!clientSecret)
73
- throw new Error('Google refresh requires clientSecret');
74
- return refreshGoogleToken({ clientId, clientSecret, refreshToken, fetch });
75
- }
76
- });
77
- }
@@ -1,34 +0,0 @@
1
- import { type ConfigEngine, type Fetch, type OAuthTokens } from './common.ts';
2
- export declare const NOTION_MCP_CREDENTIAL_KEY = "notion_mcp_access_token";
3
- export declare const NOTION_OAUTH_STATE_KEY = "notion_oauth";
4
- export declare const NOTION_OAUTH_PORT = 18982;
5
- export type NotionTokens = OAuthTokens;
6
- export declare function registerNotionClient(fetchImpl?: Fetch): Promise<string>;
7
- export declare function buildNotionAuthUrl(opts: {
8
- clientId: string;
9
- state: string;
10
- challenge: string;
11
- }): string;
12
- export declare function exchangeNotionCode(opts: {
13
- clientId: string;
14
- code: string;
15
- verifier: string;
16
- fetch?: Fetch;
17
- }): Promise<NotionTokens>;
18
- export declare function refreshNotionToken(opts: {
19
- clientId: string;
20
- refreshToken: string;
21
- fetch?: Fetch;
22
- }): Promise<NotionTokens>;
23
- export declare function connectNotion(opts: {
24
- openUrl: (url: string) => unknown;
25
- fetch?: Fetch;
26
- timeoutMs?: number;
27
- }): Promise<NotionTokens & {
28
- clientId: string;
29
- }>;
30
- export declare function resolveNotionCredential(opts: {
31
- engine: ConfigEngine;
32
- agentId?: string;
33
- fetch?: Fetch;
34
- }): Promise<string | null>;
@@ -1,82 +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 NOTION_MCP_CREDENTIAL_KEY = 'notion_mcp_access_token';
7
- export const NOTION_OAUTH_STATE_KEY = 'notion_oauth';
8
- export const NOTION_OAUTH_PORT = 18982;
9
- const REDIRECT_URI = oauthRedirectUri(NOTION_OAUTH_PORT);
10
- const AUTH_URL = 'https://mcp.notion.com/authorize';
11
- const TOKEN_URL = 'https://mcp.notion.com/token';
12
- const REGISTER_URL = 'https://mcp.notion.com/register';
13
- export async function registerNotionClient(fetchImpl = defaultFetch) {
14
- const response = await fetchImpl(REGISTER_URL, {
15
- method: 'POST',
16
- headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
17
- body: JSON.stringify({
18
- client_name: 'QV.AC assistant',
19
- redirect_uris: [REDIRECT_URI],
20
- token_endpoint_auth_method: 'none',
21
- grant_types: ['authorization_code', 'refresh_token'],
22
- response_types: ['code']
23
- })
24
- });
25
- if (!response.ok) {
26
- const text = await response.text().catch(() => '');
27
- throw new Error(`Notion client registration failed (${response.status}): ${text.slice(0, 256)}`);
28
- }
29
- const raw = (await response.json());
30
- if (!raw.client_id)
31
- throw new Error('Notion registration returned no client_id');
32
- return raw.client_id;
33
- }
34
- export function buildNotionAuthUrl(opts) {
35
- const params = new URLSearchParams({
36
- response_type: 'code',
37
- client_id: opts.clientId,
38
- redirect_uri: REDIRECT_URI,
39
- state: opts.state,
40
- code_challenge: opts.challenge,
41
- code_challenge_method: 'S256'
42
- });
43
- return `${AUTH_URL}?${params.toString()}`;
44
- }
45
- export async function exchangeNotionCode(opts) {
46
- return tokenRequest(opts.fetch ?? defaultFetch, TOKEN_URL, new URLSearchParams({
47
- grant_type: 'authorization_code',
48
- code: opts.code,
49
- redirect_uri: REDIRECT_URI,
50
- client_id: opts.clientId,
51
- code_verifier: opts.verifier
52
- }), 'Notion');
53
- }
54
- export async function refreshNotionToken(opts) {
55
- const tokens = await tokenRequest(opts.fetch ?? defaultFetch, TOKEN_URL, new URLSearchParams({
56
- grant_type: 'refresh_token',
57
- refresh_token: opts.refreshToken,
58
- client_id: opts.clientId
59
- }), 'Notion');
60
- return { ...tokens, refreshToken: tokens.refreshToken ?? opts.refreshToken };
61
- }
62
- export async function connectNotion(opts) {
63
- const fetch = opts.fetch ?? defaultFetch;
64
- const clientId = await registerNotionClient(fetch);
65
- const tokens = await runBrowserConnect({
66
- port: NOTION_OAUTH_PORT,
67
- timeoutMs: opts.timeoutMs,
68
- openUrl: opts.openUrl,
69
- buildAuthUrl: ({ state, challenge }) => buildNotionAuthUrl({ clientId, state, challenge }),
70
- exchange: ({ code, verifier }) => exchangeNotionCode({ clientId, code, verifier, fetch })
71
- });
72
- return { ...tokens, clientId };
73
- }
74
- export async function resolveNotionCredential(opts) {
75
- return resolveOAuthCredential({
76
- ...opts,
77
- credentialKey: NOTION_MCP_CREDENTIAL_KEY,
78
- stateKey: NOTION_OAUTH_STATE_KEY,
79
- requireClientSecret: false,
80
- refresh: async ({ clientId, refreshToken, fetch }) => refreshNotionToken({ clientId, refreshToken, fetch })
81
- });
82
- }
@@ -1,32 +0,0 @@
1
- import { type ConfigEngine, type Fetch, type OAuthTokens } from './common.ts';
2
- export declare const SPOTIFY_CREDENTIAL_KEY = "spotify_access_token";
3
- export declare const SPOTIFY_OAUTH_STATE_KEY = "spotify_oauth";
4
- export declare const SPOTIFY_OAUTH_PORT = 18974;
5
- export type SpotifyTokens = OAuthTokens;
6
- export declare function buildSpotifyAuthUrl(opts: {
7
- clientId: string;
8
- state: string;
9
- challenge: string;
10
- }): string;
11
- export declare function exchangeSpotifyCode(opts: {
12
- clientId: string;
13
- code: string;
14
- verifier: string;
15
- fetch?: Fetch;
16
- }): Promise<SpotifyTokens>;
17
- export declare function refreshSpotifyToken(opts: {
18
- clientId: string;
19
- refreshToken: string;
20
- fetch?: Fetch;
21
- }): Promise<SpotifyTokens>;
22
- export declare function connectSpotify(opts: {
23
- clientId: string;
24
- openUrl: (url: string) => unknown;
25
- fetch?: Fetch;
26
- timeoutMs?: number;
27
- }): Promise<SpotifyTokens>;
28
- export declare function resolveSpotifyCredential(opts: {
29
- engine: ConfigEngine;
30
- agentId?: string;
31
- fetch?: Fetch;
32
- }): Promise<string | null>;
@@ -1,74 +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 SPOTIFY_CREDENTIAL_KEY = 'spotify_access_token';
7
- export const SPOTIFY_OAUTH_STATE_KEY = 'spotify_oauth';
8
- export const SPOTIFY_OAUTH_PORT = 18974;
9
- const REDIRECT_URI = oauthRedirectUri(SPOTIFY_OAUTH_PORT);
10
- const AUTH_URL = 'https://accounts.spotify.com/authorize';
11
- const TOKEN_URL = 'https://accounts.spotify.com/api/token';
12
- const SCOPES = [
13
- 'user-read-private',
14
- 'user-read-playback-state',
15
- 'user-modify-playback-state',
16
- 'user-read-currently-playing',
17
- 'playlist-read-private',
18
- 'playlist-read-collaborative',
19
- 'user-library-read',
20
- 'user-top-read',
21
- 'user-read-recently-played'
22
- ];
23
- export function buildSpotifyAuthUrl(opts) {
24
- const params = new URLSearchParams({
25
- response_type: 'code',
26
- client_id: opts.clientId,
27
- redirect_uri: REDIRECT_URI,
28
- scope: SCOPES.join(' '),
29
- state: opts.state,
30
- code_challenge: opts.challenge,
31
- code_challenge_method: 'S256'
32
- });
33
- return `${AUTH_URL}?${params.toString()}`;
34
- }
35
- export async function exchangeSpotifyCode(opts) {
36
- return tokenRequest(opts.fetch ?? defaultFetch, TOKEN_URL, new URLSearchParams({
37
- grant_type: 'authorization_code',
38
- code: opts.code,
39
- redirect_uri: REDIRECT_URI,
40
- client_id: opts.clientId,
41
- code_verifier: opts.verifier
42
- }), 'Spotify');
43
- }
44
- export async function refreshSpotifyToken(opts) {
45
- const tokens = await tokenRequest(opts.fetch ?? defaultFetch, TOKEN_URL, new URLSearchParams({
46
- grant_type: 'refresh_token',
47
- refresh_token: opts.refreshToken,
48
- client_id: opts.clientId
49
- }), 'Spotify');
50
- return { ...tokens, refreshToken: tokens.refreshToken ?? opts.refreshToken };
51
- }
52
- export async function connectSpotify(opts) {
53
- return runBrowserConnect({
54
- port: SPOTIFY_OAUTH_PORT,
55
- timeoutMs: opts.timeoutMs,
56
- openUrl: opts.openUrl,
57
- buildAuthUrl: ({ state, challenge }) => buildSpotifyAuthUrl({ clientId: opts.clientId, state, challenge }),
58
- exchange: ({ code, verifier }) => exchangeSpotifyCode({
59
- clientId: opts.clientId,
60
- code,
61
- verifier,
62
- fetch: opts.fetch
63
- })
64
- });
65
- }
66
- export async function resolveSpotifyCredential(opts) {
67
- return resolveOAuthCredential({
68
- ...opts,
69
- credentialKey: SPOTIFY_CREDENTIAL_KEY,
70
- stateKey: SPOTIFY_OAUTH_STATE_KEY,
71
- requireClientSecret: false,
72
- refresh: async ({ clientId, refreshToken, fetch }) => refreshSpotifyToken({ clientId, refreshToken, fetch })
73
- });
74
- }
@@ -1,8 +0,0 @@
1
- import type { Fetch } from './common.ts';
2
- export type VerifyResult = {
3
- ok: true;
4
- } | {
5
- ok: false;
6
- error: string;
7
- };
8
- export declare function verifyOAuthTokens(credentialKey: string, accessToken: string, fetch: Fetch): Promise<VerifyResult>;
@@ -1,58 +0,0 @@
1
- import { oauthKeySpec } from './keys.js';
2
- export async function verifyOAuthTokens(credentialKey, accessToken, fetch) {
3
- const provider = oauthKeySpec(credentialKey)?.provider;
4
- if (provider !== 'asana' && provider !== 'spotify')
5
- return { ok: true };
6
- const controller = typeof globalThis.AbortController === 'function' ? new globalThis.AbortController() : null;
7
- const timer = setTimeout(() => controller?.abort(), 5_000);
8
- try {
9
- if (provider === 'asana') {
10
- const response = await fetch('https://mcp.asana.com/v2/mcp', {
11
- method: 'POST',
12
- headers: {
13
- Authorization: `Bearer ${accessToken}`,
14
- 'Content-Type': 'application/json',
15
- Accept: 'application/json, text/event-stream'
16
- },
17
- body: JSON.stringify({
18
- jsonrpc: '2.0',
19
- id: 1,
20
- method: 'initialize',
21
- params: {
22
- protocolVersion: '2025-03-26',
23
- capabilities: {},
24
- clientInfo: { name: 'qvac', version: '1.0.0' }
25
- }
26
- }),
27
- signal: controller?.signal
28
- });
29
- if (response.status === 401 || response.status === 403) {
30
- return { ok: false, error: 'OAuth error: asana_not_mcp_app' };
31
- }
32
- return { ok: true };
33
- }
34
- const response = await fetch('https://api.spotify.com/v1/me', {
35
- method: 'GET',
36
- headers: { Authorization: `Bearer ${accessToken}` },
37
- signal: controller?.signal
38
- });
39
- if (response.status === 401 || response.status === 403)
40
- return { ok: true };
41
- if (response.status < 200 || response.status >= 300)
42
- return { ok: true };
43
- try {
44
- const body = (await response.json());
45
- if (Object.prototype.hasOwnProperty.call(body, 'product') && body.product !== 'premium') {
46
- return { ok: false, error: 'OAuth error: spotify_premium_required' };
47
- }
48
- }
49
- catch { }
50
- return { ok: true };
51
- }
52
- catch {
53
- return { ok: true };
54
- }
55
- finally {
56
- clearTimeout(timer);
57
- }
58
- }