@qikbar/qikbar 0.1.0 → 0.2.1
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/README.md +30 -1
- package/bin/qikbar.mjs +203 -0
- package/dist/ai/embeddings.d.ts +51 -0
- package/dist/ai/index.d.ts +4 -0
- package/dist/ai/mcp.d.ts +84 -0
- package/dist/ai.js +27 -9
- package/dist/chunks/{bar-D5CSPT3U.js → bar-P3SCR4SJ.js} +684 -160
- package/dist/chunks/bar-P3SCR4SJ.js.map +7 -0
- package/dist/chunks/chunk-24EBWTCF.js +271 -0
- package/dist/chunks/chunk-24EBWTCF.js.map +7 -0
- package/dist/chunks/{chunk-I77YSUJN.js → chunk-INTEVQYK.js} +7 -3
- package/dist/chunks/{chunk-I77YSUJN.js.map → chunk-INTEVQYK.js.map} +2 -2
- package/dist/chunks/{chunk-VXTYD56F.js → chunk-JHQAIXM7.js} +9 -4
- package/dist/chunks/{chunk-VXTYD56F.js.map → chunk-JHQAIXM7.js.map} +2 -2
- package/dist/chunks/{chunk-2ADXL7KQ.js → chunk-MRHKJ2FZ.js} +63 -2
- package/dist/chunks/{chunk-2ADXL7KQ.js.map → chunk-MRHKJ2FZ.js.map} +3 -3
- package/dist/chunks/{chunk-IJ3WUM3T.js → chunk-R2AY6LRL.js} +35 -4
- package/dist/chunks/chunk-R2AY6LRL.js.map +7 -0
- package/dist/chunks/chunk-TIM4VBM4.js +98 -0
- package/dist/chunks/chunk-TIM4VBM4.js.map +7 -0
- package/dist/chunks/{chunk-HBBSETRF.js → chunk-WO6XXQ3H.js} +47 -6
- package/dist/chunks/chunk-WO6XXQ3H.js.map +7 -0
- package/dist/chunks/launcher-B5MGOPEQ.js +37 -0
- package/dist/chunks/launcher-B5MGOPEQ.js.map +7 -0
- package/dist/core/labels.d.ts +98 -0
- package/dist/core/launcher.d.ts +8 -0
- package/dist/core/lazy.d.ts +12 -0
- package/dist/core/types.d.ts +138 -2
- package/dist/element/index.d.ts +56 -0
- package/dist/element.js +145 -0
- package/dist/element.js.map +7 -0
- package/dist/extensions.js +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +19 -7
- package/dist/locales/index.d.ts +24 -0
- package/dist/locales.js +812 -0
- package/dist/locales.js.map +7 -0
- package/dist/qikbar.global.js +68 -25
- package/dist/qikbar.global.js.map +4 -4
- package/dist/react.js +7 -6
- package/dist/react.js.map +2 -2
- package/dist/server/index.d.ts +19 -0
- package/dist/server.js +38 -2
- package/dist/server.js.map +2 -2
- package/dist/solid/index.d.ts +42 -0
- package/dist/solid.js +92 -0
- package/dist/solid.js.map +7 -0
- package/dist/styles.css +34 -3
- package/dist/svelte/index.d.ts +58 -0
- package/dist/svelte.js +54 -0
- package/dist/svelte.js.map +7 -0
- package/dist/theme.js +1 -1
- package/dist/ui/bar.d.ts +89 -3
- package/dist/ui/icons.d.ts +5 -0
- package/dist/ui/markdown.d.ts +3 -1
- package/dist/ui/views.d.ts +8 -0
- package/dist/ui/webmcp.d.ts +33 -0
- package/dist/utils.js +1 -1
- package/dist/vue/index.d.ts +74 -0
- package/dist/vue.js +121 -0
- package/dist/vue.js.map +7 -0
- package/package.json +45 -4
- package/dist/chunks/bar-D5CSPT3U.js.map +0 -7
- package/dist/chunks/chunk-6TC6G2C5.js +0 -107
- package/dist/chunks/chunk-6TC6G2C5.js.map +0 -7
- package/dist/chunks/chunk-HBBSETRF.js.map +0 -7
- package/dist/chunks/chunk-IJ3WUM3T.js.map +0 -7
package/README.md
CHANGED
|
@@ -67,6 +67,35 @@ import { Qikbar, useCommands } from '@qikbar/qikbar/react'
|
|
|
67
67
|
useCommands([{ title: 'Archive project', icon: 'trash', run: archive }], [archive])
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
+
## Vue, Svelte, Solid and web components
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { Qikbar, useCommands } from '@qikbar/qikbar/vue' // <Qikbar :config="…" />
|
|
74
|
+
import { qikbarStore } from '@qikbar/qikbar/svelte' // $bar is the state
|
|
75
|
+
import { QikbarProvider, useCommands } from '@qikbar/qikbar/solid'
|
|
76
|
+
import '@qikbar/qikbar/element' // <qik-bar><qik-command href="/settings">Settings</qik-command></qik-bar>
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Mobile, personalization and more
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
createQikbar({
|
|
83
|
+
launcher: 'touch', // a floating search button on phones
|
|
84
|
+
labels: de, // from '@qikbar/qikbar/locales'
|
|
85
|
+
semantic: { embed: proxyEmbeddings({ url: '/api/embed' }) }, // search by meaning
|
|
86
|
+
webmcp: true, // let browser AI agents use your commands
|
|
87
|
+
onEvent: (e) => posthog.capture(`command_bar_${e.type}`, e), // analytics
|
|
88
|
+
})
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Users can pin commands (⌘⇧P) and give them aliases, lists can be `multiSelect` with bulk `runMany` actions, and `ctx.toast({ title, undo })` adds Undo with ⌘Z.
|
|
92
|
+
|
|
93
|
+
## Extensions from the registry
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
npx @qikbar/qikbar add weather currency
|
|
97
|
+
```
|
|
98
|
+
|
|
70
99
|
## AI
|
|
71
100
|
|
|
72
101
|
```ts
|
|
@@ -78,7 +107,7 @@ import { createHandler, anthropic } from '@qikbar/qikbar/server'
|
|
|
78
107
|
export const POST = createHandler({ provider: anthropic({ apiKey: process.env.ANTHROPIC_API_KEY }) })
|
|
79
108
|
```
|
|
80
109
|
|
|
81
|
-
Press <kbd>Tab</kbd> in the bar to ask AI. The model can search and run your commands. Providers: `anthropic`, `openai`, `gemini`, `openaiCompatible`, `ollama`, `browserAI`, `proxy`, `byok`.
|
|
110
|
+
Press <kbd>Tab</kbd> in the bar to ask AI. The model can search and run your commands. Providers: `anthropic`, `openai`, `gemini`, `openaiCompatible`, `ollama`, `browserAI`, `proxy`, `byok`. Add MCP servers' tools with `ai: { provider, mcp: [mcp({ url: '/api/mcp' })] }`.
|
|
82
111
|
|
|
83
112
|
## Script tag
|
|
84
113
|
|
package/bin/qikbar.mjs
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* qikbar CLI — add extensions from the registry to your project.
|
|
4
|
+
*
|
|
5
|
+
* npx @qikbar/qikbar add weather currency
|
|
6
|
+
* npx @qikbar/qikbar list
|
|
7
|
+
* npx @qikbar/qikbar info weather
|
|
8
|
+
*
|
|
9
|
+
* Extensions are copied into your codebase as source (like shadcn/ui), so you
|
|
10
|
+
* own them: read them, change them, delete what you don't need.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
|
|
14
|
+
import { dirname, join, relative, resolve } from 'node:path'
|
|
15
|
+
import { fileURLToPath } from 'node:url'
|
|
16
|
+
|
|
17
|
+
const REGISTRY = (process.env.QIKBAR_REGISTRY || 'https://qikbar.com/registry').replace(/\/$/, '')
|
|
18
|
+
const color = process.stdout.isTTY && !process.env.NO_COLOR
|
|
19
|
+
const paint = (code) => (s) => (color ? `\x1b[${code}m${s}\x1b[0m` : String(s))
|
|
20
|
+
const bold = paint(1)
|
|
21
|
+
const dim = paint(2)
|
|
22
|
+
const green = paint(32)
|
|
23
|
+
const red = paint(31)
|
|
24
|
+
const cyan = paint(36)
|
|
25
|
+
|
|
26
|
+
function version() {
|
|
27
|
+
try {
|
|
28
|
+
const pkg = JSON.parse(readFileSync(join(dirname(fileURLToPath(import.meta.url)), '..', 'package.json'), 'utf8'))
|
|
29
|
+
return pkg.version
|
|
30
|
+
} catch {
|
|
31
|
+
return 'unknown'
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function parseArgs(argv) {
|
|
36
|
+
const args = { _: [], flags: {} }
|
|
37
|
+
for (let i = 0; i < argv.length; i++) {
|
|
38
|
+
const a = argv[i]
|
|
39
|
+
if (a === '--') {
|
|
40
|
+
args._.push(...argv.slice(i + 1))
|
|
41
|
+
break
|
|
42
|
+
}
|
|
43
|
+
if (a.startsWith('--')) {
|
|
44
|
+
const [key, inline] = a.slice(2).split('=', 2)
|
|
45
|
+
if (inline !== undefined) args.flags[key] = inline
|
|
46
|
+
else if (['dir', 'registry', 'cwd'].includes(key)) args.flags[key] = argv[++i]
|
|
47
|
+
else args.flags[key] = true
|
|
48
|
+
} else if (a.startsWith('-') && a.length > 1) {
|
|
49
|
+
for (const c of a.slice(1)) args.flags[{ f: 'force', h: 'help', v: 'version', d: 'dir', y: 'yes' }[c] ?? c] = c === 'd' ? argv[++i] : true
|
|
50
|
+
} else args._.push(a)
|
|
51
|
+
}
|
|
52
|
+
return args
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function get(path, registry) {
|
|
56
|
+
const url = `${registry}/${path}`
|
|
57
|
+
let res
|
|
58
|
+
try {
|
|
59
|
+
res = await fetch(url, { headers: { 'user-agent': `qikbar-cli/${version()}` } })
|
|
60
|
+
} catch (err) {
|
|
61
|
+
throw new Error(`Couldn't reach ${url} (${err.cause?.code ?? err.message})`)
|
|
62
|
+
}
|
|
63
|
+
if (!res.ok) throw new Error(`${url} responded ${res.status}`)
|
|
64
|
+
return res
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function loadIndex(registry) {
|
|
68
|
+
const data = await (await get('index.json', registry)).json()
|
|
69
|
+
if (!data || !Array.isArray(data.extensions)) throw new Error('The registry index is malformed.')
|
|
70
|
+
return data
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Levenshtein distance, for "did you mean". */
|
|
74
|
+
function distance(a, b) {
|
|
75
|
+
const dp = Array.from({ length: a.length + 1 }, (_, i) => [i, ...Array(b.length).fill(0)])
|
|
76
|
+
for (let j = 1; j <= b.length; j++) dp[0][j] = j
|
|
77
|
+
for (let i = 1; i <= a.length; i++)
|
|
78
|
+
for (let j = 1; j <= b.length; j++) dp[i][j] = Math.min(dp[i - 1][j] + 1, dp[i][j - 1] + 1, dp[i - 1][j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1))
|
|
79
|
+
return dp[a.length][b.length]
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function suggest(name, names) {
|
|
83
|
+
const best = names.map((n) => [n, distance(name, n)]).sort((x, y) => x[1] - y[1])[0]
|
|
84
|
+
return best && best[1] <= Math.max(2, Math.floor(name.length / 3)) ? best[0] : undefined
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function defaultDir(cwd) {
|
|
88
|
+
try {
|
|
89
|
+
const cfg = JSON.parse(readFileSync(join(cwd, 'qikbar.json'), 'utf8'))
|
|
90
|
+
if (cfg.extensionsDir) return cfg.extensionsDir
|
|
91
|
+
} catch {
|
|
92
|
+
// no config
|
|
93
|
+
}
|
|
94
|
+
return existsSync(join(cwd, 'src')) ? 'src/qikbar/extensions' : 'qikbar/extensions'
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function identifier(name) {
|
|
98
|
+
return name.replace(/[^a-zA-Z0-9]+(.)/g, (_, c) => c.toUpperCase()).replace(/^[^a-zA-Z_$]/, '_$&')
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function hasPackage(cwd) {
|
|
102
|
+
try {
|
|
103
|
+
const pkg = JSON.parse(readFileSync(join(cwd, 'package.json'), 'utf8'))
|
|
104
|
+
return !!({ ...pkg.dependencies, ...pkg.devDependencies }['@qikbar/qikbar'])
|
|
105
|
+
} catch {
|
|
106
|
+
return true // not a node project — don't nag
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async function cmdList(flags, registry) {
|
|
111
|
+
const index = await loadIndex(registry)
|
|
112
|
+
if (flags.json) return console.log(JSON.stringify(index.extensions, null, 2))
|
|
113
|
+
const width = Math.max(...index.extensions.map((e) => e.name.length))
|
|
114
|
+
console.log(bold(`${index.extensions.length} extensions`) + dim(` ${registry}`))
|
|
115
|
+
for (const e of index.extensions) console.log(` ${cyan(e.name.padEnd(width))} ${e.description ?? e.title}`)
|
|
116
|
+
console.log(dim(`\nAdd one with: npx @qikbar/qikbar add <name>`))
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async function cmdInfo(names, registry) {
|
|
120
|
+
const index = await loadIndex(registry)
|
|
121
|
+
for (const name of names) {
|
|
122
|
+
const e = index.extensions.find((x) => x.name === name)
|
|
123
|
+
if (!e) throw new Error(`Unknown extension "${name}".`)
|
|
124
|
+
console.log(`${bold(e.title)} ${dim(`(${e.name}${e.version ? `@${e.version}` : ''})`)}`)
|
|
125
|
+
if (e.description) console.log(e.description)
|
|
126
|
+
if (e.author) console.log(dim(`by ${e.author}`))
|
|
127
|
+
if (e.uses) console.log(dim(`Uses: ${e.uses}`))
|
|
128
|
+
if (e.tags?.length) console.log(dim(`Shows off: ${e.tags.join(', ')}`))
|
|
129
|
+
if (e.try) console.log(dim(`Try: “${e.try}”`))
|
|
130
|
+
console.log(dim(`Source: ${registry}/${e.file ?? `${e.name}.ts`}`))
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async function cmdAdd(names, flags, registry) {
|
|
135
|
+
if (!names.length) throw new Error('Name at least one extension, e.g. `qikbar add weather`. Run `qikbar list` to see them all.')
|
|
136
|
+
const cwd = resolve(flags.cwd ?? process.cwd())
|
|
137
|
+
const dir = resolve(cwd, flags.dir ?? defaultDir(cwd))
|
|
138
|
+
const index = await loadIndex(registry)
|
|
139
|
+
const known = index.extensions.map((e) => e.name)
|
|
140
|
+
const wanted = names.includes('all') ? known : names
|
|
141
|
+
const unknown = wanted.filter((n) => !known.includes(n))
|
|
142
|
+
if (unknown.length) {
|
|
143
|
+
throw new Error(
|
|
144
|
+
unknown.map((n) => `Unknown extension "${n}".${suggest(n, known) ? ` Did you mean "${suggest(n, known)}"?` : ''}`).join('\n') +
|
|
145
|
+
'\nRun `qikbar list` to see them all.',
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
mkdirSync(dir, { recursive: true })
|
|
149
|
+
const added = []
|
|
150
|
+
for (const name of wanted) {
|
|
151
|
+
const entry = index.extensions.find((e) => e.name === name)
|
|
152
|
+
const file = join(dir, `${name}.ts`)
|
|
153
|
+
if (existsSync(file) && !flags.force) {
|
|
154
|
+
console.log(`${dim('skip')} ${relative(cwd, file)} ${dim('(exists — use --force to overwrite)')}`)
|
|
155
|
+
continue
|
|
156
|
+
}
|
|
157
|
+
const source = await (await get(entry.file ?? `${name}.ts`, registry)).text()
|
|
158
|
+
writeFileSync(file, source.startsWith('//') ? source : `// ${entry.title} — from ${registry}/${entry.file ?? `${name}.ts`}\n${source}`)
|
|
159
|
+
console.log(`${green('add')} ${relative(cwd, file)}`)
|
|
160
|
+
added.push({ name, file })
|
|
161
|
+
}
|
|
162
|
+
if (!added.length) return
|
|
163
|
+
const rel = relative(cwd, dir).replace(/\\/g, '/')
|
|
164
|
+
const prefix = rel.startsWith('.') ? rel : `./${rel}`
|
|
165
|
+
console.log(`\n${bold('Use it:')}\n`)
|
|
166
|
+
for (const { name } of added) console.log(` ${cyan(`import ${identifier(name)} from '${prefix}/${name}'`)}`)
|
|
167
|
+
console.log(`\n createQikbar({ extensions: [${added.map((a) => identifier(a.name)).join(', ')}] })`)
|
|
168
|
+
if (!hasPackage(cwd)) console.log(`\n${dim('Extensions import from @qikbar/qikbar — install it with')} npm install @qikbar/qikbar`)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const HELP = `${bold('qikbar')} ${dim(version())} — add Qikbar extensions to your project
|
|
172
|
+
|
|
173
|
+
${bold('Usage')}
|
|
174
|
+
npx @qikbar/qikbar add <name...> Copy extensions into your project (or "all")
|
|
175
|
+
npx @qikbar/qikbar list List available extensions
|
|
176
|
+
npx @qikbar/qikbar info <name> Show details about an extension
|
|
177
|
+
|
|
178
|
+
${bold('Options')}
|
|
179
|
+
-d, --dir <path> Where to put extensions (default: src/qikbar/extensions,
|
|
180
|
+
or "extensionsDir" in qikbar.json)
|
|
181
|
+
-f, --force Overwrite existing files
|
|
182
|
+
--registry <url> Use another registry (or set QIKBAR_REGISTRY)
|
|
183
|
+
--json Machine-readable output for list
|
|
184
|
+
-h, --help Show this help
|
|
185
|
+
-v, --version Show the version
|
|
186
|
+
|
|
187
|
+
${dim('Registry: https://qikbar.com/extensions')}`
|
|
188
|
+
|
|
189
|
+
async function main() {
|
|
190
|
+
const { _: [command, ...rest], flags } = parseArgs(process.argv.slice(2))
|
|
191
|
+
const registry = (flags.registry ?? REGISTRY).replace(/\/$/, '')
|
|
192
|
+
if (flags.version) return console.log(version())
|
|
193
|
+
if (flags.help || !command || command === 'help') return console.log(HELP)
|
|
194
|
+
if (command === 'add' || command === 'install') return cmdAdd(rest, flags, registry)
|
|
195
|
+
if (command === 'list' || command === 'ls') return cmdList(flags, registry)
|
|
196
|
+
if (command === 'info' || command === 'show') return cmdInfo(rest, registry)
|
|
197
|
+
throw new Error(`Unknown command "${command}". Run \`qikbar --help\`.`)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
main().catch((err) => {
|
|
201
|
+
console.error(red('error'), err.message)
|
|
202
|
+
process.exit(1)
|
|
203
|
+
})
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Embedding functions for `semantic` search. Each returns an `embed(texts)`
|
|
3
|
+
* function you pass as `semantic: { embed }`.
|
|
4
|
+
*
|
|
5
|
+
* Calling a provider straight from the browser exposes its key. In production,
|
|
6
|
+
* use `proxyEmbeddings()` with `createEmbeddingsHandler()` from `@qikbar/qikbar/server`.
|
|
7
|
+
*/
|
|
8
|
+
import type { SemanticOptions } from '../core/types.js';
|
|
9
|
+
export type Embed = SemanticOptions['embed'];
|
|
10
|
+
export interface OpenAIEmbeddingsOptions {
|
|
11
|
+
apiKey?: string;
|
|
12
|
+
/** Default `"text-embedding-3-small"`. */
|
|
13
|
+
model?: string;
|
|
14
|
+
/** For OpenAI-compatible APIs (Together, Mistral, LM Studio, …). Default `"https://api.openai.com/v1"`. */
|
|
15
|
+
baseURL?: string;
|
|
16
|
+
/** Shorter vectors are faster to compare. Default 256. */
|
|
17
|
+
dimensions?: number | null;
|
|
18
|
+
headers?: Record<string, string>;
|
|
19
|
+
fetch?: typeof fetch;
|
|
20
|
+
}
|
|
21
|
+
/** OpenAI (or any OpenAI-compatible) embeddings. */
|
|
22
|
+
export declare function openaiEmbeddings(options?: OpenAIEmbeddingsOptions): Embed;
|
|
23
|
+
export interface OllamaEmbeddingsOptions {
|
|
24
|
+
/** Default `"nomic-embed-text"`. */
|
|
25
|
+
model?: string;
|
|
26
|
+
/** Default `"http://localhost:11434"`. */
|
|
27
|
+
host?: string;
|
|
28
|
+
fetch?: typeof fetch;
|
|
29
|
+
}
|
|
30
|
+
/** Local embeddings with Ollama. */
|
|
31
|
+
export declare function ollamaEmbeddings(options?: OllamaEmbeddingsOptions): Embed;
|
|
32
|
+
export interface GeminiEmbeddingsOptions {
|
|
33
|
+
apiKey: string;
|
|
34
|
+
/** Default `"gemini-embedding-001"`. */
|
|
35
|
+
model?: string;
|
|
36
|
+
/** Default 256. */
|
|
37
|
+
dimensions?: number;
|
|
38
|
+
fetch?: typeof fetch;
|
|
39
|
+
}
|
|
40
|
+
/** Google Gemini embeddings. */
|
|
41
|
+
export declare function geminiEmbeddings(options: GeminiEmbeddingsOptions): Embed;
|
|
42
|
+
export interface ProxyEmbeddingsOptions {
|
|
43
|
+
/** Your endpoint made with `createEmbeddingsHandler()`. */
|
|
44
|
+
url: string;
|
|
45
|
+
headers?: Record<string, string>;
|
|
46
|
+
fetch?: typeof fetch;
|
|
47
|
+
}
|
|
48
|
+
/** Embeddings through your own server, so API keys never reach the browser. */
|
|
49
|
+
export declare function proxyEmbeddings(options: ProxyEmbeddingsOptions): Embed;
|
|
50
|
+
/** Wrap an embed function with a cache, so repeated texts aren't re-embedded. */
|
|
51
|
+
export declare function cachedEmbeddings(embed: Embed, maxEntries?: number): Embed;
|
package/dist/ai/index.d.ts
CHANGED
|
@@ -6,3 +6,7 @@ export { createAIClient, runAgent } from './agent.js';
|
|
|
6
6
|
export type { AgentEvent, RunAgentOptions, RuntimeTool } from './agent.js';
|
|
7
7
|
export { parseNDJSON, parseSSE } from './sse.js';
|
|
8
8
|
export type { AIClient, AIEvent, AIMessage, AIProvider, AIRequest, AIToolCall, AIToolDefinition } from '../core/types.js';
|
|
9
|
+
export { MCPClient, MCPError, mcp, MCP_PROTOCOL_VERSION } from './mcp.js';
|
|
10
|
+
export type { MCPOptions, MCPToolInfo } from './mcp.js';
|
|
11
|
+
export { cachedEmbeddings, geminiEmbeddings, ollamaEmbeddings, openaiEmbeddings, proxyEmbeddings } from './embeddings.js';
|
|
12
|
+
export type { Embed, GeminiEmbeddingsOptions, OllamaEmbeddingsOptions, OpenAIEmbeddingsOptions, ProxyEmbeddingsOptions } from './embeddings.js';
|
package/dist/ai/mcp.d.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A minimal MCP client (Streamable HTTP transport) that turns a remote MCP
|
|
3
|
+
* server's tools into tools the bar's AI can call.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { mcp } from '@qikbar/qikbar/ai'
|
|
7
|
+
* createQikbar({ ai: { provider, mcp: [mcp({ url: '/api/mcp' })] } })
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* Browsers can only reach servers that allow CORS. For third-party servers,
|
|
11
|
+
* proxy them through your backend (which also keeps tokens server-side).
|
|
12
|
+
*/
|
|
13
|
+
import type { JSONSchema, ToolProvider } from '../core/types.js';
|
|
14
|
+
export declare const MCP_PROTOCOL_VERSION = "2025-06-18";
|
|
15
|
+
export interface MCPOptions {
|
|
16
|
+
/** The server's Streamable HTTP endpoint. */
|
|
17
|
+
url: string;
|
|
18
|
+
/** Prefix for tool names and the label shown in errors. Default derived from the URL. */
|
|
19
|
+
name?: string;
|
|
20
|
+
/** Extra headers, e.g. `{ Authorization: 'Bearer …' }`. A function is called per request. */
|
|
21
|
+
headers?: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
|
|
22
|
+
/** Only expose these tools (by name). */
|
|
23
|
+
include?: string[];
|
|
24
|
+
/** Hide these tools (by name). */
|
|
25
|
+
exclude?: string[];
|
|
26
|
+
/**
|
|
27
|
+
* Ask the user before running a tool. Default: ask unless the server marks the tool
|
|
28
|
+
* `readOnlyHint: true`. Pass `true`/`false` to always/never ask, or a function per tool.
|
|
29
|
+
*/
|
|
30
|
+
confirm?: boolean | ((tool: MCPToolInfo) => boolean);
|
|
31
|
+
/** Re-list tools after this many ms. Default 5 minutes. */
|
|
32
|
+
ttl?: number;
|
|
33
|
+
/** Custom fetch (for tests or proxies). */
|
|
34
|
+
fetch?: typeof fetch;
|
|
35
|
+
/** Send cookies to the server (same-origin proxies). Default `"same-origin"`. */
|
|
36
|
+
credentials?: RequestCredentials;
|
|
37
|
+
}
|
|
38
|
+
export interface MCPToolInfo {
|
|
39
|
+
name: string;
|
|
40
|
+
title?: string;
|
|
41
|
+
description?: string;
|
|
42
|
+
inputSchema?: JSONSchema;
|
|
43
|
+
annotations?: {
|
|
44
|
+
title?: string;
|
|
45
|
+
readOnlyHint?: boolean;
|
|
46
|
+
destructiveHint?: boolean;
|
|
47
|
+
idempotentHint?: boolean;
|
|
48
|
+
openWorldHint?: boolean;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export declare class MCPError extends Error {
|
|
52
|
+
readonly code?: number | undefined;
|
|
53
|
+
constructor(message: string, code?: number | undefined);
|
|
54
|
+
}
|
|
55
|
+
/** A low-level MCP client. Most apps only need `mcp()`. */
|
|
56
|
+
export declare class MCPClient {
|
|
57
|
+
private options;
|
|
58
|
+
private session?;
|
|
59
|
+
private protocol;
|
|
60
|
+
private ready?;
|
|
61
|
+
private negotiated;
|
|
62
|
+
private nextId;
|
|
63
|
+
serverInfo?: {
|
|
64
|
+
name?: string;
|
|
65
|
+
version?: string;
|
|
66
|
+
};
|
|
67
|
+
constructor(options: MCPOptions);
|
|
68
|
+
private headers;
|
|
69
|
+
private post;
|
|
70
|
+
private request;
|
|
71
|
+
/** Initialize the session (once). */
|
|
72
|
+
connect(signal?: AbortSignal): Promise<void>;
|
|
73
|
+
/** List every tool, following pagination. */
|
|
74
|
+
listTools(signal?: AbortSignal): Promise<MCPToolInfo[]>;
|
|
75
|
+
/** Call a tool and return its result as text for the model. */
|
|
76
|
+
callTool(name: string, args: Record<string, unknown>, signal?: AbortSignal): Promise<string>;
|
|
77
|
+
/** End the session (best effort). */
|
|
78
|
+
close(): Promise<void>;
|
|
79
|
+
}
|
|
80
|
+
/** Use an MCP server's tools in the bar's AI chat. */
|
|
81
|
+
export declare function mcp(options: MCPOptions): ToolProvider & {
|
|
82
|
+
client: MCPClient;
|
|
83
|
+
refresh(): void;
|
|
84
|
+
};
|
package/dist/ai.js
CHANGED
|
@@ -1,36 +1,54 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
MCPClient,
|
|
3
|
+
MCPError,
|
|
4
|
+
MCP_PROTOCOL_VERSION,
|
|
5
|
+
byok,
|
|
6
|
+
mcp
|
|
7
|
+
} from "./chunks/chunk-24EBWTCF.js";
|
|
8
|
+
import {
|
|
9
|
+
createAIClient,
|
|
10
|
+
runAgent
|
|
11
|
+
} from "./chunks/chunk-N4Y2Z6YD.js";
|
|
4
12
|
import {
|
|
5
13
|
anthropic,
|
|
6
14
|
browserAI,
|
|
15
|
+
cachedEmbeddings,
|
|
7
16
|
gemini,
|
|
17
|
+
geminiEmbeddings,
|
|
8
18
|
ollama,
|
|
19
|
+
ollamaEmbeddings,
|
|
9
20
|
openai,
|
|
10
21
|
openaiCompatible,
|
|
22
|
+
openaiEmbeddings,
|
|
11
23
|
parseNDJSON,
|
|
12
24
|
parseSSE,
|
|
13
|
-
proxy
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
runAgent
|
|
18
|
-
} from "./chunks/chunk-N4Y2Z6YD.js";
|
|
19
|
-
import "./chunks/chunk-I77YSUJN.js";
|
|
25
|
+
proxy,
|
|
26
|
+
proxyEmbeddings
|
|
27
|
+
} from "./chunks/chunk-MRHKJ2FZ.js";
|
|
28
|
+
import "./chunks/chunk-INTEVQYK.js";
|
|
20
29
|
import "./chunks/chunk-YCVJQ7U3.js";
|
|
21
30
|
import "./chunks/chunk-MPTP2EWW.js";
|
|
22
31
|
export {
|
|
32
|
+
MCPClient,
|
|
33
|
+
MCPError,
|
|
34
|
+
MCP_PROTOCOL_VERSION,
|
|
23
35
|
anthropic,
|
|
24
36
|
browserAI,
|
|
25
37
|
byok,
|
|
38
|
+
cachedEmbeddings,
|
|
26
39
|
createAIClient,
|
|
27
40
|
gemini,
|
|
41
|
+
geminiEmbeddings,
|
|
42
|
+
mcp,
|
|
28
43
|
ollama,
|
|
44
|
+
ollamaEmbeddings,
|
|
29
45
|
openai,
|
|
30
46
|
openaiCompatible,
|
|
47
|
+
openaiEmbeddings,
|
|
31
48
|
parseNDJSON,
|
|
32
49
|
parseSSE,
|
|
33
50
|
proxy,
|
|
51
|
+
proxyEmbeddings,
|
|
34
52
|
runAgent
|
|
35
53
|
};
|
|
36
54
|
//# sourceMappingURL=ai.js.map
|