@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,70 +0,0 @@
1
- import { closedClass, normalize, tag } from 'asenion';
2
- import { tokenizeForRag } from '../chunk/tokenizer.js';
3
- const MIN_TERM_LENGTH = 3;
4
- const GENERIC_WORDS = new Set([
5
- 'give',
6
- 'show',
7
- 'tell',
8
- 'get',
9
- 'find',
10
- 'what',
11
- 'data',
12
- 'info',
13
- 'information',
14
- 'please',
15
- 'want'
16
- ]);
17
- export function isMeaningfulToken(token) {
18
- if (token.length < MIN_TERM_LENGTH)
19
- return false;
20
- return !closedClass(token) && !GENERIC_WORDS.has(token);
21
- }
22
- export function extractSalientTerms(query) {
23
- const quotedPhrases = [];
24
- const quotePattern = /"([^"]+)"|'([^']+)'/g;
25
- let quoted = quotePattern.exec(query);
26
- while (quoted) {
27
- const phrase = normalize(quoted[1] ?? quoted[2] ?? '');
28
- if (phrase)
29
- quotedPhrases.push(phrase);
30
- quoted = quotePattern.exec(query);
31
- }
32
- const tokens = uniqueStrings(tokenizeForRag(query)
33
- .map((token) => token.text.trim().toLowerCase())
34
- .filter((token) => isMeaningfulToken(token) && /[\p{L}\p{N}]/u.test(token)));
35
- return { tokens, quotedPhrases, entities: extractEntities(query) };
36
- }
37
- function extractEntities(query) {
38
- const words = query.split(/\s+/).filter(Boolean);
39
- const entities = [];
40
- let run = [];
41
- const flush = () => {
42
- if (run.length >= 2) {
43
- const normalized = normalize(run.join(' '));
44
- if (names(normalized))
45
- entities.push(normalized);
46
- }
47
- run = [];
48
- };
49
- for (const word of words) {
50
- if (isCapitalizedWord(word)) {
51
- run.push(word);
52
- }
53
- else {
54
- flush();
55
- }
56
- }
57
- flush();
58
- return uniqueStrings(entities);
59
- }
60
- function names(run) {
61
- return tag(run).some(({ word, tag: part }) => isMeaningfulToken(word) && NAMING.has(part));
62
- }
63
- const NAMING = new Set(['noun', 'adj', 'num']);
64
- function isCapitalizedWord(word) {
65
- const firstLetter = word.match(/[\p{L}]/u)?.[0];
66
- return Boolean(firstLetter) && firstLetter === firstLetter?.toUpperCase();
67
- }
68
- export function uniqueStrings(values) {
69
- return [...new Set(values)];
70
- }
@@ -1,29 +0,0 @@
1
- import type { VectorHit, VectorIndex } from '../vector/types.ts';
2
- import type { RagScopeFilters } from './diversity.ts';
3
- import type { RagDocumentRef } from './target.ts';
4
- export type RagEmbedFn = (texts: string[]) => Promise<number[][]>;
5
- export type RagRetrievalDeps = {
6
- readonly index: VectorIndex;
7
- readonly embed: RagEmbedFn;
8
- };
9
- export type RagRetrievalQuery = RagScopeFilters & {
10
- readonly query: string;
11
- readonly limit?: number;
12
- readonly documentFirst?: boolean;
13
- readonly coverDocuments?: boolean;
14
- readonly chunkBudgetTokens?: number;
15
- readonly coverage?: boolean;
16
- readonly perDocChunkCap?: number;
17
- };
18
- export type RagKnowledgeQuery = {
19
- readonly query: string;
20
- readonly chatId: string;
21
- readonly documents: ReadonlyArray<RagDocumentRef>;
22
- readonly liveSourceIds?: ReadonlyArray<string>;
23
- readonly scopeDocumentIds?: ReadonlyArray<string>;
24
- };
25
- export type RagKnowledgeResult = {
26
- readonly hits: ReadonlyArray<VectorHit>;
27
- readonly targetDocumentId: string | null;
28
- readonly searchedCount: number;
29
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,8 +0,0 @@
1
- import type { RagSource } from './sources.ts';
2
- type WebRagSource = RagSource & {
3
- readonly url: string;
4
- };
5
- export declare const WEB_TOOLS: string[];
6
- export declare function webSourcesFromToolResult(result: unknown): WebRagSource[];
7
- export declare function withoutDataChannel(result: unknown): unknown;
8
- export {};
@@ -1,41 +0,0 @@
1
- import { MAX_RAG_SOURCES_PER_CHUNK, MAX_RAG_SOURCE_URL_CHARS, RAG_SOURCE_EXCERPT_CHARS } from '../../../../../schema/qvac.js';
2
- export const WEB_TOOLS = ['web_search', 'web_fetch'];
3
- export function webSourcesFromToolResult(result) {
4
- const results = structuredResults(result);
5
- const records = [];
6
- for (const entry of results) {
7
- if (records.length >= MAX_RAG_SOURCES_PER_CHUNK)
8
- break;
9
- if (typeof entry?.url !== 'string' || entry.url.length === 0)
10
- continue;
11
- if (entry.url.length > MAX_RAG_SOURCE_URL_CHARS)
12
- continue;
13
- records.push({
14
- documentId: null,
15
- title: typeof entry.title === 'string' && entry.title ? entry.title : entry.url,
16
- chunkIndex: records.length,
17
- excerpt: (typeof entry.content === 'string' ? entry.content : '').slice(0, RAG_SOURCE_EXCERPT_CHARS),
18
- attachmentId: null,
19
- artifactId: null,
20
- score: 0,
21
- url: entry.url
22
- });
23
- }
24
- return records;
25
- }
26
- export function withoutDataChannel(result) {
27
- if (result && typeof result === 'object' && 'data' in result) {
28
- const { data: _data, ...rest } = result;
29
- return rest;
30
- }
31
- return result;
32
- }
33
- function structuredResults(result) {
34
- if (!result || typeof result !== 'object')
35
- return [];
36
- const data = result.data;
37
- if (!data || typeof data !== 'object')
38
- return [];
39
- const results = data.results;
40
- return Array.isArray(results) ? results : [];
41
- }
@@ -1 +0,0 @@
1
- export declare function isWholeDocumentQuery(query: string): boolean;
@@ -1,96 +0,0 @@
1
- const SUMMARIZE_MARKERS = [
2
- /\bsummar(?:ize|ise|y|ies)\b/,
3
- /\btldr\b/,
4
- /\boverview\b/,
5
- /\bkey (?:points|takeaways)\b/,
6
- /\bmain (?:points|ideas)\b/,
7
- /\bgist\b/,
8
- /\brecap\b/,
9
- /\bwhat(?:'s| is| are)? (?:this|these|it) about\b/,
10
- /\bwhat(?:'s| is| are) (?:in|on)\b/,
11
- /\bwhat (?:do|does)\b.*\bcontain\b/
12
- ];
13
- const FILLER = new Set([
14
- 'a',
15
- 'about',
16
- 'all',
17
- 'an',
18
- 'and',
19
- 'attached',
20
- 'brief',
21
- 'briefly',
22
- 'can',
23
- 'concise',
24
- 'content',
25
- 'contents',
26
- 'contain',
27
- 'do',
28
- 'does',
29
- 'doc',
30
- 'docs',
31
- 'document',
32
- 'documents',
33
- 'file',
34
- 'files',
35
- 'for',
36
- 'give',
37
- 'in',
38
- 'is',
39
- 'it',
40
- 'its',
41
- 'me',
42
- 'my',
43
- 'of',
44
- 'on',
45
- 'pdf',
46
- 'please',
47
- 'provide',
48
- 'short',
49
- 'some',
50
- 'the',
51
- 'their',
52
- 'them',
53
- 'these',
54
- 'this',
55
- 'those',
56
- 'to',
57
- 'up',
58
- 'us',
59
- 'what',
60
- 'whole',
61
- 'you',
62
- 'your'
63
- ]);
64
- const MARKER_WORDS = new Set([
65
- 'are',
66
- 'dr',
67
- 'gist',
68
- 'ideas',
69
- 'key',
70
- 'main',
71
- 'overview',
72
- 'points',
73
- 'recap',
74
- 'summaries',
75
- 'summarise',
76
- 'summarize',
77
- 'summary',
78
- 'takeaways',
79
- 'tl',
80
- 'tldr'
81
- ]);
82
- const CLAUSE_BOUNDARY = /[.!?;\n]+|\band\b|\balso\b|\bthen\b/;
83
- export function isWholeDocumentQuery(query) {
84
- const normalized = query
85
- .toLowerCase()
86
- .replace(/\bwhat's\b/g, 'what is')
87
- .replace(/\btl[;:\s-]?dr\b/g, 'tldr')
88
- .replace(/[_-]+/g, ' ');
89
- return normalized.split(CLAUSE_BOUNDARY).some(isBareSummarizeClause);
90
- }
91
- function isBareSummarizeClause(clause) {
92
- if (!SUMMARIZE_MARKERS.some((marker) => marker.test(clause)))
93
- return false;
94
- const words = clause.match(/[a-z0-9]+/g) ?? [];
95
- return words.every((word) => FILLER.has(word) || MARKER_WORDS.has(word));
96
- }
@@ -1,15 +0,0 @@
1
- import type { VectorCandidate, VectorChunk, VectorHit, VectorIndex, VectorIndexInfo } from './types.ts';
2
- export declare class MemoryVectorIndex implements VectorIndex {
3
- private readonly _artifacts;
4
- private _chunks;
5
- private _dimensions;
6
- info(): VectorIndexInfo;
7
- upsert(artifactId: string, chunks: ReadonlyArray<VectorChunk>): Promise<void>;
8
- remove(artifactId: string): Promise<void>;
9
- search(embedding: ReadonlyArray<number>, opts: {
10
- readonly limit: number;
11
- readonly filter?: (candidate: VectorCandidate) => boolean;
12
- }): Promise<ReadonlyArray<VectorHit>>;
13
- clear(): Promise<void>;
14
- private _pack;
15
- }
@@ -1,135 +0,0 @@
1
- export class MemoryVectorIndex {
2
- _artifacts = new Map();
3
- _chunks = 0;
4
- _dimensions = null;
5
- info() {
6
- return { artifacts: this._artifacts.size, chunks: this._chunks, dimensions: this._dimensions };
7
- }
8
- upsert(artifactId, chunks) {
9
- const packed = this._pack(chunks);
10
- const prev = this._artifacts.get(artifactId);
11
- if (prev)
12
- this._chunks -= prev.ids.length;
13
- this._artifacts.set(artifactId, packed.artifact);
14
- this._chunks += packed.artifact.ids.length;
15
- if (packed.dimensions !== null && this._dimensions === null) {
16
- this._dimensions = packed.dimensions;
17
- }
18
- if (this._chunks === 0)
19
- this._dimensions = null;
20
- return Promise.resolve();
21
- }
22
- remove(artifactId) {
23
- const prev = this._artifacts.get(artifactId);
24
- if (!prev)
25
- return Promise.resolve();
26
- this._artifacts.delete(artifactId);
27
- this._chunks -= prev.ids.length;
28
- if (this._chunks === 0)
29
- this._dimensions = null;
30
- return Promise.resolve();
31
- }
32
- search(embedding, opts) {
33
- if (this._chunks === 0 || opts.limit <= 0)
34
- return Promise.resolve([]);
35
- if (this._dimensions !== null && embedding.length !== this._dimensions) {
36
- throw new Error(`vector index: query has ${embedding.length} dimensions, the index holds ${this._dimensions}`);
37
- }
38
- const dimensions = embedding.length;
39
- const query = new Float64Array(dimensions);
40
- let sum = 0;
41
- for (let d = 0; d < dimensions; d++) {
42
- const value = embedding[d];
43
- if (!Number.isFinite(value))
44
- throw new Error('vector index: query embedding is not finite');
45
- query[d] = value;
46
- sum += value * value;
47
- }
48
- const queryNorm = Math.sqrt(sum);
49
- const scored = [];
50
- for (const artifact of this._artifacts.values()) {
51
- for (let i = 0; i < artifact.ids.length; i++) {
52
- if (opts.filter) {
53
- const candidate = {
54
- id: artifact.ids[i],
55
- content: artifact.contents[i],
56
- metadataJson: artifact.metadataJsons[i]
57
- };
58
- if (!opts.filter(candidate))
59
- continue;
60
- }
61
- let dot = 0;
62
- const base = i * dimensions;
63
- for (let d = 0; d < dimensions; d++)
64
- dot += artifact.vectors[base + d] * query[d];
65
- const denominator = artifact.norms[i] * queryNorm;
66
- scored.push({
67
- id: artifact.ids[i],
68
- content: artifact.contents[i],
69
- metadataJson: artifact.metadataJsons[i],
70
- cosine: denominator > 0 ? dot / denominator : 0
71
- });
72
- }
73
- }
74
- scored.sort((a, b) => b.cosine - a.cosine);
75
- const results = scored.slice(0, opts.limit).map((entry) => ({
76
- id: entry.id,
77
- content: entry.content,
78
- metadataJson: entry.metadataJson,
79
- score: Math.max(0, entry.cosine)
80
- }));
81
- return Promise.resolve(results);
82
- }
83
- clear() {
84
- this._artifacts.clear();
85
- this._chunks = 0;
86
- this._dimensions = null;
87
- return Promise.resolve();
88
- }
89
- _pack(chunks) {
90
- if (chunks.length === 0) {
91
- return {
92
- artifact: {
93
- ids: [],
94
- contents: [],
95
- metadataJsons: [],
96
- vectors: new Float32Array(0),
97
- norms: new Float64Array(0)
98
- },
99
- dimensions: null
100
- };
101
- }
102
- const dimensions = chunks[0].embedding.length;
103
- if (dimensions === 0)
104
- throw new Error('vector index: chunk embedding is empty');
105
- if (this._dimensions !== null && dimensions !== this._dimensions) {
106
- throw new Error(`vector index: artifact has ${dimensions} dimensions, the index holds ${this._dimensions}`);
107
- }
108
- const ids = [];
109
- const contents = [];
110
- const metadataJsons = [];
111
- const vectors = new Float32Array(chunks.length * dimensions);
112
- const norms = new Float64Array(chunks.length);
113
- for (let i = 0; i < chunks.length; i++) {
114
- const chunk = chunks[i];
115
- if (chunk.embedding.length !== dimensions) {
116
- throw new Error(`vector index: chunk ${chunk.id} disagrees on dimensions`);
117
- }
118
- let sum = 0;
119
- for (let d = 0; d < dimensions; d++) {
120
- const value = chunk.embedding[d];
121
- if (!Number.isFinite(value)) {
122
- throw new Error(`vector index: chunk ${chunk.id} embedding is not finite`);
123
- }
124
- const stored = Math.fround(value);
125
- vectors[i * dimensions + d] = stored;
126
- sum += stored * stored;
127
- }
128
- norms[i] = Math.sqrt(sum);
129
- ids.push(chunk.id);
130
- contents.push(chunk.content);
131
- metadataJsons.push(chunk.metadataJson);
132
- }
133
- return { artifact: { ids, contents, metadataJsons, vectors, norms }, dimensions };
134
- }
135
- }
@@ -1,28 +0,0 @@
1
- export type VectorChunk = {
2
- readonly id: string;
3
- readonly content: string;
4
- readonly metadataJson: string;
5
- readonly embedding: ReadonlyArray<number>;
6
- };
7
- export type VectorHit = {
8
- readonly id: string;
9
- readonly content: string;
10
- readonly metadataJson: string;
11
- readonly score: number;
12
- };
13
- export type VectorCandidate = Omit<VectorHit, 'score'>;
14
- export type VectorIndexInfo = {
15
- readonly artifacts: number;
16
- readonly chunks: number;
17
- readonly dimensions: number | null;
18
- };
19
- export interface VectorIndex {
20
- info(): VectorIndexInfo;
21
- upsert(artifactId: string, chunks: ReadonlyArray<VectorChunk>): Promise<void>;
22
- remove(artifactId: string): Promise<void>;
23
- search(embedding: ReadonlyArray<number>, opts: {
24
- readonly limit: number;
25
- readonly filter?: (candidate: VectorCandidate) => boolean;
26
- }): Promise<ReadonlyArray<VectorHit>>;
27
- clear(): Promise<void>;
28
- }
@@ -1 +0,0 @@
1
- export {};
@@ -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
- }