@qvac/core 0.3.0 → 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 (191) hide show
  1. package/dist-lib/lib/api/chat.d.ts +3 -1
  2. package/dist-lib/lib/api/chat.js +6 -2
  3. package/dist-lib/lib/api/index.d.ts +2 -0
  4. package/dist-lib/lib/api/index.js +3 -1
  5. package/dist-lib/lib/api/inference-calls.d.ts +18 -0
  6. package/dist-lib/lib/api/inference-calls.js +15 -0
  7. package/dist-lib/lib/api/rag.js +10 -2
  8. package/dist-lib/lib/assistant/harness.d.ts +1 -0
  9. package/dist-lib/lib/assistant/history.d.ts +10 -1
  10. package/dist-lib/lib/assistant/history.js +36 -1
  11. package/dist-lib/lib/assistant/message.d.ts +2 -0
  12. package/dist-lib/lib/assistant/message.js +11 -0
  13. package/dist-lib/lib/assistant/skill-encode.js +27 -1
  14. package/dist-lib/lib/assistant-tree.d.ts +2 -0
  15. package/dist-lib/lib/assistant-tree.js +11 -2
  16. package/dist-lib/lib/assistant.d.ts +19 -3
  17. package/dist-lib/lib/assistant.js +148 -23
  18. package/dist-lib/lib/core/chunk.js +5 -0
  19. package/dist-lib/lib/core/files/rag/build.d.ts +1 -2
  20. package/dist-lib/lib/core/files/rag/build.js +1 -2
  21. package/dist-lib/lib/core/files/rag/extract/office-collabora.d.ts +1 -1
  22. package/dist-lib/lib/core/files/rag/index.d.ts +4 -24
  23. package/dist-lib/lib/core/files/rag/index.js +3 -17
  24. package/dist-lib/lib/core/files/rag/load.d.ts +1 -2
  25. package/dist-lib/lib/core/files/rag/load.js +1 -2
  26. package/dist-lib/lib/core/files/rag/produce.d.ts +1 -1
  27. package/dist-lib/lib/core/files/rag/produce.js +1 -3
  28. package/dist-lib/lib/core/files/rag/retrieval/full-text.d.ts +1 -1
  29. package/dist-lib/lib/core/files/rag/retrieval/full-text.js +1 -4
  30. package/dist-lib/lib/core/files/rag/similarity.d.ts +5 -0
  31. package/dist-lib/lib/core/files/rag/similarity.js +6 -0
  32. package/dist-lib/lib/core/files/upload.d.ts +1 -1
  33. package/dist-lib/lib/core/inference-calls-handoff.d.ts +20 -0
  34. package/dist-lib/lib/core/inference-calls-handoff.js +37 -0
  35. package/dist-lib/lib/core/inference-calls-receiver.d.ts +14 -0
  36. package/dist-lib/lib/core/inference-calls-receiver.js +39 -0
  37. package/dist-lib/lib/core/notification.js +5 -4
  38. package/dist-lib/lib/core/skill-secrets.js +3 -6
  39. package/dist-lib/lib/core.d.ts +9 -1
  40. package/dist-lib/lib/core.js +129 -13
  41. package/dist-lib/lib/credential-pusher.d.ts +2 -3
  42. package/dist-lib/lib/credential-pusher.js +67 -39
  43. package/dist-lib/lib/inference-calls.d.ts +40 -0
  44. package/dist-lib/lib/inference-calls.js +266 -0
  45. package/dist-lib/lib/integrations/index.d.ts +1 -2
  46. package/dist-lib/lib/integrations/index.js +0 -1
  47. package/dist-lib/lib/integrations/setup-routes.js +0 -15
  48. package/dist-lib/lib/oauth/flow-core.js +1 -1
  49. package/dist-lib/lib/oauth/flow.d.ts +4 -2
  50. package/dist-lib/lib/oauth/flow.js +3 -4
  51. package/dist-lib/lib/oauth/host.d.ts +3 -1
  52. package/dist-lib/lib/oauth/host.js +3 -1
  53. package/dist-lib/lib/oauth/keys.d.ts +21 -20
  54. package/dist-lib/lib/oauth/keys.js +59 -85
  55. package/dist-lib/lib/oauth/loopback.d.ts +2 -2
  56. package/dist-lib/lib/oauth/loopback.js +32 -19
  57. package/dist-lib/lib/oauth/loopback.stub.d.ts +2 -2
  58. package/dist-lib/lib/oauth/loopback.stub.js +2 -2
  59. package/dist-lib/lib/oauth/providers.d.ts +3 -5
  60. package/dist-lib/lib/oauth/providers.js +20 -67
  61. package/dist-lib/lib/oauth/redirect-types.d.ts +1 -0
  62. package/dist-lib/lib/oauth/registry.d.ts +10 -0
  63. package/dist-lib/lib/oauth/registry.js +25 -0
  64. package/dist-lib/lib/oauth/resolve.js +1 -1
  65. package/dist-lib/lib/oauth/token-exchange-core.js +2 -1
  66. package/dist-lib/lib/oauth/types.d.ts +1 -1
  67. package/dist-lib/lib/oauth.client.d.ts +3 -1
  68. package/dist-lib/lib/oauth.client.js +3 -1
  69. package/dist-lib/lib/oauth.d.ts +4 -7
  70. package/dist-lib/lib/oauth.js +4 -7
  71. package/dist-lib/lib/skill-types.d.ts +12 -0
  72. package/dist-lib/schema/content.js +5 -1
  73. package/dist-lib/schema/engine.js +63 -2
  74. package/dist-lib/schema/qvac.js +4 -2
  75. package/dist-lib/spec/bind.js +3 -0
  76. package/dist-lib/spec/calls.js +1 -0
  77. package/dist-lib/spec/capabilities.d.ts +2 -0
  78. package/dist-lib/spec/hrpc/hrpc.json +13 -0
  79. package/dist-lib/spec/hrpc/index.js +15 -3
  80. package/dist-lib/spec/hrpc/messages.js +284 -52
  81. package/dist-lib/spec/hyperschema/index.js +284 -52
  82. package/dist-lib/spec/hyperschema/schema.json +210 -1
  83. package/dist-lib/spec/hyperschema/types.d.ts +51 -1
  84. package/dist-lib/spec/local/hyperdb/messages.js +64 -128
  85. package/dist-lib/spec/local/hyperschema/index.js +32 -64
  86. package/dist-lib/spec/local/hyperschema/schema.json +16 -0
  87. package/dist-lib/spec/mesh/hyperdb/messages.js +176 -311
  88. package/dist-lib/spec/mesh/hyperdispatch/messages.js +132 -236
  89. package/dist-lib/spec/mesh/hyperschema/index.js +132 -236
  90. package/dist-lib/spec/mesh/hyperschema/schema.json +70 -1
  91. package/dist-lib/spec/mesh/hyperschema/types.d.ts +3 -1
  92. package/package.json +15 -18
  93. package/tui/app.mjs +98 -155
  94. package/tui/lib/knowledge-import.mjs +1 -1
  95. package/tui/lib/save-file.mjs +1 -1
  96. package/.claude/skills/asana/SKILL.md +0 -86
  97. package/.claude/skills/compaction/SKILL.md +0 -136
  98. package/.claude/skills/device-mesh-debug/SKILL.md +0 -328
  99. package/.claude/skills/gh-stack/SKILL.md +0 -181
  100. package/.claude/skills/gh-stack/references/commands.md +0 -177
  101. package/.claude/skills/gh-stack/references/stack-design.md +0 -97
  102. package/.claude/skills/gh-stack/references/troubleshooting.md +0 -159
  103. package/.claude/skills/js-house-style/SKILL.md +0 -671
  104. package/.claude/skills/pr-create/SKILL.md +0 -243
  105. package/.claude/skills/pr-review/SKILL.md +0 -428
  106. package/.claude/skills/release/SKILL.md +0 -122
  107. package/CLAUDE.md +0 -48
  108. package/dist-lib/lib/core/files/rag/artifact/codec.d.ts +0 -3
  109. package/dist-lib/lib/core/files/rag/artifact/codec.js +0 -172
  110. package/dist-lib/lib/core/files/rag/artifact/id.d.ts +0 -10
  111. package/dist-lib/lib/core/files/rag/artifact/id.js +0 -39
  112. package/dist-lib/lib/core/files/rag/artifact/types.d.ts +0 -24
  113. package/dist-lib/lib/core/files/rag/artifact/types.js +0 -41
  114. package/dist-lib/lib/core/files/rag/chunk/chunking.d.ts +0 -12
  115. package/dist-lib/lib/core/files/rag/chunk/chunking.js +0 -117
  116. package/dist-lib/lib/core/files/rag/chunk/metadata.d.ts +0 -30
  117. package/dist-lib/lib/core/files/rag/chunk/metadata.js +0 -89
  118. package/dist-lib/lib/core/files/rag/chunk/tokenizer.d.ts +0 -7
  119. package/dist-lib/lib/core/files/rag/chunk/tokenizer.js +0 -18
  120. package/dist-lib/lib/core/files/rag/extract/csv-text.d.ts +0 -1
  121. package/dist-lib/lib/core/files/rag/extract/csv-text.js +0 -117
  122. package/dist-lib/lib/core/files/rag/extract/document-types.d.ts +0 -22
  123. package/dist-lib/lib/core/files/rag/extract/document-types.js +0 -152
  124. package/dist-lib/lib/core/files/rag/extract/extract.d.ts +0 -17
  125. package/dist-lib/lib/core/files/rag/extract/extract.js +0 -81
  126. package/dist-lib/lib/core/files/rag/extract/html-table-text.d.ts +0 -1
  127. package/dist-lib/lib/core/files/rag/extract/html-table-text.js +0 -125
  128. package/dist-lib/lib/core/files/rag/extract/html-text.d.ts +0 -1
  129. package/dist-lib/lib/core/files/rag/extract/html-text.js +0 -132
  130. package/dist-lib/lib/core/files/rag/extract/pdf-platform.d.ts +0 -17
  131. package/dist-lib/lib/core/files/rag/extract/pdf-platform.js +0 -141
  132. package/dist-lib/lib/core/files/rag/extract/pdf-text.d.ts +0 -12
  133. package/dist-lib/lib/core/files/rag/extract/pdf-text.js +0 -43
  134. package/dist-lib/lib/core/files/rag/extract/rtf-text.d.ts +0 -1
  135. package/dist-lib/lib/core/files/rag/extract/rtf-text.js +0 -15
  136. package/dist-lib/lib/core/files/rag/extract/text-decoding.d.ts +0 -1
  137. package/dist-lib/lib/core/files/rag/extract/text-decoding.js +0 -91
  138. package/dist-lib/lib/core/files/rag/extract/types.d.ts +0 -36
  139. package/dist-lib/lib/core/files/rag/extract/types.js +0 -12
  140. package/dist-lib/lib/core/files/rag/extract/utf.d.ts +0 -2
  141. package/dist-lib/lib/core/files/rag/extract/utf.js +0 -18
  142. package/dist-lib/lib/core/files/rag/retrieval/citation-match.d.ts +0 -2
  143. package/dist-lib/lib/core/files/rag/retrieval/citation-match.js +0 -16
  144. package/dist-lib/lib/core/files/rag/retrieval/coverage.d.ts +0 -4
  145. package/dist-lib/lib/core/files/rag/retrieval/coverage.js +0 -48
  146. package/dist-lib/lib/core/files/rag/retrieval/diversity.d.ts +0 -10
  147. package/dist-lib/lib/core/files/rag/retrieval/diversity.js +0 -37
  148. package/dist-lib/lib/core/files/rag/retrieval/floor.d.ts +0 -5
  149. package/dist-lib/lib/core/files/rag/retrieval/floor.js +0 -21
  150. package/dist-lib/lib/core/files/rag/retrieval/format.d.ts +0 -6
  151. package/dist-lib/lib/core/files/rag/retrieval/format.js +0 -21
  152. package/dist-lib/lib/core/files/rag/retrieval/knowledge.d.ts +0 -2
  153. package/dist-lib/lib/core/files/rag/retrieval/knowledge.js +0 -54
  154. package/dist-lib/lib/core/files/rag/retrieval/notices.d.ts +0 -16
  155. package/dist-lib/lib/core/files/rag/retrieval/notices.js +0 -27
  156. package/dist-lib/lib/core/files/rag/retrieval/scoring.d.ts +0 -8
  157. package/dist-lib/lib/core/files/rag/retrieval/scoring.js +0 -82
  158. package/dist-lib/lib/core/files/rag/retrieval/search.d.ts +0 -3
  159. package/dist-lib/lib/core/files/rag/retrieval/search.js +0 -49
  160. package/dist-lib/lib/core/files/rag/retrieval/selection.d.ts +0 -11
  161. package/dist-lib/lib/core/files/rag/retrieval/selection.js +0 -93
  162. package/dist-lib/lib/core/files/rag/retrieval/source-tag-filter.d.ts +0 -6
  163. package/dist-lib/lib/core/files/rag/retrieval/source-tag-filter.js +0 -79
  164. package/dist-lib/lib/core/files/rag/retrieval/sources.d.ts +0 -13
  165. package/dist-lib/lib/core/files/rag/retrieval/sources.js +0 -20
  166. package/dist-lib/lib/core/files/rag/retrieval/target.d.ts +0 -13
  167. package/dist-lib/lib/core/files/rag/retrieval/target.js +0 -89
  168. package/dist-lib/lib/core/files/rag/retrieval/terms.d.ts +0 -8
  169. package/dist-lib/lib/core/files/rag/retrieval/terms.js +0 -70
  170. package/dist-lib/lib/core/files/rag/retrieval/types.d.ts +0 -29
  171. package/dist-lib/lib/core/files/rag/retrieval/types.js +0 -1
  172. package/dist-lib/lib/core/files/rag/retrieval/web-sources.d.ts +0 -8
  173. package/dist-lib/lib/core/files/rag/retrieval/web-sources.js +0 -41
  174. package/dist-lib/lib/core/files/rag/retrieval/whole-document-query.d.ts +0 -1
  175. package/dist-lib/lib/core/files/rag/retrieval/whole-document-query.js +0 -96
  176. package/dist-lib/lib/core/files/rag/vector/memory.d.ts +0 -15
  177. package/dist-lib/lib/core/files/rag/vector/memory.js +0 -135
  178. package/dist-lib/lib/core/files/rag/vector/types.d.ts +0 -28
  179. package/dist-lib/lib/core/files/rag/vector/types.js +0 -1
  180. package/dist-lib/lib/integrations/oauth-providers.d.ts +0 -14
  181. package/dist-lib/lib/integrations/oauth-providers.js +0 -116
  182. package/dist-lib/lib/oauth/asana.d.ts +0 -35
  183. package/dist-lib/lib/oauth/asana.js +0 -71
  184. package/dist-lib/lib/oauth/google.d.ts +0 -37
  185. package/dist-lib/lib/oauth/google.js +0 -77
  186. package/dist-lib/lib/oauth/notion.d.ts +0 -34
  187. package/dist-lib/lib/oauth/notion.js +0 -82
  188. package/dist-lib/lib/oauth/spotify.d.ts +0 -32
  189. package/dist-lib/lib/oauth/spotify.js +0 -74
  190. package/dist-lib/lib/oauth/verify.d.ts +0 -8
  191. package/dist-lib/lib/oauth/verify.js +0 -58
