@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
@@ -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
- }