@yaks/cli 0.0.0-stage → 0.2.36
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/LICENSE +202 -0
- package/README.md +1059 -2
- package/_dist/account-forward.d.ts +12 -0
- package/_dist/account-forward.d.ts.map +1 -0
- package/_dist/accounts.d.ts +23 -0
- package/_dist/accounts.d.ts.map +1 -0
- package/_dist/answer.d.ts +88 -0
- package/_dist/answer.d.ts.map +1 -0
- package/_dist/apply.d.ts +17 -0
- package/_dist/apply.d.ts.map +1 -0
- package/_dist/args.d.ts +86 -0
- package/_dist/args.d.ts.map +1 -0
- package/_dist/commands.d.ts +15 -0
- package/_dist/commands.d.ts.map +1 -0
- package/_dist/complete.d.ts +15 -0
- package/_dist/complete.d.ts.map +1 -0
- package/_dist/config.d.ts +37 -0
- package/_dist/config.d.ts.map +1 -0
- package/_dist/dependencies.d.ts +6 -0
- package/_dist/dependencies.d.ts.map +1 -0
- package/_dist/facets.d.ts +71 -0
- package/_dist/facets.d.ts.map +1 -0
- package/_dist/grammar.d.ts +5 -0
- package/_dist/grammar.d.ts.map +1 -0
- package/_dist/host.d.ts +164 -0
- package/_dist/host.d.ts.map +1 -0
- package/_dist/install.d.ts +43 -0
- package/_dist/install.d.ts.map +1 -0
- package/_dist/main.d.ts +16 -0
- package/_dist/main.d.ts.map +1 -0
- package/_dist/memo.d.ts +60 -0
- package/_dist/memo.d.ts.map +1 -0
- package/_dist/mod.d.ts +46 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/page.d.ts +73 -0
- package/_dist/page.d.ts.map +1 -0
- package/_dist/platform.d.ts +27 -0
- package/_dist/platform.d.ts.map +1 -0
- package/_dist/reader.d.ts +10 -0
- package/_dist/reader.d.ts.map +1 -0
- package/_dist/release.d.ts +48 -0
- package/_dist/release.d.ts.map +1 -0
- package/_dist/remote.d.ts +13 -0
- package/_dist/remote.d.ts.map +1 -0
- package/_dist/reported.d.ts +11 -0
- package/_dist/reported.d.ts.map +1 -0
- package/_dist/roles.d.ts +2 -0
- package/_dist/roles.d.ts.map +1 -0
- package/_dist/roster.d.ts +41 -0
- package/_dist/roster.d.ts.map +1 -0
- package/_dist/rpc.d.ts +29 -0
- package/_dist/rpc.d.ts.map +1 -0
- package/_dist/run.d.ts +164 -0
- package/_dist/run.d.ts.map +1 -0
- package/_dist/runtime.d.ts +4 -0
- package/_dist/runtime.d.ts.map +1 -0
- package/_dist/searching.d.ts +7 -0
- package/_dist/searching.d.ts.map +1 -0
- package/_dist/show.d.ts +22 -0
- package/_dist/show.d.ts.map +1 -0
- package/_dist/store.d.ts +25 -0
- package/_dist/store.d.ts.map +1 -0
- package/_dist/terminal.d.ts +17 -0
- package/_dist/terminal.d.ts.map +1 -0
- package/_dist/tool.d.ts +55 -0
- package/_dist/tool.d.ts.map +1 -0
- package/_dist/tty.d.ts +3 -0
- package/_dist/tty.d.ts.map +1 -0
- package/_dist/vault.d.ts +9 -0
- package/_dist/vault.d.ts.map +1 -0
- package/_dist/words.d.ts +11 -0
- package/_dist/words.d.ts.map +1 -0
- package/_dist/yak.d.ts +10 -0
- package/_dist/yak.d.ts.map +1 -0
- package/account-forward.js +40 -0
- package/account-forward.js.map +1 -0
- package/account-forward.ts +50 -0
- package/accounts.js +162 -0
- package/accounts.js.map +1 -0
- package/accounts.ts +228 -0
- package/answer.js +394 -0
- package/answer.js.map +1 -0
- package/answer.ts +569 -0
- package/apply.js +49 -0
- package/apply.js.map +1 -0
- package/apply.ts +54 -0
- package/args.js +420 -0
- package/args.js.map +1 -0
- package/args.ts +494 -0
- package/code.js +209 -0
- package/code.js.map +1 -0
- package/code.ts +227 -0
- package/commands.js +131 -0
- package/commands.js.map +1 -0
- package/commands.ts +142 -0
- package/complete.js +104 -0
- package/complete.js.map +1 -0
- package/complete.ts +152 -0
- package/config.js +125 -0
- package/config.js.map +1 -0
- package/config.ts +180 -0
- package/declarations.js +67 -0
- package/declarations.js.map +1 -0
- package/declarations.ts +84 -0
- package/deno.json +1 -0
- package/dependencies.js +126 -0
- package/dependencies.js.map +1 -0
- package/dependencies.ts +141 -0
- package/derive.js +102 -0
- package/derive.js.map +1 -0
- package/derive.ts +125 -0
- package/drain.js +83 -0
- package/drain.js.map +1 -0
- package/drain.ts +115 -0
- package/duties.ts +17 -0
- package/exports.json +1486 -0
- package/external.js +373 -0
- package/external.js.map +1 -0
- package/external.ts +435 -0
- package/facets.js +214 -0
- package/facets.js.map +1 -0
- package/facets.ts +232 -0
- package/feedback.js +54 -0
- package/feedback.js.map +1 -0
- package/feedback.ts +57 -0
- package/files.js +84 -0
- package/files.js.map +1 -0
- package/files.ts +112 -0
- package/get_starts.js +31 -0
- package/get_starts.js.map +1 -0
- package/get_starts.ts +34 -0
- package/git-credential.js +79 -0
- package/git-credential.js.map +1 -0
- package/git-credential.ts +77 -0
- package/grammar.js +4 -0
- package/grammar.js.map +1 -0
- package/grammar.ts +5 -0
- package/held.js +51 -0
- package/held.js.map +1 -0
- package/held.ts +66 -0
- package/host.js +1174 -0
- package/host.js.map +1 -0
- package/host.ts +1343 -0
- package/init.js +138 -0
- package/init.js.map +1 -0
- package/init.ts +139 -0
- package/install.js +216 -0
- package/install.js.map +1 -0
- package/install.ts +223 -0
- package/lifetime.js +56 -0
- package/lifetime.js.map +1 -0
- package/lifetime.ts +66 -0
- package/local-page.ts +114 -0
- package/local.js +417 -0
- package/local.js.map +1 -0
- package/local.ts +537 -0
- package/lockfile.js +20 -0
- package/lockfile.js.map +1 -0
- package/lockfile.ts +32 -0
- package/machines.js +33 -0
- package/machines.js.map +1 -0
- package/machines.ts +51 -0
- package/made/4f855610bdabcd736100d34e4e467ea5.json +1 -0
- package/main.js +534 -0
- package/main.js.map +1 -0
- package/main.ts +547 -0
- package/mcp.js +108 -0
- package/mcp.js.map +1 -0
- package/mcp.ts +113 -0
- package/member.js +103 -0
- package/member.js.map +1 -0
- package/member.ts +133 -0
- package/memo.js +503 -0
- package/memo.js.map +1 -0
- package/memo.ts +634 -0
- package/mod.js +46 -0
- package/mod.js.map +1 -0
- package/mod.ts +99 -0
- package/operations.js +53 -0
- package/operations.js.map +1 -0
- package/operations.ts +68 -0
- package/package.json +115 -4
- package/page.js +211 -0
- package/page.js.map +1 -0
- package/page.ts +308 -0
- package/parser.js +45 -0
- package/parser.js.map +1 -0
- package/parser.ts +77 -0
- package/people-search.js +112 -0
- package/people-search.js.map +1 -0
- package/people-search.ts +162 -0
- package/platform.js +184 -0
- package/platform.js.map +1 -0
- package/platform.ts +224 -0
- package/platform_effects.js +5 -0
- package/platform_effects.js.map +1 -0
- package/platform_effects.ts +13 -0
- package/prepare.js +40 -0
- package/prepare.js.map +1 -0
- package/prepare.ts +46 -0
- package/read_activity.js +54 -0
- package/read_activity.js.map +1 -0
- package/read_activity.ts +61 -0
- package/read_thread.js +387 -0
- package/read_thread.js.map +1 -0
- package/read_thread.ts +506 -0
- package/read_worker.ts +164 -0
- package/reader.js +48 -0
- package/reader.js.map +1 -0
- package/reader.ts +57 -0
- package/release.js +82 -0
- package/release.js.map +1 -0
- package/release.json +127 -0
- package/release.ts +98 -0
- package/remote-page.ts +70 -0
- package/remote.js +96 -0
- package/remote.js.map +1 -0
- package/remote.ts +153 -0
- package/report.js +83 -0
- package/report.js.map +1 -0
- package/report.ts +101 -0
- package/reported.js +32 -0
- package/reported.js.map +1 -0
- package/reported.ts +38 -0
- package/restart.js +349 -0
- package/restart.js.map +1 -0
- package/restart.ts +478 -0
- package/restore.js +32 -0
- package/restore.js.map +1 -0
- package/restore.ts +38 -0
- package/roles.js +32 -0
- package/roles.js.map +1 -0
- package/roles.ts +49 -0
- package/roster.js +65 -0
- package/roster.js.map +1 -0
- package/roster.ts +84 -0
- package/rpc.js +113 -0
- package/rpc.js.map +1 -0
- package/rpc.ts +159 -0
- package/run.js +533 -0
- package/run.js.map +1 -0
- package/run.ts +741 -0
- package/runtime.js +381 -0
- package/runtime.js.map +1 -0
- package/runtime.ts +433 -0
- package/sandboxes.js +26 -0
- package/sandboxes.js.map +1 -0
- package/sandboxes.ts +30 -0
- package/searching.js +33 -0
- package/searching.js.map +1 -0
- package/searching.ts +50 -0
- package/show.js +109 -0
- package/show.js.map +1 -0
- package/show.ts +144 -0
- package/shown.js +13 -0
- package/shown.js.map +1 -0
- package/shown.ts +44 -0
- package/stall.js +90 -0
- package/stall.js.map +1 -0
- package/stall.ts +156 -0
- package/stall_profile.js +113 -0
- package/stall_profile.js.map +1 -0
- package/stall_profile.ts +142 -0
- package/stall_wait.js +183 -0
- package/stall_wait.js.map +1 -0
- package/stall_wait.ts +249 -0
- package/stall_wait_worker.ts +11 -0
- package/start.js +349 -0
- package/start.js.map +1 -0
- package/start.ts +343 -0
- package/starvation.js +147 -0
- package/starvation.js.map +1 -0
- package/starvation.ts +224 -0
- package/store.js +118 -0
- package/store.js.map +1 -0
- package/store.ts +193 -0
- package/subcommands.js +62 -0
- package/subcommands.js.map +1 -0
- package/subcommands.ts +77 -0
- package/terminal.js +93 -0
- package/terminal.js.map +1 -0
- package/terminal.ts +128 -0
- package/text.js +20 -0
- package/text.js.map +1 -0
- package/text.ts +37 -0
- package/tool.js +76 -0
- package/tool.js.map +1 -0
- package/tool.ts +157 -0
- package/trace_control.js +231 -0
- package/trace_control.js.map +1 -0
- package/trace_control.ts +233 -0
- package/traces.js +138 -0
- package/traces.js.map +1 -0
- package/traces.ts +160 -0
- package/tracker.js +22 -0
- package/tracker.js.map +1 -0
- package/tracker.ts +27 -0
- package/tty.js +82 -0
- package/tty.js.map +1 -0
- package/tty.ts +142 -0
- package/unit_failure.js +178 -0
- package/unit_failure.js.map +1 -0
- package/unit_failure.ts +191 -0
- package/upkeep_thread.js +32 -0
- package/upkeep_thread.js.map +1 -0
- package/upkeep_thread.ts +35 -0
- package/upkeep_worker.ts +27 -0
- package/vault.js +186 -0
- package/vault.js.map +1 -0
- package/vault.ts +220 -0
- package/vocab-ids.js +63 -0
- package/vocab-ids.js.map +1 -0
- package/vocab-ids.ts +62 -0
- package/vocab.json +35 -0
- package/warm.js +138 -0
- package/warm.js.map +1 -0
- package/warm.ts +171 -0
- package/watch_revision.js +25 -0
- package/watch_revision.js.map +1 -0
- package/watch_revision.ts +30 -0
- package/words.js +29 -0
- package/words.js.map +1 -0
- package/words.ts +41 -0
- package/workspaces.js +40 -0
- package/workspaces.js.map +1 -0
- package/workspaces.ts +58 -0
- package/yak-unit-failure.conf +6 -0
- package/yak-unit-handoff.conf +2 -0
- package/yak.js +123 -0
- package/yak.js.map +1 -0
- package/yak.ts +136 -0
package/roster.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// The tool list a client is holding, and what a tool result tells it about
|
|
2
|
+
// that list.
|
|
3
|
+
//
|
|
4
|
+
// The CLI calls `tools/list` once and caches the result (store.ts), because
|
|
5
|
+
// listing on every command would double the round trips this program exists to
|
|
6
|
+
// make cheap. That leaves one question, which the roster answers (@yaks/mcp
|
|
7
|
+
// `roster.ts`, T-34277): is the list I am holding still current? Two signals
|
|
8
|
+
// answer it and both arrive for free — a tool result carrying the server's
|
|
9
|
+
// roster notice, and an `about` result naming a version this cache is not
|
|
10
|
+
// stamped with. Nothing here asks the server on purpose: asking costs a round
|
|
11
|
+
// trip. The list is asked for again past the cache only once `about` has said
|
|
12
|
+
// the one held is not current, or the held schema refuses a command line
|
|
13
|
+
// (run.ts).
|
|
14
|
+
//
|
|
15
|
+
// The roster notice is also not part of the tool's own output. It is news
|
|
16
|
+
// about this program, so `saidBy` separates it from the result: the caller
|
|
17
|
+
// prints it on stderr and stdout stays exactly what was asked for.
|
|
18
|
+
import { valueIn } from "@yaks/tools/value";
|
|
19
|
+
/** How @yaks/mcp's roster notice begins, which is how it is recognized. */ export let STALE = 'The tool list changed since you connected';
|
|
20
|
+
/** The tool's own output, and the roster notice the server added beside
|
|
21
|
+
* it. */ export let saidBy = (out)=>{
|
|
22
|
+
let blocks = (out.content ?? []).map((c)=>c.text ?? `[${c.type}]`);
|
|
23
|
+
let stale = blocks.find((b)=>b.startsWith(STALE));
|
|
24
|
+
return {
|
|
25
|
+
text: blocks.filter((b)=>b != stale).join('\n'),
|
|
26
|
+
...stale ? {
|
|
27
|
+
stale
|
|
28
|
+
} : {}
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
/** The roster version an `about` result names (workers/yak `tools.ts`), off
|
|
32
|
+
* the answer as data: its words are for a person. */ export let versionIn = (out)=>{
|
|
33
|
+
let result = out.structuredContent?.result;
|
|
34
|
+
let roster = Array.isArray(result) ? valueIn(result)?.roster : undefined;
|
|
35
|
+
let version = roster?.version;
|
|
36
|
+
return typeof version == 'string' ? version : undefined;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* The roster to keep after a result: the same one, or `null` — drop the cache
|
|
40
|
+
* and call `tools/list` again. Only an `about` naming the version the list is
|
|
41
|
+
* stamped with confirms it. A list nobody stamped may come from any release,
|
|
42
|
+
* however long ago it was listed, so `about` drops it too; the caller lists
|
|
43
|
+
* again at once and stamps that list with the version `about` named
|
|
44
|
+
* (platform.ts `printed`).
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* let about = {
|
|
48
|
+
* structuredContent: {
|
|
49
|
+
* result: [{
|
|
50
|
+
* entity: { eid: '$said' },
|
|
51
|
+
* output: { value: { roster: { version: '1a2b3c4d' } } },
|
|
52
|
+
* }],
|
|
53
|
+
* },
|
|
54
|
+
* }
|
|
55
|
+
* rosterAfter({ tools: [], version: '1a2b3c4d' }, 'about', about)
|
|
56
|
+
* // { tools: [], version: '1a2b3c4d' }
|
|
57
|
+
* rosterAfter({ tools: [] }, 'about', about)
|
|
58
|
+
* // null
|
|
59
|
+
* ```
|
|
60
|
+
*/ export let rosterAfter = (roster, name, out)=>{
|
|
61
|
+
if (saidBy(out).stale) return null;
|
|
62
|
+
let seen = name == 'about' ? versionIn(out) : undefined;
|
|
63
|
+
return !seen || roster.version == seen ? roster : null;
|
|
64
|
+
};
|
|
65
|
+
//# sourceMappingURL=roster.js.map
|
package/ro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O,IAAI,OAAO,SAAS;AACpD,EAAC"}
|
package/roster.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// The tool list a client is holding, and what a tool result tells it about
|
|
2
|
+
// that list.
|
|
3
|
+
//
|
|
4
|
+
// The CLI calls `tools/list` once and caches the result (store.ts), because
|
|
5
|
+
// listing on every command would double the round trips this program exists to
|
|
6
|
+
// make cheap. That leaves one question, which the roster answers (@yaks/mcp
|
|
7
|
+
// `roster.ts`, T-34277): is the list I am holding still current? Two signals
|
|
8
|
+
// answer it and both arrive for free — a tool result carrying the server's
|
|
9
|
+
// roster notice, and an `about` result naming a version this cache is not
|
|
10
|
+
// stamped with. Nothing here asks the server on purpose: asking costs a round
|
|
11
|
+
// trip. The list is asked for again past the cache only once `about` has said
|
|
12
|
+
// the one held is not current, or the held schema refuses a command line
|
|
13
|
+
// (run.ts).
|
|
14
|
+
//
|
|
15
|
+
// The roster notice is also not part of the tool's own output. It is news
|
|
16
|
+
// about this program, so `saidBy` separates it from the result: the caller
|
|
17
|
+
// prints it on stderr and stdout stays exactly what was asked for.
|
|
18
|
+
|
|
19
|
+
import { valueIn } from '@yaks/tools/value'
|
|
20
|
+
import type { Roster } from './store.ts'
|
|
21
|
+
|
|
22
|
+
/** A tool result, as much of it as this client reads. */
|
|
23
|
+
export type Result = {
|
|
24
|
+
content?: { type: string; text?: string }[]
|
|
25
|
+
structuredContent?: unknown
|
|
26
|
+
isError?: boolean
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** How @yaks/mcp's roster notice begins, which is how it is recognized. */
|
|
30
|
+
export let STALE = 'The tool list changed since you connected'
|
|
31
|
+
|
|
32
|
+
/** The tool's own output, and the roster notice the server added beside
|
|
33
|
+
* it. */
|
|
34
|
+
export let saidBy = (out: Result): { text: string; stale?: string } => {
|
|
35
|
+
let blocks = (out.content ?? []).map((c) => c.text ?? `[${c.type}]`)
|
|
36
|
+
let stale = blocks.find((b) => b.startsWith(STALE))
|
|
37
|
+
return {
|
|
38
|
+
text: blocks.filter((b) => b != stale).join('\n'),
|
|
39
|
+
...(stale ? { stale } : {}),
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The roster version an `about` result names (workers/yak `tools.ts`), off
|
|
44
|
+
* the answer as data: its words are for a person. */
|
|
45
|
+
export let versionIn = (out: Result): string | undefined => {
|
|
46
|
+
let result = (out.structuredContent as { result?: unknown } | undefined)
|
|
47
|
+
?.result
|
|
48
|
+
let roster = Array.isArray(result) ? valueIn(result)?.roster : undefined
|
|
49
|
+
let version = (roster as { version?: unknown } | undefined)?.version
|
|
50
|
+
return typeof version == 'string' ? version : undefined
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The roster to keep after a result: the same one, or `null` — drop the cache
|
|
55
|
+
* and call `tools/list` again. Only an `about` naming the version the list is
|
|
56
|
+
* stamped with confirms it. A list nobody stamped may come from any release,
|
|
57
|
+
* however long ago it was listed, so `about` drops it too; the caller lists
|
|
58
|
+
* again at once and stamps that list with the version `about` named
|
|
59
|
+
* (platform.ts `printed`).
|
|
60
|
+
*
|
|
61
|
+
* ```ts
|
|
62
|
+
* let about = {
|
|
63
|
+
* structuredContent: {
|
|
64
|
+
* result: [{
|
|
65
|
+
* entity: { eid: '$said' },
|
|
66
|
+
* output: { value: { roster: { version: '1a2b3c4d' } } },
|
|
67
|
+
* }],
|
|
68
|
+
* },
|
|
69
|
+
* }
|
|
70
|
+
* rosterAfter({ tools: [], version: '1a2b3c4d' }, 'about', about)
|
|
71
|
+
* // { tools: [], version: '1a2b3c4d' }
|
|
72
|
+
* rosterAfter({ tools: [] }, 'about', about)
|
|
73
|
+
* // null
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export let rosterAfter = (
|
|
77
|
+
roster: Roster,
|
|
78
|
+
name: string,
|
|
79
|
+
out: Result,
|
|
80
|
+
): Roster | null => {
|
|
81
|
+
if (saidBy(out).stale) return null
|
|
82
|
+
let seen = name == 'about' ? versionIn(out) : undefined
|
|
83
|
+
return !seen || roster.version == seen ? roster : null
|
|
84
|
+
}
|
package/rpc.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// The client half of MCP over Streamable HTTP, written out by hand: a client
|
|
2
|
+
// that only ever sends three requests — `initialize`, `tools/list`,
|
|
3
|
+
// `tools/call` — is smaller than the SDK that would answer them, and adds no
|
|
4
|
+
// dependency to somebody's `deno install`.
|
|
5
|
+
//
|
|
6
|
+
// One POST is one JSON-RPC request. The MCP server answers one at a time
|
|
7
|
+
// (@yaks/mcp `mount.ts`), and a graph can keep the connection's identity. So
|
|
8
|
+
// `initialize` is sent only when listing tools — where the protocol version is
|
|
9
|
+
// negotiated and cached beside the tool list (store.ts) — and a tool call made
|
|
10
|
+
// from a cached list costs a single round trip, which is what makes the CLI
|
|
11
|
+
// feel like a local program. A server that responds with an `mcp-session-id`
|
|
12
|
+
// gets it back on every request after that.
|
|
13
|
+
//
|
|
14
|
+
// A 401 is the one status code read for meaning: the server answers it with
|
|
15
|
+
// the `WWW-Authenticate` challenge an MCP client would follow into an OAuth
|
|
16
|
+
// flow, and this client has no browser to follow it with — so it prints the
|
|
17
|
+
// door's refusal, or a sign-in sentence when the door sends only a challenge.
|
|
18
|
+
import { forwarded } from "./account-forward.js";
|
|
19
|
+
/** The newest MCP protocol version this client supports. */ export let PROTOCOL = '2025-06-18';
|
|
20
|
+
/** The server said no: a transport failure, or a JSON-RPC error, whose
|
|
21
|
+
* code it carries. */ export class Refused extends Error {
|
|
22
|
+
code;
|
|
23
|
+
constructor(message, code){
|
|
24
|
+
super(message), this.code = code;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** Nobody is signed in — the message is the sentence to print. */ export class Unauthorized extends Error {
|
|
28
|
+
}
|
|
29
|
+
/** The header a command line names its session in, over HTTP and to a graph
|
|
30
|
+
* it opened itself (local.ts) alike. */ export let VIA = 'x-via';
|
|
31
|
+
// This machine's own server (`yak serve`) answers plain http, and nothing else
|
|
32
|
+
// is reached without TLS unless the line names the scheme.
|
|
33
|
+
let LOOPBACK = /^(localhost|127(\.\d{1,3}){3}|\[::1\])(:\d+)?(\/|$)/;
|
|
34
|
+
/** `yaks.app` → `https://yaks.app/mcp`, `localhost:5173` →
|
|
35
|
+
* `http://localhost:5173/mcp`; a full origin is used as given. */ export let doorUrl = (host)=>(/^https?:\/\//.test(host) ? host : `${LOOPBACK.test(host) ? 'http' : 'https'}://${host}`).replace(/\/+$/, '') + '/mcp';
|
|
36
|
+
// A Streamable HTTP server may send its response as a server-sent event
|
|
37
|
+
// rather than as JSON. Only the `data:` lines carry it, and there is only ever
|
|
38
|
+
// one response per request, so the frames are concatenated.
|
|
39
|
+
let eventData = (body)=>body.split('\n').filter((l)=>l.startsWith('data:')).map((l)=>l.slice(5).trim()).join('');
|
|
40
|
+
let SIGN_IN = 'not signed in — run `yak auth yaks.app`, or set YAKS_TOKEN';
|
|
41
|
+
/** A client of one MCP server. Request ids count up within the process; the
|
|
42
|
+
* session id, if the server issued one, is sent on every request after the
|
|
43
|
+
* response that carried it. */ export let rpc = (door)=>{
|
|
44
|
+
let go = door.fetch ?? ((r)=>fetch(r));
|
|
45
|
+
let platform = /^https:\/\/yaks\.app\/mcp(?:\?|$)/.test(door.url);
|
|
46
|
+
let n = 0;
|
|
47
|
+
let session = null;
|
|
48
|
+
return async (method, params = {})=>{
|
|
49
|
+
let token = typeof door.token == 'function' ? await door.token() : door.token;
|
|
50
|
+
if (platform && token && method == 'tools/call') {
|
|
51
|
+
let call = params;
|
|
52
|
+
params = {
|
|
53
|
+
...call,
|
|
54
|
+
_meta: {
|
|
55
|
+
'app.yaks/client': 'yak',
|
|
56
|
+
'app.yaks/machine': Deno.hostname(),
|
|
57
|
+
...call._meta
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
let { url, init } = forwarded(door.url, token, false, {
|
|
62
|
+
method: 'POST',
|
|
63
|
+
headers: {
|
|
64
|
+
'content-type': 'application/json',
|
|
65
|
+
accept: 'application/json, text/event-stream',
|
|
66
|
+
'mcp-protocol-version': PROTOCOL,
|
|
67
|
+
...token ? {
|
|
68
|
+
authorization: `Bearer ${token}`
|
|
69
|
+
} : {},
|
|
70
|
+
...door.via ? {
|
|
71
|
+
[VIA]: door.via
|
|
72
|
+
} : {},
|
|
73
|
+
...session ? {
|
|
74
|
+
'mcp-session-id': session
|
|
75
|
+
} : {},
|
|
76
|
+
...door.headers
|
|
77
|
+
},
|
|
78
|
+
body: JSON.stringify({
|
|
79
|
+
jsonrpc: '2.0',
|
|
80
|
+
id: ++n,
|
|
81
|
+
method,
|
|
82
|
+
params
|
|
83
|
+
})
|
|
84
|
+
});
|
|
85
|
+
let r = await go(new Request(url, init));
|
|
86
|
+
session ??= r.headers.get('mcp-session-id');
|
|
87
|
+
let text = await r.text();
|
|
88
|
+
let said = r.headers.get('content-type')?.includes('text/event-stream') ? eventData(text) : text;
|
|
89
|
+
let reply;
|
|
90
|
+
try {
|
|
91
|
+
reply = JSON.parse(said);
|
|
92
|
+
} catch {
|
|
93
|
+
if (r.status == 401) throw new Unauthorized(SIGN_IN);
|
|
94
|
+
throw new Refused(`${door.url} said ${r.status} and not JSON: ${text.slice(0, 200)}`);
|
|
95
|
+
}
|
|
96
|
+
if (r.status == 401) {
|
|
97
|
+
throw new Unauthorized(typeof reply?.error?.code == 'string' && typeof reply.error.message == 'string' ? reply.error.message : SIGN_IN);
|
|
98
|
+
}
|
|
99
|
+
if (reply.error) throw new Refused(reply.error.message, reply.error.code);
|
|
100
|
+
if (!reply.result) throw new Refused(`${door.url} said ${r.status}`);
|
|
101
|
+
return reply.result;
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
/** The `initialize` handshake, sent before listing tools: it returns what the
|
|
105
|
+
* server calls itself and which protocol version it agreed to. */ export let initialize = async (ask)=>await ask('initialize', {
|
|
106
|
+
protocolVersion: PROTOCOL,
|
|
107
|
+
capabilities: {},
|
|
108
|
+
clientInfo: {
|
|
109
|
+
name: 'yak',
|
|
110
|
+
version: '0.0.0'
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
//# sourceMappingURL=rpc.js.map
|
package/rpc.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc.js","sources":["./rpc.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,oEAAoE;AACpE,6EAA6E;AAC7E,2CAA2C;AAC3C,EAAE;AACF,yEAAyE;AACzE,6EAA6E;AAC7E,+EAA+E;AAC/E,+EAA+E;AAC/E,4EAA4E;AAC5E,6EAA6E;AAC7E,4CAA4C;AAC5C,EAAE;AACF,4EAA4E;AAC5E,4EAA4E;AAC5E,4EAA4E;AAC5E,8EAA8E;AAE9E,SAAS,SAAS,+BAA8B;AAEhD,0DAA0D,GAC1D,OAAO,IAAI,WAAW,aAAY;AAElC;oBACoB,GACpB,OAAO,MAAM,gBAAgB;;EAC3B,YAAY,OAAe,EAAE,AAAS,IAAsB,CAAE;IAC5D,KAAK,CAAC,eAD8B,OAAA;EAEtC;AACF;AAEA,gEAAgE,GAChE,OAAO,MAAM,qBAAqB;AAAO;AAEzC;sCACsC,GACtC,OAAO,IAAI,MAAM,QAAO;AAwBxB,+EAA+E;AAC/E,2DAA2D;AAC3D,IAAI,WAAW;AAEf;gEACgE,GAChE,OAAO,IAAI,UAAU,CAAC,OACpB,CAAC,eAAe,IAAI,CAAC,QACjB,OACA,GAAG,SAAS,IAAI,CAAC,QAAQ,SAAS,QAAQ,GAAG,EAAE,MAAM,EACtD,OAAO,CAAC,QAAQ,MAAM,OAAM;AAEjC,wEAAwE;AACxE,+EAA+E;AAC/E,4DAA4D;AAC5D,IAAI,YAAY,CAAC,OACf,KAAK,KAAK,CAAC,MACR,MAAM,CAAC,CAAC,IAAM,EAAE,UAAU,CAAC,UAC3B,GAAG,CAAC,CAAC,IAAM,EAAE,KAAK,CAAC,GAAG,IAAI,IAC1B,IAAI,CAA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I;IAIJ,IAAI;MACF,QAAQ,KAAK,KAAK,CAAC;IACrB,EAAE,OAAM;MACN,IAAI,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,aAAa;MAC5C,MAAM,IAAI,QACR,GAAG,KAAK,GAAG,CAAC,MAAM,EAAE,EAAE,MAAM,CAAC,eAAe,EAAE,KAAK,KAAK,CAAC,GAAG,MAAM;IAEtE;IACA,IAAI,EAAE,MAAM,IAAI,KAAK;MACnB,MAAM,IAAI,aACR,OAAO,OAAO,OAAO,QAAQ,YAC3B,OAAO,MAAM,KAAK,CAAC,OAAO,IAAI,WAC5B,MAAM,KAAK,CAAC,OAAO,GACnB;IAER;IACA,IAAI,MAAM,KAAK,EAAE,MAAM,IAAI,QAAQ,MAAM,KAAK,CAAC,OAAO,EAAE,MAAM,KAAK,CAAC,IAAI;IACxE,IAAI,CAAC,MAAM,MAAM,EAAE,MAAM,IAAI,QAAQ,GAAG,KAAK,GAAG,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE;IACnE,OAAO,MAAM,MAAM;EACrB;AACF,EAAC;AAED;gEACgE,GAChE,OAAO,IAAI,aAAa,OAAO,MAC7B,MAAM,IAAI,cAAc;IACtB,iBAAiB;IACjB,cAAc,CAAC;IACf,YAAY;MAAE,MAAM;MAAO,SAAS;IAAQ;EAC9C,GAAE"}
|
package/rpc.ts
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// The client half of MCP over Streamable HTTP, written out by hand: a client
|
|
2
|
+
// that only ever sends three requests — `initialize`, `tools/list`,
|
|
3
|
+
// `tools/call` — is smaller than the SDK that would answer them, and adds no
|
|
4
|
+
// dependency to somebody's `deno install`.
|
|
5
|
+
//
|
|
6
|
+
// One POST is one JSON-RPC request. The MCP server answers one at a time
|
|
7
|
+
// (@yaks/mcp `mount.ts`), and a graph can keep the connection's identity. So
|
|
8
|
+
// `initialize` is sent only when listing tools — where the protocol version is
|
|
9
|
+
// negotiated and cached beside the tool list (store.ts) — and a tool call made
|
|
10
|
+
// from a cached list costs a single round trip, which is what makes the CLI
|
|
11
|
+
// feel like a local program. A server that responds with an `mcp-session-id`
|
|
12
|
+
// gets it back on every request after that.
|
|
13
|
+
//
|
|
14
|
+
// A 401 is the one status code read for meaning: the server answers it with
|
|
15
|
+
// the `WWW-Authenticate` challenge an MCP client would follow into an OAuth
|
|
16
|
+
// flow, and this client has no browser to follow it with — so it prints the
|
|
17
|
+
// door's refusal, or a sign-in sentence when the door sends only a challenge.
|
|
18
|
+
|
|
19
|
+
import { forwarded } from './account-forward.js'
|
|
20
|
+
|
|
21
|
+
/** The newest MCP protocol version this client supports. */
|
|
22
|
+
export let PROTOCOL = '2025-06-18'
|
|
23
|
+
|
|
24
|
+
/** The server said no: a transport failure, or a JSON-RPC error, whose
|
|
25
|
+
* code it carries. */
|
|
26
|
+
export class Refused extends Error {
|
|
27
|
+
constructor(message: string, readonly code?: number | string) {
|
|
28
|
+
super(message)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Nobody is signed in — the message is the sentence to print. */
|
|
33
|
+
export class Unauthorized extends Error {}
|
|
34
|
+
|
|
35
|
+
/** The header a command line names its session in, over HTTP and to a graph
|
|
36
|
+
* it opened itself (local.ts) alike. */
|
|
37
|
+
export let VIA = 'x-via'
|
|
38
|
+
|
|
39
|
+
/** Where to call and as whom: the `/mcp` URL, the bearer token, the session
|
|
40
|
+
* this command speaks for, and the `fetch` to use (a test passes a handler, so
|
|
41
|
+
* nothing here needs a socket). */
|
|
42
|
+
export type Door = {
|
|
43
|
+
url: string
|
|
44
|
+
token?: string | null | (() => string | null | Promise<string | null>)
|
|
45
|
+
/** the session this command line is part of, sent on the `x-via` header —
|
|
46
|
+
* it records what wrote something, and is never a credential. A host that
|
|
47
|
+
* stores transcripts resolves it to that session and attributes the writes
|
|
48
|
+
* to it (@yaks/session/graph); one that does not ignores the header. */
|
|
49
|
+
via?: string | null
|
|
50
|
+
/** more headers sent on every request */
|
|
51
|
+
headers?: Record<string, string>
|
|
52
|
+
fetch?: (request: Request) => Response | Promise<Response>
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Send one JSON-RPC method and return its result. */
|
|
56
|
+
export type Rpc = (
|
|
57
|
+
method: string,
|
|
58
|
+
params?: unknown,
|
|
59
|
+
) => Promise<Record<string, unknown>>
|
|
60
|
+
|
|
61
|
+
// This machine's own server (`yak serve`) answers plain http, and nothing else
|
|
62
|
+
// is reached without TLS unless the line names the scheme.
|
|
63
|
+
let LOOPBACK = /^(localhost|127(\.\d{1,3}){3}|\[::1\])(:\d+)?(\/|$)/
|
|
64
|
+
|
|
65
|
+
/** `yaks.app` → `https://yaks.app/mcp`, `localhost:5173` →
|
|
66
|
+
* `http://localhost:5173/mcp`; a full origin is used as given. */
|
|
67
|
+
export let doorUrl = (host: string): string =>
|
|
68
|
+
(/^https?:\/\//.test(host)
|
|
69
|
+
? host
|
|
70
|
+
: `${LOOPBACK.test(host) ? 'http' : 'https'}://${host}`)
|
|
71
|
+
.replace(/\/+$/, '') + '/mcp'
|
|
72
|
+
|
|
73
|
+
// A Streamable HTTP server may send its response as a server-sent event
|
|
74
|
+
// rather than as JSON. Only the `data:` lines carry it, and there is only ever
|
|
75
|
+
// one response per request, so the frames are concatenated.
|
|
76
|
+
let eventData = (body: string): string =>
|
|
77
|
+
body.split('\n')
|
|
78
|
+
.filter((l) => l.startsWith('data:'))
|
|
79
|
+
.map((l) => l.slice(5).trim())
|
|
80
|
+
.join('')
|
|
81
|
+
|
|
82
|
+
let SIGN_IN = 'not signed in — run `yak auth yaks.app`, or set YAKS_TOKEN'
|
|
83
|
+
|
|
84
|
+
/** A client of one MCP server. Request ids count up within the process; the
|
|
85
|
+
* session id, if the server issued one, is sent on every request after the
|
|
86
|
+
* response that carried it. */
|
|
87
|
+
export let rpc = (door: Door): Rpc => {
|
|
88
|
+
let go = door.fetch ?? ((r: Request) => fetch(r))
|
|
89
|
+
let platform = /^https:\/\/yaks\.app\/mcp(?:\?|$)/.test(door.url)
|
|
90
|
+
let n = 0
|
|
91
|
+
let session: string | null = null
|
|
92
|
+
return async (method, params = {}) => {
|
|
93
|
+
let token = typeof door.token == 'function'
|
|
94
|
+
? await door.token()
|
|
95
|
+
: door.token
|
|
96
|
+
if (platform && token && method == 'tools/call') {
|
|
97
|
+
let call = params as { _meta?: Record<string, unknown> }
|
|
98
|
+
params = {
|
|
99
|
+
...call,
|
|
100
|
+
_meta: {
|
|
101
|
+
'app.yaks/client': 'yak',
|
|
102
|
+
'app.yaks/machine': Deno.hostname(),
|
|
103
|
+
...call._meta,
|
|
104
|
+
},
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
let { url, init } = forwarded(door.url, token, false, {
|
|
108
|
+
method: 'POST',
|
|
109
|
+
headers: {
|
|
110
|
+
'content-type': 'application/json',
|
|
111
|
+
accept: 'application/json, text/event-stream',
|
|
112
|
+
'mcp-protocol-version': PROTOCOL,
|
|
113
|
+
...(token ? { authorization: `Bearer ${token}` } : {}),
|
|
114
|
+
...(door.via ? { [VIA]: door.via } : {}),
|
|
115
|
+
...(session ? { 'mcp-session-id': session } : {}),
|
|
116
|
+
...door.headers,
|
|
117
|
+
},
|
|
118
|
+
body: JSON.stringify({ jsonrpc: '2.0', id: ++n, method, params }),
|
|
119
|
+
})
|
|
120
|
+
let r = await go(new Request(url, init))
|
|
121
|
+
session ??= r.headers.get('mcp-session-id')
|
|
122
|
+
let text = await r.text()
|
|
123
|
+
let said = r.headers.get('content-type')?.includes('text/event-stream')
|
|
124
|
+
? eventData(text)
|
|
125
|
+
: text
|
|
126
|
+
let reply: {
|
|
127
|
+
result?: Record<string, unknown>
|
|
128
|
+
error?: { code: number | string; message: string }
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
reply = JSON.parse(said)
|
|
132
|
+
} catch {
|
|
133
|
+
if (r.status == 401) throw new Unauthorized(SIGN_IN)
|
|
134
|
+
throw new Refused(
|
|
135
|
+
`${door.url} said ${r.status} and not JSON: ${text.slice(0, 200)}`,
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
if (r.status == 401) {
|
|
139
|
+
throw new Unauthorized(
|
|
140
|
+
typeof reply?.error?.code == 'string' &&
|
|
141
|
+
typeof reply.error.message == 'string'
|
|
142
|
+
? reply.error.message
|
|
143
|
+
: SIGN_IN,
|
|
144
|
+
)
|
|
145
|
+
}
|
|
146
|
+
if (reply.error) throw new Refused(reply.error.message, reply.error.code)
|
|
147
|
+
if (!reply.result) throw new Refused(`${door.url} said ${r.status}`)
|
|
148
|
+
return reply.result
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** The `initialize` handshake, sent before listing tools: it returns what the
|
|
153
|
+
* server calls itself and which protocol version it agreed to. */
|
|
154
|
+
export let initialize = async (ask: Rpc): Promise<Record<string, unknown>> =>
|
|
155
|
+
await ask('initialize', {
|
|
156
|
+
protocolVersion: PROTOCOL,
|
|
157
|
+
capabilities: {},
|
|
158
|
+
clientInfo: { name: 'yak', version: '0.0.0' },
|
|
159
|
+
})
|