@@ -1,95 +1,69 @@
1
1
  export function scopedKey(agentId, key) {
2
2
  return agentId ? `skills.${agentId}.${key}` : `skills.${key}`;
3
3
  }
4
- export const GMAIL_CREDENTIAL_KEY = 'gmail_access_token';
5
- export const GOOGLE_CALENDAR_CREDENTIAL_KEY = 'google_calendar_access_token';
6
- export const GOOGLE_DOCS_CREDENTIAL_KEY = 'google_docs_access_token';
7
- export const GOOGLE_DRIVE_CREDENTIAL_KEY = 'google_drive_access_token';
8
- export const GOOGLE_SHEETS_CREDENTIAL_KEY = 'google_sheets_access_token';
9
- export const SPOTIFY_CREDENTIAL_KEY = 'spotify_access_token';
10
- export const ASANA_MCP_CREDENTIAL_KEY = 'asana_mcp_access_token';
11
- export const NOTION_MCP_CREDENTIAL_KEY = 'notion_mcp_access_token';
12
- export const LEGACY_GOOGLE_CREDENTIAL_KEY = 'google_workspace_access_token';
13
- const DRIVE_SCOPE = 'https://www.googleapis.com/auth/drive';
14
- export const OAUTH_KEY_SPECS = [
15
- {
16
- credentialKey: GMAIL_CREDENTIAL_KEY,
17
- stateKey: 'gmail_oauth',
18
- provider: 'google',
19
- scopes: ['https://www.googleapis.com/auth/gmail.modify']
20
- },
21
- {
22
- credentialKey: GOOGLE_CALENDAR_CREDENTIAL_KEY,
23
- stateKey: 'google_calendar_oauth',
24
- provider: 'google',
25
- scopes: ['https://www.googleapis.com/auth/calendar']
26
- },
27
- {
28
- credentialKey: GOOGLE_DOCS_CREDENTIAL_KEY,
29
- stateKey: 'google_docs_oauth',
30
- provider: 'google',
31
- scopes: ['https://www.googleapis.com/auth/documents', DRIVE_SCOPE]
32
- },
33
- {
34
- credentialKey: GOOGLE_DRIVE_CREDENTIAL_KEY,
35
- stateKey: 'google_drive_oauth',
36
- provider: 'google',
37
- scopes: [DRIVE_SCOPE]
38
- },
39
- {
40
- credentialKey: GOOGLE_SHEETS_CREDENTIAL_KEY,
41
- stateKey: 'google_sheets_oauth',
42
- provider: 'google',
43
- scopes: ['https://www.googleapis.com/auth/spreadsheets', DRIVE_SCOPE]
44
- },
45
- {
46
- credentialKey: SPOTIFY_CREDENTIAL_KEY,
47
- stateKey: 'spotify_oauth',
48
- provider: 'spotify',
49
- scopes: [
50
- 'user-read-private',
51
- 'user-read-playback-state',
52
- 'user-modify-playback-state',
53
- 'user-read-currently-playing',
54
- 'playlist-read-private',
55
- 'playlist-read-collaborative',
56
- 'user-library-read',
57
- 'user-top-read',
58
- 'user-read-recently-played'
59
- ]
60
- },
61
- {
62
- credentialKey: ASANA_MCP_CREDENTIAL_KEY,
63
- stateKey: 'asana_oauth',
64
- provider: 'asana',
65
- scopes: []
66
- },
67
- {
68
- credentialKey: NOTION_MCP_CREDENTIAL_KEY,
69
- stateKey: 'notion_oauth',
70
- provider: 'notion',
71
- scopes: []
4
+ const TOKEN_AUTH = ['pkce-only', 'secret-in-body', 'secret-in-basic'];
5
+ function tokenAuthOf(value) {
6
+ return TOKEN_AUTH.find((candidate) => candidate === value) ?? null;
7
+ }
8
+ function httpsUrl(value) {
9
+ if (!value)
10
+ return null;
11
+ try {
12
+ return new URL(value).protocol === 'https:' ? value : null;
13
+ }
14
+ catch {
15
+ return null;
72
16
  }
73
- ];
74
- export function oauthKeySpec(credentialKey) {
75
- return OAUTH_KEY_SPECS.find((spec) => spec.credentialKey === credentialKey) ?? null;
76
17
  }
77
- export function oauthStateKeyFor(credentialKey) {
78
- return oauthKeySpec(credentialKey)?.stateKey ?? null;
18
+ function portOf(value) {
19
+ if (value === undefined || value === null)
20
+ return null;
21
+ return Number.isInteger(value) && value >= 0 && value <= 65535
22
+ ? value
23
+ : null;
24
+ }
25
+ export function specFromRoute(route) {
26
+ const oauth = route.oauth;
27
+ if (!oauth)
28
+ return null;
29
+ const tokenAuth = tokenAuthOf(oauth.tokenAuth);
30
+ const authUrl = httpsUrl(oauth.authUrl);
31
+ const tokenUrl = httpsUrl(oauth.tokenUrl);
32
+ if (!route.credentialKey || !oauth.stateKey || !authUrl || !tokenUrl || !tokenAuth)
33
+ return null;
34
+ if (oauth.stateKey === route.credentialKey)
35
+ return null;
36
+ if (oauth.port !== undefined && oauth.port !== null && portOf(oauth.port) === null)
37
+ return null;
38
+ if (oauth.registrationEndpoint && !httpsUrl(oauth.registrationEndpoint))
39
+ return null;
40
+ if (oauth.registrationEndpoint && tokenAuth !== 'pkce-only')
41
+ return null;
42
+ const extraParams = stringRecord(oauth.extraAuthParams);
43
+ const port = portOf(oauth.port);
44
+ return {
45
+ credentialKey: route.credentialKey,
46
+ provider: route.provider ?? route.credentialKey,
47
+ stateKey: oauth.stateKey,
48
+ authUrl,
49
+ tokenUrl,
50
+ tokenAuth,
51
+ scopes: stringList(oauth.scopes),
52
+ ...(extraParams ? { extraAuthParams: extraParams } : {}),
53
+ ...(oauth.registrationEndpoint ? { registrationEndpoint: oauth.registrationEndpoint } : {}),
54
+ ...(port !== null ? { port } : {}),
55
+ ...(oauth.sharedIosSession === true ? { sharedIosSession: true } : {})
56
+ };
57
+ }
58
+ function stringRecord(value) {
59
+ if (!value || typeof value !== 'object' || Array.isArray(value))
60
+ return null;
61
+ const entries = Object.entries(value).filter(([, item]) => typeof item === 'string');
62
+ return entries.length > 0 ? Object.fromEntries(entries) : null;
79
63
  }
80
- export function defaultCredentialKeyFor(provider) {
81
- const spec = OAUTH_KEY_SPECS.find((candidate) => candidate.provider === provider);
82
- if (!spec)
83
- throw new Error(`Unknown OAuth provider: ${String(provider)}`);
84
- return spec.credentialKey;
64
+ function stringList(value) {
65
+ return Array.isArray(value) ? value.filter((item) => typeof item === 'string') : [];
85
66
  }
86
- export const GOOGLE_CREDENTIAL_KEYS = OAUTH_KEY_SPECS.filter((spec) => spec.provider === 'google').map((spec) => spec.credentialKey);
87
- export const OAUTH_PROVIDER_PORTS = {
88
- google: 18978,
89
- spotify: 18974,
90
- asana: 18981,
91
- notion: 18982
92
- };
93
67
  export const OAUTH_CALLBACK_PATH = '/callback';
94
68
  export const OAUTH_WAIT_FOR_CODE_TIMEOUT_MS = 120_000;
95
69
  export function oauthRedirectUri(port) {
@@ -1,3 +1,3 @@
1
1
  import type { OAuthLoopbackServer } from './redirect-types.ts';
2
- export declare function abortOAuthLoopback(port: number): Promise<boolean>;
3
- export declare function startOAuthLoopback(port: number): Promise<OAuthLoopbackServer>;
2
+ export declare function abortOAuthLoopback(credentialKey: string): Promise<boolean>;
3
+ export declare function startOAuthLoopback(port: number, credentialKey: string): Promise<OAuthLoopbackServer>;
@@ -1,6 +1,6 @@
1
1
  import { createServer } from 'http';
2
2
  import { OAUTH_CALLBACK_PATH, OAUTH_WAIT_FOR_CODE_TIMEOUT_MS, oauthRedirectUri } from './keys.js';
3
- const activeLoopbacks = new Map();
3
+ const activeLoopbacks = new Set();
4
4
  function closeServer(server) {
5
5
  return new Promise((resolve) => {
6
6
  if (!server.listening) {
@@ -11,17 +11,23 @@ function closeServer(server) {
11
11
  server.close(() => resolve());
12
12
  });
13
13
  }
14
- export async function abortOAuthLoopback(port) {
15
- const handle = activeLoopbacks.get(port);
16
- if (!handle)
17
- return false;
18
- await handle.abort(new Error('OAuth flow cancelled'));
19
- return true;
14
+ async function abortMatching(matches, reason) {
15
+ await Promise.all(matches.map((handle) => handle.abort(reason)));
16
+ return matches.length > 0;
20
17
  }
21
- export async function startOAuthLoopback(port) {
22
- const stale = activeLoopbacks.get(port);
23
- if (stale) {
24
- await stale.abort(new Error('OAuth loopback superseded by a new connect attempt'));
18
+ function abortFor(credentialKey, reason) {
19
+ return abortMatching([...activeLoopbacks].filter((handle) => handle.credentialKey === credentialKey), reason);
20
+ }
21
+ export function abortOAuthLoopback(credentialKey) {
22
+ return abortFor(credentialKey, new Error('OAuth flow cancelled'));
23
+ }
24
+ export async function startOAuthLoopback(port, credentialKey) {
25
+ if (!Number.isInteger(port) || port < 0 || port > 65535) {
26
+ throw new Error(`OAuth loopback port must be an integer in [0, 65535], got ${port}`);
27
+ }
28
+ await abortFor(credentialKey, new Error('OAuth loopback superseded by a new connect attempt'));
29
+ if (port !== 0) {
30
+ await abortMatching([...activeLoopbacks].filter((handle) => handle.port === port), new Error('OAuth loopback superseded by a new connect attempt on the same port'));
25
31
  }
26
32
  let resolveCode = null;
27
33
  let rejectCode = null;
@@ -46,7 +52,7 @@ export async function startOAuthLoopback(port) {
46
52
  reject?.(new Error('OAuth callback missing code or state'));
47
53
  };
48
54
  const server = createServer((request, response) => {
49
- const url = new URL(request.url ?? '/', `http://127.0.0.1:${port}`);
55
+ const url = new URL(request.url ?? '/', 'http://127.0.0.1');
50
56
  if (url.pathname !== OAUTH_CALLBACK_PATH) {
51
57
  response.writeHead(404, { 'Content-Type': 'text/plain' });
52
58
  response.end('Not found');
@@ -74,27 +80,34 @@ export async function startOAuthLoopback(port) {
74
80
  return;
75
81
  listenSettled = true;
76
82
  server.removeListener('listening', onListening);
77
- reject(error);
83
+ reject(error.code === 'EADDRINUSE'
84
+ ? new Error(`OAuth loopback port ${port} is already in use by another process`)
85
+ : error);
78
86
  };
79
87
  const onListening = () => {
80
88
  if (listenSettled)
81
89
  return;
82
90
  listenSettled = true;
83
91
  server.removeListener('error', onError);
92
+ const address = server.address();
93
+ if (typeof address !== 'object' || !address) {
94
+ server.close();
95
+ reject(new Error('OAuth loopback bound to no address'));
96
+ return;
97
+ }
84
98
  const handle = {
99
+ credentialKey,
100
+ port: address.port,
85
101
  abort: (reason) => {
86
102
  abortedReason = reason;
87
103
  rejectWaiter(reason);
88
104
  return closeServer(server);
89
105
  }
90
106
  };
91
- activeLoopbacks.set(port, handle);
92
- server.once('close', () => {
93
- if (activeLoopbacks.get(port) === handle)
94
- activeLoopbacks.delete(port);
95
- });
107
+ activeLoopbacks.add(handle);
108
+ server.once('close', () => activeLoopbacks.delete(handle));
96
109
  resolve({
97
- redirectUri: oauthRedirectUri(port),
110
+ redirectUri: oauthRedirectUri(address.port),
98
111
  waitForCode(timeoutMs = OAUTH_WAIT_FOR_CODE_TIMEOUT_MS, expected) {
99
112
  if (abortedReason)
100
113
  throw abortedReason;
@@ -1,3 +1,3 @@
1
1
  import type { OAuthLoopbackServer } from './redirect-types.ts';
2
- export declare function abortOAuthLoopback(_port: number): Promise<boolean>;
3
- export declare function startOAuthLoopback(_port: number): Promise<OAuthLoopbackServer>;
2
+ export declare function abortOAuthLoopback(_credentialKey: string): Promise<boolean>;
3
+ export declare function startOAuthLoopback(_port: number, _credentialKey: string): Promise<OAuthLoopbackServer>;
@@ -1,6 +1,6 @@
1
- export function abortOAuthLoopback(_port) {
1
+ export function abortOAuthLoopback(_credentialKey) {
2
2
  return Promise.resolve(false);
3
3
  }
4
- export function startOAuthLoopback(_port) {
4
+ export function startOAuthLoopback(_port, _credentialKey) {
5
5
  return Promise.reject(new Error('OAuth loopback is unavailable in this runtime; inject createRedirect instead'));
6
6
  }
@@ -1,5 +1,3 @@
1
- import type { OAuthCredentials, OAuthProvider, OAuthProviderConfig } from './types.ts';
2
- export declare function providerRequiresSecret(provider: OAuthProvider): boolean;
3
- export declare function providerSupportsDcr(provider: OAuthProvider): boolean;
4
- export declare function providerSupportsSharedIosSession(provider: OAuthProvider): boolean;
5
- export declare function buildProviderConfig(credentialKey: string, credentials: OAuthCredentials): OAuthProviderConfig;
1
+ import type { OAuthKeySpec } from './keys.ts';
2
+ import type { OAuthCredentials, OAuthProviderConfig } from './types.ts';
3
+ export declare function buildProviderConfig(spec: OAuthKeySpec, credentials: OAuthCredentials): OAuthProviderConfig;
@@ -1,70 +1,23 @@
1
- import { OAUTH_PROVIDER_PORTS, oauthKeySpec } from './keys.js';
2
- const ASANA_MCP_RESOURCE = 'https://mcp.asana.com/v2';
3
- export function providerRequiresSecret(provider) {
4
- return provider === 'google' || provider === 'asana';
5
- }
6
- export function providerSupportsDcr(provider) {
7
- return provider === 'notion';
8
- }
9
- export function providerSupportsSharedIosSession(provider) {
10
- return provider === 'spotify' || provider === 'notion';
11
- }
12
- export function buildProviderConfig(credentialKey, credentials) {
13
- const spec = oauthKeySpec(credentialKey);
14
- if (!spec)
15
- throw new Error(`Unknown OAuth credential key: ${credentialKey}`);
16
- const { provider } = spec;
17
- if (provider === 'google') {
18
- return {
19
- clientId: credentials.clientId,
20
- clientSecret: requireSecret(credentials.clientSecret, provider),
21
- tokenAuth: 'secret-in-body',
22
- authUrl: 'https://accounts.google.com/o/oauth2/v2/auth',
23
- tokenUrl: 'https://oauth2.googleapis.com/token',
24
- scopes: spec.scopes,
25
- credentialKey: spec.credentialKey,
26
- port: OAUTH_PROVIDER_PORTS[provider],
27
- extraAuthParams: { access_type: 'offline', prompt: 'consent' }
28
- };
29
- }
30
- if (provider === 'spotify') {
31
- return {
32
- clientId: credentials.clientId,
33
- tokenAuth: 'pkce-only',
34
- authUrl: 'https://accounts.spotify.com/authorize',
35
- tokenUrl: 'https://accounts.spotify.com/api/token',
36
- scopes: spec.scopes,
37
- credentialKey: spec.credentialKey,
38
- port: OAUTH_PROVIDER_PORTS[provider]
39
- };
40
- }
41
- if (provider === 'asana') {
42
- return {
43
- clientId: credentials.clientId,
44
- clientSecret: requireSecret(credentials.clientSecret, provider),
45
- tokenAuth: 'secret-in-body',
46
- authUrl: 'https://app.asana.com/-/oauth_authorize',
47
- tokenUrl: 'https://app.asana.com/-/oauth_token',
48
- scopes: spec.scopes,
49
- credentialKey: spec.credentialKey,
50
- port: OAUTH_PROVIDER_PORTS[provider],
51
- extraAuthParams: { resource: ASANA_MCP_RESOURCE }
52
- };
53
- }
54
- if (provider === 'notion') {
55
- return {
56
- clientId: credentials.clientId,
57
- tokenAuth: 'pkce-only',
58
- authUrl: 'https://mcp.notion.com/authorize',
59
- tokenUrl: 'https://mcp.notion.com/token',
60
- registrationEndpoint: 'https://mcp.notion.com/register',
61
- dynamicRegistration: true,
62
- scopes: spec.scopes,
63
- credentialKey: spec.credentialKey,
64
- port: OAUTH_PROVIDER_PORTS[provider]
65
- };
66
- }
67
- throw new Error(`Unknown OAuth provider: ${String(provider)}`);
1
+ export function buildProviderConfig(spec, credentials) {
2
+ const base = {
3
+ clientId: credentials.clientId,
4
+ authUrl: spec.authUrl,
5
+ tokenUrl: spec.tokenUrl,
6
+ scopes: spec.scopes,
7
+ credentialKey: spec.credentialKey,
8
+ port: spec.port ?? 0,
9
+ ...(spec.extraAuthParams ? { extraAuthParams: spec.extraAuthParams } : {}),
10
+ ...(spec.registrationEndpoint
11
+ ? { registrationEndpoint: spec.registrationEndpoint, dynamicRegistration: true }
12
+ : {})
13
+ };
14
+ if (spec.tokenAuth === 'pkce-only')
15
+ return { ...base, tokenAuth: 'pkce-only' };
16
+ return {
17
+ ...base,
18
+ tokenAuth: spec.tokenAuth,
19
+ clientSecret: requireSecret(credentials.clientSecret, spec.provider)
20
+ };
68
21
  }
69
22
  function requireSecret(secret, provider) {
70
23
  if (!secret)
@@ -14,6 +14,7 @@ export type OAuthRedirect = {
14
14
  };
15
15
  export type OAuthRedirectFactory = (target: {
16
16
  readonly port: number;
17
+ readonly credentialKey: string;
17
18
  }, deps: {
18
19
  readonly openUrl: (url: string) => Promise<void>;
19
20
  }) => Promise<OAuthRedirect>;
@@ -0,0 +1,10 @@
1
+ import { type OAuthKeySpec, type OAuthRouteLike } from './keys.ts';
2
+ type SkillLike = {
3
+ readonly origin?: string;
4
+ readonly setup?: {
5
+ readonly routes?: ReadonlyArray<OAuthRouteLike> | null | undefined;
6
+ } | null;
7
+ };
8
+ export declare function oauthSpecs(skills: ReadonlyArray<SkillLike>): ReadonlyArray<OAuthKeySpec>;
9
+ export declare function oauthSpecFor(skills: ReadonlyArray<SkillLike>, credentialKey: string): OAuthKeySpec | null;
10
+ export {};
@@ -0,0 +1,25 @@
1
+ import { specFromRoute } from './keys.js';
2
+ export function oauthSpecs(skills) {
3
+ const byKey = new Map();
4
+ for (const skill of skills) {
5
+ if (skill.origin === 'overlay')
6
+ continue;
7
+ for (const route of skill.setup?.routes ?? []) {
8
+ const spec = specFromRoute(route);
9
+ if (spec && !byKey.has(spec.credentialKey))
10
+ byKey.set(spec.credentialKey, spec);
11
+ }
12
+ }
13
+ const claimed = new Set();
14
+ const specs = [];
15
+ for (const spec of byKey.values()) {
16
+ if (byKey.has(spec.stateKey) || claimed.has(spec.stateKey))
17
+ continue;
18
+ claimed.add(spec.stateKey);
19
+ specs.push(spec);
20
+ }
21
+ return specs;
22
+ }
23
+ export function oauthSpecFor(skills, credentialKey) {
24
+ return oauthSpecs(skills).find((spec) => spec.credentialKey === credentialKey) ?? null;
25
+ }
@@ -41,7 +41,7 @@ export async function resolveOAuthCredential(opts) {
41
41
  key: scopedKey(agentId, stateKey),
42
42
  value: JSON.stringify({
43
43
  ...stored,
44
- refreshToken: refreshed.refreshToken,
44
+ refreshToken: refreshed.refreshToken ?? refreshToken,
45
45
  expiresAt: refreshed.expiresAt
46
46
  })
47
47
  });
@@ -1,3 +1,4 @@
1
+ import { AbortController } from 'bare-abort-controller';
1
2
  import * as z from 'zod';
2
3
  const TOKEN_REQUEST_TIMEOUT_MS = 30_000;
3
4
  const TokenResponseSchema = z.object({
@@ -73,7 +74,7 @@ export async function refreshOAuthTokensWithFetch(config, refreshToken, fetchImp
73
74
  Accept: 'application/json'
74
75
  };
75
76
  applyClientSecret(config, body, headers);
76
- const controller = new globalThis.AbortController();
77
+ const controller = new AbortController();
77
78
  const timeout = globalThis.setTimeout(() => controller.abort(new Error('OAuth token refresh timed out')), TOKEN_REQUEST_TIMEOUT_MS);
78
79
  try {
79
80
  const response = await fetchImpl(config.tokenUrl, {
@@ -1,5 +1,5 @@
1
1
  import type { OAuthRedirectFactory } from './redirect-types.ts';
2
- export type OAuthProvider = 'google' | 'spotify' | 'asana' | 'notion';
2
+ export type OAuthProvider = string;
3
3
  export type OAuthTokens = {
4
4
  readonly accessToken: string;
5
5
  readonly refreshToken?: string;
@@ -1,5 +1,7 @@
1
1
  export { createOAuthClient, isTokenExpired, type OAuthClient } from './oauth/client.ts';
2
- export { buildProviderConfig, providerRequiresSecret, providerSupportsDcr, providerSupportsSharedIosSession } from './oauth/providers.ts';
2
+ export { buildProviderConfig } from './oauth/providers.ts';
3
+ export { specFromRoute, type OAuthKeySpec, type OAuthRouteLike } from './oauth/keys.ts';
4
+ export { oauthSpecFor, oauthSpecs } from './oauth/registry.ts';
3
5
  export type { OAuthCallbackResult, OAuthRedirect, OAuthRedirectFactory } from './oauth/redirect-types.ts';
4
6
  export type { OAuthRuntimeFlowDeps } from './oauth/flow-core.ts';
5
7
  export type { OAuthCredentials, OAuthFetch, OAuthFlowDeps, OAuthFlowResult, OAuthProvider, OAuthProviderConfig, OAuthRuntime, OAuthTokens } from './oauth/types.ts';
@@ -1,2 +1,4 @@
1
1
  export { createOAuthClient, isTokenExpired } from './oauth/client.js';
2
- export { buildProviderConfig, providerRequiresSecret, providerSupportsDcr, providerSupportsSharedIosSession } from './oauth/providers.js';
2
+ export { buildProviderConfig } from './oauth/providers.js';
3
+ export { specFromRoute } from './oauth/keys.js';
4
+ export { oauthSpecFor, oauthSpecs } from './oauth/registry.js';
@@ -1,15 +1,12 @@
1
1
  export { createPkce, scopedKey, type ConfigEngine, type Fetch, type FetchResponse, type OAuthTokens } from './oauth/common.ts';
2
2
  export { waitForOAuthCallback } from './oauth/browser-connect.ts';
3
- export { buildGoogleAuthUrl, connectGoogle, exchangeGoogleCode, GOOGLE_OAUTH_PORT, refreshGoogleToken, resolveGoogleCredential, type GoogleTokens } from './oauth/google.ts';
4
- export { buildNotionAuthUrl, connectNotion, exchangeNotionCode, NOTION_MCP_CREDENTIAL_KEY, NOTION_OAUTH_PORT, NOTION_OAUTH_STATE_KEY, refreshNotionToken, registerNotionClient, resolveNotionCredential, type NotionTokens } from './oauth/notion.ts';
5
- export { buildAsanaAuthUrl, connectAsana, exchangeAsanaCode, ASANA_MCP_CREDENTIAL_KEY, ASANA_OAUTH_PORT, ASANA_OAUTH_STATE_KEY, refreshAsanaToken, resolveAsanaCredential, type AsanaTokens } from './oauth/asana.ts';
6
- export { buildSpotifyAuthUrl, connectSpotify, exchangeSpotifyCode, refreshSpotifyToken, resolveSpotifyCredential, SPOTIFY_CREDENTIAL_KEY, SPOTIFY_OAUTH_PORT, SPOTIFY_OAUTH_STATE_KEY, type SpotifyTokens } from './oauth/spotify.ts';
7
3
  export { cancelOAuthFlow, runOAuthFlow } from './oauth/flow.ts';
8
- export { defaultCredentialKeyFor, GMAIL_CREDENTIAL_KEY, GOOGLE_CALENDAR_CREDENTIAL_KEY, GOOGLE_CREDENTIAL_KEYS, GOOGLE_DOCS_CREDENTIAL_KEY, GOOGLE_DRIVE_CREDENTIAL_KEY, GOOGLE_SHEETS_CREDENTIAL_KEY, LEGACY_GOOGLE_CREDENTIAL_KEY, OAUTH_KEY_SPECS, oauthKeySpec, oauthStateKeyFor, type OAuthKeySpec } from './oauth/keys.ts';
4
+ export { OAUTH_CALLBACK_PATH, OAUTH_WAIT_FOR_CODE_TIMEOUT_MS, oauthRedirectUri, specFromRoute, type OAuthKeySpec, type OAuthRouteLike } from './oauth/keys.ts';
5
+ export { oauthSpecFor, oauthSpecs } from './oauth/registry.ts';
9
6
  export { generatePkceChallenge, type PkceChallenge } from './oauth/pkce.ts';
10
- export { buildProviderConfig, providerRequiresSecret, providerSupportsDcr, providerSupportsSharedIosSession } from './oauth/providers.ts';
7
+ export { buildProviderConfig } from './oauth/providers.ts';
11
8
  export type { OAuthCallbackResult, OAuthRedirect, OAuthRedirectFactory } from './oauth/redirect-types.ts';
12
9
  export { registerOAuthClient, resolveDynamicClientId } from './oauth/register.ts';
10
+ export { resolveOAuthCredential } from './oauth/resolve.ts';
13
11
  export { isTokenExpired, refreshOAuthTokens } from './oauth/token-exchange.ts';
14
- export { verifyOAuthTokens, type VerifyResult } from './oauth/verify.ts';
15
12
  export type { OAuthCredentials, OAuthFlowDeps, OAuthFlowResult, OAuthProvider, OAuthProviderConfig } from './oauth/types.ts';
@@ -1,13 +1,10 @@
1
1
  export { createPkce, scopedKey } from './oauth/common.js';
2
2
  export { waitForOAuthCallback } from './oauth/browser-connect.js';
3
- export { buildGoogleAuthUrl, connectGoogle, exchangeGoogleCode, GOOGLE_OAUTH_PORT, refreshGoogleToken, resolveGoogleCredential } from './oauth/google.js';
4
- export { buildNotionAuthUrl, connectNotion, exchangeNotionCode, NOTION_MCP_CREDENTIAL_KEY, NOTION_OAUTH_PORT, NOTION_OAUTH_STATE_KEY, refreshNotionToken, registerNotionClient, resolveNotionCredential } from './oauth/notion.js';
5
- export { buildAsanaAuthUrl, connectAsana, exchangeAsanaCode, ASANA_MCP_CREDENTIAL_KEY, ASANA_OAUTH_PORT, ASANA_OAUTH_STATE_KEY, refreshAsanaToken, resolveAsanaCredential } from './oauth/asana.js';
6
- export { buildSpotifyAuthUrl, connectSpotify, exchangeSpotifyCode, refreshSpotifyToken, resolveSpotifyCredential, SPOTIFY_CREDENTIAL_KEY, SPOTIFY_OAUTH_PORT, SPOTIFY_OAUTH_STATE_KEY } from './oauth/spotify.js';
7
3
  export { cancelOAuthFlow, runOAuthFlow } from './oauth/flow.js';
8
- export { defaultCredentialKeyFor, GMAIL_CREDENTIAL_KEY, GOOGLE_CALENDAR_CREDENTIAL_KEY, GOOGLE_CREDENTIAL_KEYS, GOOGLE_DOCS_CREDENTIAL_KEY, GOOGLE_DRIVE_CREDENTIAL_KEY, GOOGLE_SHEETS_CREDENTIAL_KEY, LEGACY_GOOGLE_CREDENTIAL_KEY, OAUTH_KEY_SPECS, oauthKeySpec, oauthStateKeyFor } from './oauth/keys.js';
4
+ export { OAUTH_CALLBACK_PATH, OAUTH_WAIT_FOR_CODE_TIMEOUT_MS, oauthRedirectUri, specFromRoute } from './oauth/keys.js';
5
+ export { oauthSpecFor, oauthSpecs } from './oauth/registry.js';
9
6
  export { generatePkceChallenge } from './oauth/pkce.js';
10
- export { buildProviderConfig, providerRequiresSecret, providerSupportsDcr, providerSupportsSharedIosSession } from './oauth/providers.js';
7
+ export { buildProviderConfig } from './oauth/providers.js';
11
8
  export { registerOAuthClient, resolveDynamicClientId } from './oauth/register.js';
9
+ export { resolveOAuthCredential } from './oauth/resolve.js';
12
10
  export { isTokenExpired, refreshOAuthTokens } from './oauth/token-exchange.js';
13
- export { verifyOAuthTokens } from './oauth/verify.js';
@@ -21,6 +21,17 @@ export type SkillSetupField = {
21
21
  readonly secret?: boolean | undefined;
22
22
  readonly required?: boolean | undefined;
23
23
  };
24
+ export type SkillOAuthConfig = {
25
+ readonly stateKey: string;
26
+ readonly authUrl: string;
27
+ readonly tokenUrl: string;
28
+ readonly scopes: ReadonlyArray<string>;
29
+ readonly tokenAuth: 'pkce-only' | 'secret-in-body' | 'secret-in-basic';
30
+ readonly extraAuthParams?: Readonly<Record<string, string>> | undefined;
31
+ readonly registrationEndpoint?: string | undefined;
32
+ readonly port?: number | undefined;
33
+ readonly sharedIosSession?: boolean | undefined;
34
+ };
24
35
  export type SkillSetupRoute = {
25
36
  readonly kind: 'oauth' | 'token' | 'install' | 'picker' | 'instructions';
26
37
  readonly label: string;
@@ -32,6 +43,7 @@ export type SkillSetupRoute = {
32
43
  readonly configSteps?: ReadonlyArray<string> | undefined;
33
44
  readonly fields?: ReadonlyArray<SkillSetupField> | undefined;
34
45
  readonly satisfied?: boolean | undefined;
46
+ readonly oauth?: SkillOAuthConfig | undefined;
35
47
  };
36
48
  export type SkillSetup = {
37
49
  readonly summary?: string | undefined;
@@ -29,7 +29,11 @@ export const CHUNK_PAYLOAD_FIELDS = {
29
29
  export function versionedRegistrar(ns, namespace) {
30
30
  return (name, fields) => {
31
31
  ns.register({ name: `${name}-v1`, fields });
32
- ns.register({ name, versions: [{ version: 1, type: `@${namespace}/${name}-v1` }] });
32
+ ns.register({
33
+ name,
34
+ framed: false,
35
+ versions: [{ version: 1, type: `@${namespace}/${name}-v1` }]
36
+ });
33
37
  };
34
38
  }
35
39
  export function registerContentTypes(ns, namespace) {