narai-primitives 2.1.0 → 2.1.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.
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* agent_resolver — locate a connector's CLI on disk via the canonical
|
|
3
|
-
*
|
|
3
|
+
* 5-step fallback every consumer (the hub, doc-wiki's wrappers, etc.) needs:
|
|
4
4
|
*
|
|
5
5
|
* 1. `<NAME>_AGENT_CLI` env var (operator escape hatch).
|
|
6
|
-
* 2.
|
|
6
|
+
* 2. **Bundled-self** — when narai-primitives is installed (npm install,
|
|
7
|
+
* npm link, or running from its own source tree), the canonical 2.x
|
|
8
|
+
* layout ships every connector CLI at
|
|
9
|
+
* `<narai-primitives root>/dist/connectors/<name>/cli.js`. The
|
|
10
|
+
* resolver derives that root from its own file path via
|
|
11
|
+
* `import.meta.url`, so the lookup works regardless of install layout.
|
|
12
|
+
* 3. `~/.claude/plugins/cache/<name>-agent-plugin*` — populated by Claude
|
|
7
13
|
* Code's plugin manager.
|
|
8
|
-
*
|
|
14
|
+
* 4. `${CLAUDE_PLUGIN_DATA}/node_modules/<package>/<cliRelativePath>` —
|
|
9
15
|
* where the connector's `SessionStart` hook installs it.
|
|
10
|
-
*
|
|
11
|
-
* developer-machine fallback
|
|
16
|
+
* 5. `~/src/connectors/<name>-agent-connector/<cliRelativePath>` — the
|
|
17
|
+
* legacy developer-machine fallback (kept for backward compat with
|
|
18
|
+
* pre-2.0 layouts).
|
|
12
19
|
*
|
|
13
20
|
* Returns null if no candidate exists, so callers can fail with a clear
|
|
14
21
|
* message instead of crashing on `spawn`.
|
|
@@ -26,12 +33,21 @@ export interface ResolveAgentCliOptions {
|
|
|
26
33
|
cliRelativePath?: string;
|
|
27
34
|
/** Dev-fallback root. Default: `~/src/connectors/`. */
|
|
28
35
|
devRoot?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Override the bundled-self search root. The default is computed from
|
|
38
|
+
* `import.meta.url` (the resolver's own file location) so the lookup
|
|
39
|
+
* works in any install layout. Pass `null` (explicit) to skip the
|
|
40
|
+
* bundled-self check entirely — useful for unit tests that want to
|
|
41
|
+
* exercise the lower fallback paths without colliding with the real
|
|
42
|
+
* bundled connector CLIs that ship next to this file.
|
|
43
|
+
*/
|
|
44
|
+
bundledSelfRoot?: string | null;
|
|
29
45
|
/** Override for `process.env`. Used by tests; production callers leave it alone. */
|
|
30
46
|
envOverride?: NodeJS.ProcessEnv;
|
|
31
47
|
/** Override for `os.homedir()`. Used by tests. */
|
|
32
48
|
homeOverride?: string;
|
|
33
49
|
}
|
|
34
|
-
export type ResolutionSource = "env" | "plugin-cache" | "claude-plugin-data" | "dev-fallback";
|
|
50
|
+
export type ResolutionSource = "env" | "bundled-self" | "plugin-cache" | "claude-plugin-data" | "dev-fallback";
|
|
35
51
|
export interface ResolvedAgentCli {
|
|
36
52
|
/** Always `"node"` — connector CLIs are always invoked through node. */
|
|
37
53
|
command: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent_resolver.d.ts","sourceRoot":"","sources":["../../src/toolkit/agent_resolver.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"agent_resolver.d.ts","sourceRoot":"","sources":["../../src/toolkit/agent_resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAOH,MAAM,WAAW,sBAAsB;IACrC,mEAAmE;IACnE,IAAI,EAAE,MAAM,CAAC;IACb,iGAAiG;IACjG,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,uGAAuG;IACvG,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,2FAA2F;IAC3F,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2DAA2D;IAC3D,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,uDAAuD;IACvD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,oFAAoF;IACpF,WAAW,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IAChC,kDAAkD;IAClD,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,MAAM,gBAAgB,GACxB,KAAK,GACL,cAAc,GACd,cAAc,GACd,oBAAoB,GACpB,cAAc,CAAC;AAEnB,MAAM,WAAW,gBAAgB;IAC/B,wEAAwE;IACxE,OAAO,EAAE,MAAM,CAAC;IAChB,6FAA6F;IAC7F,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,2EAA2E;IAC3E,MAAM,EAAE,gBAAgB,CAAC;IACzB,4CAA4C;IAC5C,YAAY,EAAE,MAAM,CAAC;CACtB;AAqCD,wBAAgB,eAAe,CAAC,IAAI,EAAE,sBAAsB,GAAG,gBAAgB,GAAG,IAAI,CA2ErF"}
|
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* agent_resolver — locate a connector's CLI on disk via the canonical
|
|
3
|
-
*
|
|
3
|
+
* 5-step fallback every consumer (the hub, doc-wiki's wrappers, etc.) needs:
|
|
4
4
|
*
|
|
5
5
|
* 1. `<NAME>_AGENT_CLI` env var (operator escape hatch).
|
|
6
|
-
* 2.
|
|
6
|
+
* 2. **Bundled-self** — when narai-primitives is installed (npm install,
|
|
7
|
+
* npm link, or running from its own source tree), the canonical 2.x
|
|
8
|
+
* layout ships every connector CLI at
|
|
9
|
+
* `<narai-primitives root>/dist/connectors/<name>/cli.js`. The
|
|
10
|
+
* resolver derives that root from its own file path via
|
|
11
|
+
* `import.meta.url`, so the lookup works regardless of install layout.
|
|
12
|
+
* 3. `~/.claude/plugins/cache/<name>-agent-plugin*` — populated by Claude
|
|
7
13
|
* Code's plugin manager.
|
|
8
|
-
*
|
|
14
|
+
* 4. `${CLAUDE_PLUGIN_DATA}/node_modules/<package>/<cliRelativePath>` —
|
|
9
15
|
* where the connector's `SessionStart` hook installs it.
|
|
10
|
-
*
|
|
11
|
-
* developer-machine fallback
|
|
16
|
+
* 5. `~/src/connectors/<name>-agent-connector/<cliRelativePath>` — the
|
|
17
|
+
* legacy developer-machine fallback (kept for backward compat with
|
|
18
|
+
* pre-2.0 layouts).
|
|
12
19
|
*
|
|
13
20
|
* Returns null if no candidate exists, so callers can fail with a clear
|
|
14
21
|
* message instead of crashing on `spawn`.
|
|
@@ -16,6 +23,7 @@
|
|
|
16
23
|
import * as fs from "node:fs";
|
|
17
24
|
import * as os from "node:os";
|
|
18
25
|
import * as path from "node:path";
|
|
26
|
+
import { fileURLToPath } from "node:url";
|
|
19
27
|
function defaultEnvVar(name) {
|
|
20
28
|
return `${name.toUpperCase().replace(/-/g, "_")}_AGENT_CLI`;
|
|
21
29
|
}
|
|
@@ -28,6 +36,25 @@ function defaultPackageName(name) {
|
|
|
28
36
|
function defaultDevRoot(home) {
|
|
29
37
|
return path.join(home, "src", "connectors");
|
|
30
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Derive narai-primitives' own package root from this file's location.
|
|
41
|
+
*
|
|
42
|
+
* Layout after build: `<package root>/dist/toolkit/agent_resolver.js`. Walking
|
|
43
|
+
* up two directories from `import.meta.url` lands on the package root in
|
|
44
|
+
* every install scenario (npm install, npm link, source dir).
|
|
45
|
+
*
|
|
46
|
+
* Returns `null` when the file URL can't be parsed — defensive only;
|
|
47
|
+
* shouldn't happen in any standard ESM runtime.
|
|
48
|
+
*/
|
|
49
|
+
function defaultBundledSelfRoot() {
|
|
50
|
+
try {
|
|
51
|
+
const here = fileURLToPath(import.meta.url);
|
|
52
|
+
return path.resolve(path.dirname(here), "..", "..");
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
31
58
|
export function resolveAgentCli(opts) {
|
|
32
59
|
const env = opts.envOverride ?? process.env;
|
|
33
60
|
const home = opts.homeOverride ?? os.homedir();
|
|
@@ -36,12 +63,30 @@ export function resolveAgentCli(opts) {
|
|
|
36
63
|
const packageName = opts.packageName ?? defaultPackageName(opts.name);
|
|
37
64
|
const cliRelative = opts.cliRelativePath ?? "dist/cli.js";
|
|
38
65
|
const devRoot = opts.devRoot ?? defaultDevRoot(home);
|
|
66
|
+
const bundledSelfRoot = opts.bundledSelfRoot === null
|
|
67
|
+
? null
|
|
68
|
+
: (opts.bundledSelfRoot ?? defaultBundledSelfRoot());
|
|
39
69
|
// 1. Explicit env-var override.
|
|
40
70
|
const envPath = env[envVar];
|
|
41
71
|
if (typeof envPath === "string" && envPath !== "" && fs.existsSync(envPath)) {
|
|
42
72
|
return { command: "node", args: [envPath], source: "env", resolvedPath: envPath };
|
|
43
73
|
}
|
|
44
|
-
// 2.
|
|
74
|
+
// 2. Bundled-self: the canonical 2.x layout ships every connector CLI at
|
|
75
|
+
// `<narai-primitives root>/dist/connectors/<name>/cli.js`. This is the
|
|
76
|
+
// primary path for any caller that has narai-primitives installed —
|
|
77
|
+
// npm install, npm link, or a source checkout all flow through here.
|
|
78
|
+
if (bundledSelfRoot !== null) {
|
|
79
|
+
const bundledCli = path.join(bundledSelfRoot, "dist", "connectors", opts.name, "cli.js");
|
|
80
|
+
if (fs.existsSync(bundledCli)) {
|
|
81
|
+
return {
|
|
82
|
+
command: "node",
|
|
83
|
+
args: [bundledCli],
|
|
84
|
+
source: "bundled-self",
|
|
85
|
+
resolvedPath: bundledCli,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// 3. Plugin cache lookup.
|
|
45
90
|
const pluginCache = path.join(home, ".claude", "plugins", "cache");
|
|
46
91
|
if (fs.existsSync(pluginCache)) {
|
|
47
92
|
let entries;
|
|
@@ -60,7 +105,7 @@ export function resolveAgentCli(opts) {
|
|
|
60
105
|
}
|
|
61
106
|
}
|
|
62
107
|
}
|
|
63
|
-
//
|
|
108
|
+
// 4. CLAUDE_PLUGIN_DATA install location.
|
|
64
109
|
const pluginData = env["CLAUDE_PLUGIN_DATA"];
|
|
65
110
|
if (typeof pluginData === "string" && pluginData !== "") {
|
|
66
111
|
const candidate = path.join(pluginData, "node_modules", packageName, cliRelative);
|
|
@@ -68,7 +113,7 @@ export function resolveAgentCli(opts) {
|
|
|
68
113
|
return { command: "node", args: [candidate], source: "claude-plugin-data", resolvedPath: candidate };
|
|
69
114
|
}
|
|
70
115
|
}
|
|
71
|
-
//
|
|
116
|
+
// 5. Dev fallback (legacy ~/src/connectors/<name>-agent-connector layout).
|
|
72
117
|
const devCandidate = path.join(devRoot, `${opts.name}-agent-connector`, cliRelative);
|
|
73
118
|
if (fs.existsSync(devCandidate)) {
|
|
74
119
|
return { command: "node", args: [devCandidate], source: "dev-fallback", resolvedPath: devCandidate };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent_resolver.js","sourceRoot":"","sources":["../../src/toolkit/agent_resolver.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"agent_resolver.js","sourceRoot":"","sources":["../../src/toolkit/agent_resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAgDzC,SAAS,aAAa,CAAC,IAAY;IACjC,OAAO,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,YAAY,CAAC;AAC9D,CAAC;AAED,SAAS,yBAAyB,CAAC,IAAY;IAC7C,OAAO,GAAG,IAAI,eAAe,CAAC;AAChC,CAAC;AAED,SAAS,kBAAkB,CAAC,IAAY;IACtC,OAAO,UAAU,IAAI,kBAAkB,CAAC;AAC1C,CAAC;AAED,SAAS,cAAc,CAAC,IAAY;IAClC,OAAO,IAAI,CAAC,IAAI,CAAC,IAA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|
"description": "Read-only connectors + planning hub + connector framework + credential resolution, in one package. Bundles what was @narai/connector-toolkit, @narai/connector-config, @narai/connector-hub, the seven @narai/<svc>-agent-connector packages, and @narai/credential-providers.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/hub/index.js",
|