@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.
- package/dist-lib/lib/api/chat.d.ts +3 -1
- package/dist-lib/lib/api/chat.js +6 -2
- package/dist-lib/lib/api/index.d.ts +2 -0
- package/dist-lib/lib/api/index.js +3 -1
- package/dist-lib/lib/api/inference-calls.d.ts +18 -0
- package/dist-lib/lib/api/inference-calls.js +15 -0
- package/dist-lib/lib/api/rag.js +10 -2
- package/dist-lib/lib/assistant/harness.d.ts +1 -0
- package/dist-lib/lib/assistant/history.d.ts +10 -1
- package/dist-lib/lib/assistant/history.js +36 -1
- package/dist-lib/lib/assistant/message.d.ts +2 -0
- package/dist-lib/lib/assistant/message.js +11 -0
- package/dist-lib/lib/assistant/skill-encode.js +27 -1
- package/dist-lib/lib/assistant-tree.d.ts +2 -0
- package/dist-lib/lib/assistant-tree.js +11 -2
- package/dist-lib/lib/assistant.d.ts +19 -3
- package/dist-lib/lib/assistant.js +148 -23
- package/dist-lib/lib/core/chunk.js +5 -0
- package/dist-lib/lib/core/files/rag/build.d.ts +1 -2
- package/dist-lib/lib/core/files/rag/build.js +1 -2
- package/dist-lib/lib/core/files/rag/extract/office-collabora.d.ts +1 -1
- package/dist-lib/lib/core/files/rag/index.d.ts +4 -24
- package/dist-lib/lib/core/files/rag/index.js +3 -17
- package/dist-lib/lib/core/files/rag/load.d.ts +1 -2
- package/dist-lib/lib/core/files/rag/load.js +1 -2
- package/dist-lib/lib/core/files/rag/produce.d.ts +1 -1
- package/dist-lib/lib/core/files/rag/produce.js +1 -3
- package/dist-lib/lib/core/files/rag/retrieval/full-text.d.ts +1 -1
- package/dist-lib/lib/core/files/rag/retrieval/full-text.js +1 -4
- package/dist-lib/lib/core/files/rag/similarity.d.ts +5 -0
- package/dist-lib/lib/core/files/rag/similarity.js +6 -0
- package/dist-lib/lib/core/files/upload.d.ts +1 -1
- package/dist-lib/lib/core/inference-calls-handoff.d.ts +20 -0
- package/dist-lib/lib/core/inference-calls-handoff.js +37 -0
- package/dist-lib/lib/core/inference-calls-receiver.d.ts +14 -0
- package/dist-lib/lib/core/inference-calls-receiver.js +39 -0
- package/dist-lib/lib/core/notification.js +5 -4
- package/dist-lib/lib/core/skill-secrets.js +3 -6
- package/dist-lib/lib/core.d.ts +9 -1
- package/dist-lib/lib/core.js +129 -13
- package/dist-lib/lib/credential-pusher.d.ts +2 -3
- package/dist-lib/lib/credential-pusher.js +67 -39
- package/dist-lib/lib/inference-calls.d.ts +40 -0
- package/dist-lib/lib/inference-calls.js +266 -0
- package/dist-lib/lib/integrations/index.d.ts +1 -2
- package/dist-lib/lib/integrations/index.js +0 -1
- package/dist-lib/lib/integrations/setup-routes.js +0 -15
- package/dist-lib/lib/oauth/flow-core.js +1 -1
- package/dist-lib/lib/oauth/flow.d.ts +4 -2
- package/dist-lib/lib/oauth/flow.js +3 -4
- package/dist-lib/lib/oauth/host.d.ts +3 -1
- package/dist-lib/lib/oauth/host.js +3 -1
- package/dist-lib/lib/oauth/keys.d.ts +21 -20
- package/dist-lib/lib/oauth/keys.js +59 -85
- package/dist-lib/lib/oauth/loopback.d.ts +2 -2
- package/dist-lib/lib/oauth/loopback.js +32 -19
- package/dist-lib/lib/oauth/loopback.stub.d.ts +2 -2
- package/dist-lib/lib/oauth/loopback.stub.js +2 -2
- package/dist-lib/lib/oauth/providers.d.ts +3 -5
- package/dist-lib/lib/oauth/providers.js +20 -67
- package/dist-lib/lib/oauth/redirect-types.d.ts +1 -0
- package/dist-lib/lib/oauth/registry.d.ts +10 -0
- package/dist-lib/lib/oauth/registry.js +25 -0
- package/dist-lib/lib/oauth/resolve.js +1 -1
- package/dist-lib/lib/oauth/token-exchange-core.js +2 -1
- package/dist-lib/lib/oauth/types.d.ts +1 -1
- package/dist-lib/lib/oauth.client.d.ts +3 -1
- package/dist-lib/lib/oauth.client.js +3 -1
- package/dist-lib/lib/oauth.d.ts +4 -7
- package/dist-lib/lib/oauth.js +4 -7
- package/dist-lib/lib/skill-types.d.ts +12 -0
- package/dist-lib/schema/content.js +5 -1
- package/dist-lib/schema/engine.js +63 -2
- package/dist-lib/schema/qvac.js +4 -2
- package/dist-lib/spec/bind.js +3 -0
- package/dist-lib/spec/calls.js +1 -0
- package/dist-lib/spec/capabilities.d.ts +2 -0
- package/dist-lib/spec/hrpc/hrpc.json +13 -0
- package/dist-lib/spec/hrpc/index.js +15 -3
- package/dist-lib/spec/hrpc/messages.js +284 -52
- package/dist-lib/spec/hyperschema/index.js +284 -52
- package/dist-lib/spec/hyperschema/schema.json +210 -1
- package/dist-lib/spec/hyperschema/types.d.ts +51 -1
- package/dist-lib/spec/local/hyperdb/messages.js +64 -128
- package/dist-lib/spec/local/hyperschema/index.js +32 -64
- package/dist-lib/spec/local/hyperschema/schema.json +16 -0
- package/dist-lib/spec/mesh/hyperdb/messages.js +176 -311
- package/dist-lib/spec/mesh/hyperdispatch/messages.js +132 -236
- package/dist-lib/spec/mesh/hyperschema/index.js +132 -236
- package/dist-lib/spec/mesh/hyperschema/schema.json +70 -1
- package/dist-lib/spec/mesh/hyperschema/types.d.ts +3 -1
- package/package.json +15 -18
- package/tui/app.mjs +98 -155
- package/tui/lib/knowledge-import.mjs +1 -1
- package/tui/lib/save-file.mjs +1 -1
- package/.claude/skills/asana/SKILL.md +0 -86
- package/.claude/skills/compaction/SKILL.md +0 -136
- package/.claude/skills/device-mesh-debug/SKILL.md +0 -328
- package/.claude/skills/gh-stack/SKILL.md +0 -181
- package/.claude/skills/gh-stack/references/commands.md +0 -177
- package/.claude/skills/gh-stack/references/stack-design.md +0 -97
- package/.claude/skills/gh-stack/references/troubleshooting.md +0 -159
- package/.claude/skills/js-house-style/SKILL.md +0 -671
- package/.claude/skills/pr-create/SKILL.md +0 -243
- package/.claude/skills/pr-review/SKILL.md +0 -428
- package/.claude/skills/release/SKILL.md +0 -122
- package/CLAUDE.md +0 -48
- package/dist-lib/lib/core/files/rag/artifact/codec.d.ts +0 -3
- package/dist-lib/lib/core/files/rag/artifact/codec.js +0 -172
- package/dist-lib/lib/core/files/rag/artifact/id.d.ts +0 -10
- package/dist-lib/lib/core/files/rag/artifact/id.js +0 -39
- package/dist-lib/lib/core/files/rag/artifact/types.d.ts +0 -24
- package/dist-lib/lib/core/files/rag/artifact/types.js +0 -41
- package/dist-lib/lib/core/files/rag/chunk/chunking.d.ts +0 -12
- package/dist-lib/lib/core/files/rag/chunk/chunking.js +0 -117
- package/dist-lib/lib/core/files/rag/chunk/metadata.d.ts +0 -30
- package/dist-lib/lib/core/files/rag/chunk/metadata.js +0 -89
- package/dist-lib/lib/core/files/rag/chunk/tokenizer.d.ts +0 -7
- package/dist-lib/lib/core/files/rag/chunk/tokenizer.js +0 -18
- package/dist-lib/lib/core/files/rag/extract/csv-text.d.ts +0 -1
- package/dist-lib/lib/core/files/rag/extract/csv-text.js +0 -117
- package/dist-lib/lib/core/files/rag/extract/document-types.d.ts +0 -22
- package/dist-lib/lib/core/files/rag/extract/document-types.js +0 -152
- package/dist-lib/lib/core/files/rag/extract/extract.d.ts +0 -17
- package/dist-lib/lib/core/files/rag/extract/extract.js +0 -81
- package/dist-lib/lib/core/files/rag/extract/html-table-text.d.ts +0 -1
- package/dist-lib/lib/core/files/rag/extract/html-table-text.js +0 -125
- package/dist-lib/lib/core/files/rag/extract/html-text.d.ts +0 -1
- package/dist-lib/lib/core/files/rag/extract/html-text.js +0 -132
- package/dist-lib/lib/core/files/rag/extract/pdf-platform.d.ts +0 -17
- package/dist-lib/lib/core/files/rag/extract/pdf-platform.js +0 -141
- package/dist-lib/lib/core/files/rag/extract/pdf-text.d.ts +0 -12
- package/dist-lib/lib/core/files/rag/extract/pdf-text.js +0 -43
- package/dist-lib/lib/core/files/rag/extract/rtf-text.d.ts +0 -1
- package/dist-lib/lib/core/files/rag/extract/rtf-text.js +0 -15
- package/dist-lib/lib/core/files/rag/extract/text-decoding.d.ts +0 -1
- package/dist-lib/lib/core/files/rag/extract/text-decoding.js +0 -91
- package/dist-lib/lib/core/files/rag/extract/types.d.ts +0 -36
- package/dist-lib/lib/core/files/rag/extract/types.js +0 -12
- package/dist-lib/lib/core/files/rag/extract/utf.d.ts +0 -2
- package/dist-lib/lib/core/files/rag/extract/utf.js +0 -18
- package/dist-lib/lib/core/files/rag/retrieval/citation-match.d.ts +0 -2
- package/dist-lib/lib/core/files/rag/retrieval/citation-match.js +0 -16
- package/dist-lib/lib/core/files/rag/retrieval/coverage.d.ts +0 -4
- package/dist-lib/lib/core/files/rag/retrieval/coverage.js +0 -48
- package/dist-lib/lib/core/files/rag/retrieval/diversity.d.ts +0 -10
- package/dist-lib/lib/core/files/rag/retrieval/diversity.js +0 -37
- package/dist-lib/lib/core/files/rag/retrieval/floor.d.ts +0 -5
- package/dist-lib/lib/core/files/rag/retrieval/floor.js +0 -21
- package/dist-lib/lib/core/files/rag/retrieval/format.d.ts +0 -6
- package/dist-lib/lib/core/files/rag/retrieval/format.js +0 -21
- package/dist-lib/lib/core/files/rag/retrieval/knowledge.d.ts +0 -2
- package/dist-lib/lib/core/files/rag/retrieval/knowledge.js +0 -54
- package/dist-lib/lib/core/files/rag/retrieval/notices.d.ts +0 -16
- package/dist-lib/lib/core/files/rag/retrieval/notices.js +0 -27
- package/dist-lib/lib/core/files/rag/retrieval/scoring.d.ts +0 -8
- package/dist-lib/lib/core/files/rag/retrieval/scoring.js +0 -82
- package/dist-lib/lib/core/files/rag/retrieval/search.d.ts +0 -3
- package/dist-lib/lib/core/files/rag/retrieval/search.js +0 -49
- package/dist-lib/lib/core/files/rag/retrieval/selection.d.ts +0 -11
- package/dist-lib/lib/core/files/rag/retrieval/selection.js +0 -93
- package/dist-lib/lib/core/files/rag/retrieval/source-tag-filter.d.ts +0 -6
- package/dist-lib/lib/core/files/rag/retrieval/source-tag-filter.js +0 -79
- package/dist-lib/lib/core/files/rag/retrieval/sources.d.ts +0 -13
- package/dist-lib/lib/core/files/rag/retrieval/sources.js +0 -20
- package/dist-lib/lib/core/files/rag/retrieval/target.d.ts +0 -13
- package/dist-lib/lib/core/files/rag/retrieval/target.js +0 -89
- package/dist-lib/lib/core/files/rag/retrieval/terms.d.ts +0 -8
- package/dist-lib/lib/core/files/rag/retrieval/terms.js +0 -70
- package/dist-lib/lib/core/files/rag/retrieval/types.d.ts +0 -29
- package/dist-lib/lib/core/files/rag/retrieval/types.js +0 -1
- package/dist-lib/lib/core/files/rag/retrieval/web-sources.d.ts +0 -8
- package/dist-lib/lib/core/files/rag/retrieval/web-sources.js +0 -41
- package/dist-lib/lib/core/files/rag/retrieval/whole-document-query.d.ts +0 -1
- package/dist-lib/lib/core/files/rag/retrieval/whole-document-query.js +0 -96
- package/dist-lib/lib/core/files/rag/vector/memory.d.ts +0 -15
- package/dist-lib/lib/core/files/rag/vector/memory.js +0 -135
- package/dist-lib/lib/core/files/rag/vector/types.d.ts +0 -28
- package/dist-lib/lib/core/files/rag/vector/types.js +0 -1
- package/dist-lib/lib/integrations/oauth-providers.d.ts +0 -14
- package/dist-lib/lib/integrations/oauth-providers.js +0 -116
- package/dist-lib/lib/oauth/asana.d.ts +0 -35
- package/dist-lib/lib/oauth/asana.js +0 -71
- package/dist-lib/lib/oauth/google.d.ts +0 -37
- package/dist-lib/lib/oauth/google.js +0 -77
- package/dist-lib/lib/oauth/notion.d.ts +0 -34
- package/dist-lib/lib/oauth/notion.js +0 -82
- package/dist-lib/lib/oauth/spotify.d.ts +0 -32
- package/dist-lib/lib/oauth/spotify.js +0 -74
- package/dist-lib/lib/oauth/verify.d.ts +0 -8
- 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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
78
|
-
|
|
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
|
-
|
|
81
|
-
|
|
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(
|
|
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
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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 ?? '/',
|
|
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.
|
|
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(
|
|
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(
|
|
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 {
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
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
|
-
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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)
|
|
@@ -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
|
|
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 =
|
|
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
|
|
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
|
|
2
|
+
export { buildProviderConfig } from './oauth/providers.js';
|
|
3
|
+
export { specFromRoute } from './oauth/keys.js';
|
|
4
|
+
export { oauthSpecFor, oauthSpecs } from './oauth/registry.js';
|
package/dist-lib/lib/oauth.d.ts
CHANGED
|
@@ -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 {
|
|
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
|
|
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';
|
package/dist-lib/lib/oauth.js
CHANGED
|
@@ -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 {
|
|
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
|
|
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({
|
|
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) {
|