@ottimis/jack-provider-sdk 0.4.0 → 0.7.0
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 +2 -2
- package/dist/cjs/host.js +38 -0
- package/dist/cjs/host.js.map +1 -0
- package/dist/cjs/index.js +9 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/profiles.js +29 -0
- package/dist/cjs/profiles.js.map +1 -0
- package/dist/host.d.ts +161 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +37 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +9 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/profiles.d.ts +130 -0
- package/dist/profiles.d.ts.map +1 -0
- package/dist/profiles.js +28 -0
- package/dist/profiles.js.map +1 -0
- package/dist/provider.d.ts +44 -0
- package/dist/provider.d.ts.map +1 -1
- package/dist/usage.d.ts +38 -10
- package/dist/usage.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/host.ts +159 -0
- package/src/index.ts +9 -1
- package/src/profiles.ts +142 -0
- package/src/provider.ts +44 -0
- package/src/usage.ts +38 -10
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# `@ottimis/jack-provider-sdk`
|
|
2
2
|
|
|
3
|
-
Plugin contract for AI provider integrations in
|
|
3
|
+
Plugin contract for AI provider integrations in Jack. Every package that drives an AI coding agent inside Jack — `jack-claude`, `jack-codex`, `jack-gemini`, future `jack-<name>` — depends on this SDK and exports a single `JackProvider` object that satisfies the contract here.
|
|
4
4
|
|
|
5
5
|
## What's in the box
|
|
6
6
|
|
|
@@ -41,7 +41,7 @@ export const myProvider: JackProvider = {
|
|
|
41
41
|
}
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
Step-by-step walkthrough (Pattern A vs Pattern B, capability matrix, knowledge context, gotchas): [`docs/implementing-a-provider.md`](./docs/implementing-a-provider.md). Full type reference lives in the JSDoc on each exported type.
|
|
45
45
|
|
|
46
46
|
## Versioning
|
|
47
47
|
|
package/dist/cjs/host.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Host primitives exposed to providers — handed in via
|
|
4
|
+
* {@link JackProvider.activate} so provider code never imports `electron`,
|
|
5
|
+
* `better-sqlite3`, or any other host-internal module directly.
|
|
6
|
+
*
|
|
7
|
+
* Why this exists
|
|
8
|
+
* ---------------
|
|
9
|
+
* In Jack v0.4.x the Claude provider reached into Electron (`safeStorage`,
|
|
10
|
+
* `BrowserWindow`, `session`) and Jack's settings table (`getSetting` /
|
|
11
|
+
* `setSetting`) to persist its login cookie. That breaks two goals:
|
|
12
|
+
*
|
|
13
|
+
* 1. **Out-of-tree packages.** A future `@third-party/jack-provider-foo`
|
|
14
|
+
* installed from npm shouldn't need to know about the host's storage
|
|
15
|
+
* layer or its windowing toolkit.
|
|
16
|
+
* 2. **Testability.** Provider unit tests on plain Node want a fake host
|
|
17
|
+
* that returns canned credentials, not a real `safeStorage`.
|
|
18
|
+
*
|
|
19
|
+
* `HostServices` is the contract that satisfies both: a tiny set of
|
|
20
|
+
* primitives the host implements once (with whatever it has — Electron in
|
|
21
|
+
* Jack's case, but a CLI host could use `keytar` + headless puppeteer)
|
|
22
|
+
* and providers consume through dependency injection.
|
|
23
|
+
*
|
|
24
|
+
* Surface stays intentionally small. New capabilities grow this file as
|
|
25
|
+
* specific providers need them — but the rule is "host-side knowledge
|
|
26
|
+
* doesn't leak out the SDK". A provider that needs deep host integration
|
|
27
|
+
* is a sign that the integration belongs in the host, not in the
|
|
28
|
+
* provider.
|
|
29
|
+
*
|
|
30
|
+
* Lifecycle
|
|
31
|
+
* ---------
|
|
32
|
+
* The host calls `provider.activate(host)` once during registration. The
|
|
33
|
+
* provider stores the `host` reference and uses it lazily — no host
|
|
34
|
+
* primitive may be invoked before activation. Methods that need the host
|
|
35
|
+
* must guard accordingly (typically by deferring all work to a closure).
|
|
36
|
+
*/
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
//# sourceMappingURL=host.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.js","sourceRoot":"","sources":["../../src/host.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -8,13 +8,19 @@
|
|
|
8
8
|
* (not on Jack's main process internals) and Jack stays free to evolve
|
|
9
9
|
* its host code without breaking provider authors.
|
|
10
10
|
*
|
|
11
|
-
* Re-exports cover
|
|
11
|
+
* Re-exports cover four layers:
|
|
12
12
|
* - `./backend` — neutral wire-shape contract (`AgentBackend`,
|
|
13
13
|
* `AgentQueryOptions`, `AgentSession`, …)
|
|
14
14
|
* - `./spawner` — process-spawning primitives shared by every backend
|
|
15
15
|
* (`ProcessSpawner`, `ProcessHandle`, `localSpawner`, …)
|
|
16
16
|
* - `./provider` — plugin-level contract (`JackProvider`,
|
|
17
17
|
* `CapabilityMatrix`, `ToolDescriptor`, `ProviderBranding`, …)
|
|
18
|
+
* - `./usage` — provider-owned billing/usage surface (`UsageApi`,
|
|
19
|
+
* `UsageMetric`, …)
|
|
20
|
+
* - `./host` — host primitives injected at activation
|
|
21
|
+
* (`HostServices`, `HostKvScope`, `HostAuthService`, …) — providers
|
|
22
|
+
* consume these via `JackProvider.activate(host)` instead of
|
|
23
|
+
* reaching into Electron / host internals directly.
|
|
18
24
|
*
|
|
19
25
|
* Companion runtime types from `@ottimis/jack-chat-core` (`NormalizedMessage`,
|
|
20
26
|
* `ClientToolHandler`, `ToolShape`, …) are re-exported through `./provider`
|
|
@@ -40,4 +46,6 @@ __exportStar(require("./backend"), exports);
|
|
|
40
46
|
__exportStar(require("./spawner"), exports);
|
|
41
47
|
__exportStar(require("./provider"), exports);
|
|
42
48
|
__exportStar(require("./usage"), exports);
|
|
49
|
+
__exportStar(require("./host"), exports);
|
|
50
|
+
__exportStar(require("./profiles"), exports);
|
|
43
51
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;;;;;;;;;;;;;;;;AAEH,4CAAyB;AACzB,4CAAyB;AACzB,6CAA0B;AAC1B,0CAAuB;AACvB,yCAAsB;AACtB,6CAA0B"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Profiles — multiple isolated identities for a single provider.
|
|
4
|
+
*
|
|
5
|
+
* A "profile" is an isolated config/identity directory the provider's runtime
|
|
6
|
+
* can be pointed at via an env var (Claude `CLAUDE_CONFIG_DIR`, Codex
|
|
7
|
+
* `CODEX_HOME`, Gemini `GEMINI_CONFIG_DIR`, …). Two profiles = two distinct
|
|
8
|
+
* accounts / login states / agent customizations / history sets, all running
|
|
9
|
+
* the same provider binary.
|
|
10
|
+
*
|
|
11
|
+
* The user-facing scenario this exists for: an employee with separate
|
|
12
|
+
* "claude-personal" and "claude-work" shell aliases that point CLAUDE_CONFIG_DIR
|
|
13
|
+
* at different folders. The host turns that into a first-class concept —
|
|
14
|
+
* choosable per session, with a default per workspace-agent slot — instead of
|
|
15
|
+
* making the user re-shell their alias every time they switch context.
|
|
16
|
+
*
|
|
17
|
+
* Provider opts in by:
|
|
18
|
+
* - declaring `capabilities.profiles = true`
|
|
19
|
+
* - implementing `JackProvider.profiles` with a {@link ProfilesApi}
|
|
20
|
+
* - injecting the right env var inside `applyProfile`
|
|
21
|
+
*
|
|
22
|
+
* Storage of the profile *list* lives on the host's per-provider kv (provider
|
|
23
|
+
* stores it via `host.kv` at activation time). Storage of the profile
|
|
24
|
+
* *content* (auth, sessions, agents, history) lives inside `configDir` on
|
|
25
|
+
* disk and is the runtime's concern, not the host's — Jack never reads or
|
|
26
|
+
* writes inside `configDir`.
|
|
27
|
+
*/
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
//# sourceMappingURL=profiles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profiles.js","sourceRoot":"","sources":["../../src/profiles.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG"}
|
package/dist/host.d.ts
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host primitives exposed to providers — handed in via
|
|
3
|
+
* {@link JackProvider.activate} so provider code never imports `electron`,
|
|
4
|
+
* `better-sqlite3`, or any other host-internal module directly.
|
|
5
|
+
*
|
|
6
|
+
* Why this exists
|
|
7
|
+
* ---------------
|
|
8
|
+
* In Jack v0.4.x the Claude provider reached into Electron (`safeStorage`,
|
|
9
|
+
* `BrowserWindow`, `session`) and Jack's settings table (`getSetting` /
|
|
10
|
+
* `setSetting`) to persist its login cookie. That breaks two goals:
|
|
11
|
+
*
|
|
12
|
+
* 1. **Out-of-tree packages.** A future `@third-party/jack-provider-foo`
|
|
13
|
+
* installed from npm shouldn't need to know about the host's storage
|
|
14
|
+
* layer or its windowing toolkit.
|
|
15
|
+
* 2. **Testability.** Provider unit tests on plain Node want a fake host
|
|
16
|
+
* that returns canned credentials, not a real `safeStorage`.
|
|
17
|
+
*
|
|
18
|
+
* `HostServices` is the contract that satisfies both: a tiny set of
|
|
19
|
+
* primitives the host implements once (with whatever it has — Electron in
|
|
20
|
+
* Jack's case, but a CLI host could use `keytar` + headless puppeteer)
|
|
21
|
+
* and providers consume through dependency injection.
|
|
22
|
+
*
|
|
23
|
+
* Surface stays intentionally small. New capabilities grow this file as
|
|
24
|
+
* specific providers need them — but the rule is "host-side knowledge
|
|
25
|
+
* doesn't leak out the SDK". A provider that needs deep host integration
|
|
26
|
+
* is a sign that the integration belongs in the host, not in the
|
|
27
|
+
* provider.
|
|
28
|
+
*
|
|
29
|
+
* Lifecycle
|
|
30
|
+
* ---------
|
|
31
|
+
* The host calls `provider.activate(host)` once during registration. The
|
|
32
|
+
* provider stores the `host` reference and uses it lazily — no host
|
|
33
|
+
* primitive may be invoked before activation. Methods that need the host
|
|
34
|
+
* must guard accordingly (typically by deferring all work to a closure).
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* Per-provider key/value store. Keys are namespaced automatically by the
|
|
38
|
+
* calling provider's id, so `kv.set('token', x)` from `claudeProvider`
|
|
39
|
+
* lands in a different bucket than the same call from `codexProvider`.
|
|
40
|
+
*
|
|
41
|
+
* Values are strings — callers serialize JSON / numbers / booleans
|
|
42
|
+
* themselves. `null` from `get` / `getSecret` means "no value stored",
|
|
43
|
+
* not "value is null"; explicit removal goes through `remove`.
|
|
44
|
+
*
|
|
45
|
+
* `setSecret` / `getSecret` route through the host's OS-level keychain
|
|
46
|
+
* encryption when available (Electron's `safeStorage`, `keytar`, etc.).
|
|
47
|
+
* `setSecret` MUST throw when no secure storage is available so providers
|
|
48
|
+
* never silently degrade to plaintext on unsupported systems.
|
|
49
|
+
*/
|
|
50
|
+
export type HostKvScope = {
|
|
51
|
+
/** Plain (unencrypted) read. */
|
|
52
|
+
get(key: string): string | null;
|
|
53
|
+
/** Plain (unencrypted) write. */
|
|
54
|
+
set(key: string, value: string): void;
|
|
55
|
+
/** Remove the value at `key`. Idempotent (no-op when the key is absent). */
|
|
56
|
+
remove(key: string): void;
|
|
57
|
+
/** Encrypted read. Returns `null` when the key is absent OR the host's secret store can't decrypt (e.g. user wiped keychain). */
|
|
58
|
+
getSecret(key: string): string | null;
|
|
59
|
+
/** Encrypted write. Throws when secure storage isn't available — providers should surface a clear error to the user, not fall back to plaintext. */
|
|
60
|
+
setSecret(key: string, value: string): void;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Options for {@link HostAuthService.openCookieLoginWindow}.
|
|
64
|
+
*
|
|
65
|
+
* The host opens a child auth window at `url` and polls the cookie jar
|
|
66
|
+
* until `cookieName` appears on `cookieDomain`. When the cookie shows up
|
|
67
|
+
* the host returns its value and closes the window.
|
|
68
|
+
*
|
|
69
|
+
* Each provider's auth flow lives in its own session partition so two
|
|
70
|
+
* providers can be "logged in" simultaneously without their cookies
|
|
71
|
+
* colliding in the host's shared cookie store.
|
|
72
|
+
*/
|
|
73
|
+
export type CookieLoginOptions = {
|
|
74
|
+
/** URL to open in the child window. */
|
|
75
|
+
url: string;
|
|
76
|
+
/** Name of the cookie the provider waits for (e.g. `'sessionKey'`). */
|
|
77
|
+
cookieName: string;
|
|
78
|
+
/** Cookie domain to scope the lookup (e.g. `'https://claude.ai'`). */
|
|
79
|
+
cookieDomain: string;
|
|
80
|
+
/**
|
|
81
|
+
* Storage partition string for session isolation. Convention:
|
|
82
|
+
* `persist:<provider-id>-<flow-name>` (e.g. `persist:claude-usage`).
|
|
83
|
+
* Different partition strings keep parallel logins independent.
|
|
84
|
+
*/
|
|
85
|
+
partition: string;
|
|
86
|
+
/** Window title shown in the OS chrome. Default: `'Connect'`. */
|
|
87
|
+
title?: string;
|
|
88
|
+
/** Hard timeout in milliseconds. Default: 5 minutes. */
|
|
89
|
+
timeoutMs?: number;
|
|
90
|
+
/** Window width in pixels. Default: 520. */
|
|
91
|
+
width?: number;
|
|
92
|
+
/** Window height in pixels. Default: 720. */
|
|
93
|
+
height?: number;
|
|
94
|
+
/**
|
|
95
|
+
* Optional parent window the host narrows internally to attach
|
|
96
|
+
* modality. Typed as `unknown` so the SDK doesn't depend on Electron.
|
|
97
|
+
*/
|
|
98
|
+
parentWindow?: unknown;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Result of a cookie-login flow.
|
|
102
|
+
*
|
|
103
|
+
* - `'success'` — cookie captured; `cookieValue` is the raw value.
|
|
104
|
+
* - `'cancelled'` — user closed the window before the cookie appeared.
|
|
105
|
+
* - `'timeout'` — `timeoutMs` elapsed without the cookie being set.
|
|
106
|
+
* - `'error'` — host couldn't open the window (e.g. running headless,
|
|
107
|
+
* no display server, partition rejected). Providers should surface
|
|
108
|
+
* `error` to the user as an actionable message.
|
|
109
|
+
*/
|
|
110
|
+
export type CookieLoginResult = {
|
|
111
|
+
kind: 'success';
|
|
112
|
+
cookieValue: string;
|
|
113
|
+
} | {
|
|
114
|
+
kind: 'cancelled';
|
|
115
|
+
} | {
|
|
116
|
+
kind: 'timeout';
|
|
117
|
+
} | {
|
|
118
|
+
kind: 'error';
|
|
119
|
+
error: string;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Auth primitives the host provides. Today only cookie-based login;
|
|
123
|
+
* OAuth / device-code flows can be added as future providers need them
|
|
124
|
+
* without breaking existing implementations (`HostAuthService` is an
|
|
125
|
+
* open-shape type — additions are purely additive).
|
|
126
|
+
*/
|
|
127
|
+
export type HostAuthService = {
|
|
128
|
+
/**
|
|
129
|
+
* Open a child window at the given URL and wait for the named cookie
|
|
130
|
+
* to appear. Used by providers whose login flow is "send the user to
|
|
131
|
+
* a web page, scrape the session cookie when they sign in".
|
|
132
|
+
*
|
|
133
|
+
* The host is responsible for: opening the window, polling cookies,
|
|
134
|
+
* closing the window when the cookie shows up (or the user cancels /
|
|
135
|
+
* times out), and isolating the session partition. The provider
|
|
136
|
+
* doesn't see Electron, BrowserWindow, or any windowing detail.
|
|
137
|
+
*/
|
|
138
|
+
openCookieLoginWindow(opts: CookieLoginOptions): Promise<CookieLoginResult>;
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* The bag of host services injected into a provider via
|
|
142
|
+
* {@link JackProvider.activate}. Providers store the reference and
|
|
143
|
+
* pull primitives lazily.
|
|
144
|
+
*
|
|
145
|
+
* Adding a new capability:
|
|
146
|
+
* 1. Define the new service interface in this file (or a sibling).
|
|
147
|
+
* 2. Add it as an optional field here so older providers that don't
|
|
148
|
+
* use it keep compiling.
|
|
149
|
+
* 3. Document the feature flag — providers that need the capability
|
|
150
|
+
* should guard with `if (!host.newCapability) return undefined`
|
|
151
|
+
* and the host implements it.
|
|
152
|
+
*
|
|
153
|
+
* Concrete services exposed today are documented in their own types.
|
|
154
|
+
*/
|
|
155
|
+
export type HostServices = {
|
|
156
|
+
/** Per-provider key/value store. Namespaced by provider id by the host. */
|
|
157
|
+
kv: HostKvScope;
|
|
158
|
+
/** Auth flow primitives (cookie login today; OAuth / device-code in the future). */
|
|
159
|
+
auth: HostAuthService;
|
|
160
|
+
};
|
|
161
|
+
//# sourceMappingURL=host.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,gCAAgC;IAChC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IAC/B,iCAAiC;IACjC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACrC,4EAA4E;IAC5E,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,iIAAiI;IACjI,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IACrC,oJAAoJ;IACpJ,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;CAC5C,CAAA;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,uCAAuC;IACvC,GAAG,EAAE,MAAM,CAAA;IACX,uEAAuE;IACvE,UAAU,EAAE,MAAM,CAAA;IAClB,sEAAsE;IACtE,YAAY,EAAE,MAAM,CAAA;IACpB;;;;OAIG;IACH,SAAS,EAAE,MAAM,CAAA;IACjB,iEAAiE;IACjE,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,wDAAwD;IACxD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,4CAA4C;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,6CAA6C;IAC7C,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,CAAA;AAED;;;;;;;;;GASG;AACH,MAAM,MAAM,iBAAiB,GACzB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GACxC;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,GACrB;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GACnB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAA;AAEpC;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B;;;;;;;;;OASG;IACH,qBAAqB,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAA;CAC5E,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,2EAA2E;IAC3E,EAAE,EAAE,WAAW,CAAA;IACf,oFAAoF;IACpF,IAAI,EAAE,eAAe,CAAA;CACtB,CAAA"}
|
package/dist/host.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host primitives exposed to providers — handed in via
|
|
3
|
+
* {@link JackProvider.activate} so provider code never imports `electron`,
|
|
4
|
+
* `better-sqlite3`, or any other host-internal module directly.
|
|
5
|
+
*
|
|
6
|
+
* Why this exists
|
|
7
|
+
* ---------------
|
|
8
|
+
* In Jack v0.4.x the Claude provider reached into Electron (`safeStorage`,
|
|
9
|
+
* `BrowserWindow`, `session`) and Jack's settings table (`getSetting` /
|
|
10
|
+
* `setSetting`) to persist its login cookie. That breaks two goals:
|
|
11
|
+
*
|
|
12
|
+
* 1. **Out-of-tree packages.** A future `@third-party/jack-provider-foo`
|
|
13
|
+
* installed from npm shouldn't need to know about the host's storage
|
|
14
|
+
* layer or its windowing toolkit.
|
|
15
|
+
* 2. **Testability.** Provider unit tests on plain Node want a fake host
|
|
16
|
+
* that returns canned credentials, not a real `safeStorage`.
|
|
17
|
+
*
|
|
18
|
+
* `HostServices` is the contract that satisfies both: a tiny set of
|
|
19
|
+
* primitives the host implements once (with whatever it has — Electron in
|
|
20
|
+
* Jack's case, but a CLI host could use `keytar` + headless puppeteer)
|
|
21
|
+
* and providers consume through dependency injection.
|
|
22
|
+
*
|
|
23
|
+
* Surface stays intentionally small. New capabilities grow this file as
|
|
24
|
+
* specific providers need them — but the rule is "host-side knowledge
|
|
25
|
+
* doesn't leak out the SDK". A provider that needs deep host integration
|
|
26
|
+
* is a sign that the integration belongs in the host, not in the
|
|
27
|
+
* provider.
|
|
28
|
+
*
|
|
29
|
+
* Lifecycle
|
|
30
|
+
* ---------
|
|
31
|
+
* The host calls `provider.activate(host)` once during registration. The
|
|
32
|
+
* provider stores the `host` reference and uses it lazily — no host
|
|
33
|
+
* primitive may be invoked before activation. Methods that need the host
|
|
34
|
+
* must guard accordingly (typically by deferring all work to a closure).
|
|
35
|
+
*/
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=host.js.map
|
package/dist/host.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.js","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG"}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,13 +7,19 @@
|
|
|
7
7
|
* (not on Jack's main process internals) and Jack stays free to evolve
|
|
8
8
|
* its host code without breaking provider authors.
|
|
9
9
|
*
|
|
10
|
-
* Re-exports cover
|
|
10
|
+
* Re-exports cover four layers:
|
|
11
11
|
* - `./backend` — neutral wire-shape contract (`AgentBackend`,
|
|
12
12
|
* `AgentQueryOptions`, `AgentSession`, …)
|
|
13
13
|
* - `./spawner` — process-spawning primitives shared by every backend
|
|
14
14
|
* (`ProcessSpawner`, `ProcessHandle`, `localSpawner`, …)
|
|
15
15
|
* - `./provider` — plugin-level contract (`JackProvider`,
|
|
16
16
|
* `CapabilityMatrix`, `ToolDescriptor`, `ProviderBranding`, …)
|
|
17
|
+
* - `./usage` — provider-owned billing/usage surface (`UsageApi`,
|
|
18
|
+
* `UsageMetric`, …)
|
|
19
|
+
* - `./host` — host primitives injected at activation
|
|
20
|
+
* (`HostServices`, `HostKvScope`, `HostAuthService`, …) — providers
|
|
21
|
+
* consume these via `JackProvider.activate(host)` instead of
|
|
22
|
+
* reaching into Electron / host internals directly.
|
|
17
23
|
*
|
|
18
24
|
* Companion runtime types from `@ottimis/jack-chat-core` (`NormalizedMessage`,
|
|
19
25
|
* `ClientToolHandler`, `ToolShape`, …) are re-exported through `./provider`
|
|
@@ -24,6 +30,8 @@ export * from './backend';
|
|
|
24
30
|
export * from './spawner';
|
|
25
31
|
export * from './provider';
|
|
26
32
|
export * from './usage';
|
|
33
|
+
export * from './host';
|
|
34
|
+
export * from './profiles';
|
|
27
35
|
/**
|
|
28
36
|
* Re-export of `NormalizedMessage` from chat-core so consumers don't need
|
|
29
37
|
* to depend on it directly when their only entrypoint into the wire shape
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA;AACvB,cAAc,QAAQ,CAAA;AACtB,cAAc,YAAY,CAAA;AAE1B;;;;;GAKG;AACH,YAAY,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -7,13 +7,19 @@
|
|
|
7
7
|
* (not on Jack's main process internals) and Jack stays free to evolve
|
|
8
8
|
* its host code without breaking provider authors.
|
|
9
9
|
*
|
|
10
|
-
* Re-exports cover
|
|
10
|
+
* Re-exports cover four layers:
|
|
11
11
|
* - `./backend` — neutral wire-shape contract (`AgentBackend`,
|
|
12
12
|
* `AgentQueryOptions`, `AgentSession`, …)
|
|
13
13
|
* - `./spawner` — process-spawning primitives shared by every backend
|
|
14
14
|
* (`ProcessSpawner`, `ProcessHandle`, `localSpawner`, …)
|
|
15
15
|
* - `./provider` — plugin-level contract (`JackProvider`,
|
|
16
16
|
* `CapabilityMatrix`, `ToolDescriptor`, `ProviderBranding`, …)
|
|
17
|
+
* - `./usage` — provider-owned billing/usage surface (`UsageApi`,
|
|
18
|
+
* `UsageMetric`, …)
|
|
19
|
+
* - `./host` — host primitives injected at activation
|
|
20
|
+
* (`HostServices`, `HostKvScope`, `HostAuthService`, …) — providers
|
|
21
|
+
* consume these via `JackProvider.activate(host)` instead of
|
|
22
|
+
* reaching into Electron / host internals directly.
|
|
17
23
|
*
|
|
18
24
|
* Companion runtime types from `@ottimis/jack-chat-core` (`NormalizedMessage`,
|
|
19
25
|
* `ClientToolHandler`, `ToolShape`, …) are re-exported through `./provider`
|
|
@@ -24,4 +30,6 @@ export * from './backend';
|
|
|
24
30
|
export * from './spawner';
|
|
25
31
|
export * from './provider';
|
|
26
32
|
export * from './usage';
|
|
33
|
+
export * from './host';
|
|
34
|
+
export * from './profiles';
|
|
27
35
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA;AACvB,cAAc,QAAQ,CAAA;AACtB,cAAc,YAAY,CAAA"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Profiles — multiple isolated identities for a single provider.
|
|
3
|
+
*
|
|
4
|
+
* A "profile" is an isolated config/identity directory the provider's runtime
|
|
5
|
+
* can be pointed at via an env var (Claude `CLAUDE_CONFIG_DIR`, Codex
|
|
6
|
+
* `CODEX_HOME`, Gemini `GEMINI_CONFIG_DIR`, …). Two profiles = two distinct
|
|
7
|
+
* accounts / login states / agent customizations / history sets, all running
|
|
8
|
+
* the same provider binary.
|
|
9
|
+
*
|
|
10
|
+
* The user-facing scenario this exists for: an employee with separate
|
|
11
|
+
* "claude-personal" and "claude-work" shell aliases that point CLAUDE_CONFIG_DIR
|
|
12
|
+
* at different folders. The host turns that into a first-class concept —
|
|
13
|
+
* choosable per session, with a default per workspace-agent slot — instead of
|
|
14
|
+
* making the user re-shell their alias every time they switch context.
|
|
15
|
+
*
|
|
16
|
+
* Provider opts in by:
|
|
17
|
+
* - declaring `capabilities.profiles = true`
|
|
18
|
+
* - implementing `JackProvider.profiles` with a {@link ProfilesApi}
|
|
19
|
+
* - injecting the right env var inside `applyProfile`
|
|
20
|
+
*
|
|
21
|
+
* Storage of the profile *list* lives on the host's per-provider kv (provider
|
|
22
|
+
* stores it via `host.kv` at activation time). Storage of the profile
|
|
23
|
+
* *content* (auth, sessions, agents, history) lives inside `configDir` on
|
|
24
|
+
* disk and is the runtime's concern, not the host's — Jack never reads or
|
|
25
|
+
* writes inside `configDir`.
|
|
26
|
+
*/
|
|
27
|
+
import type { AgentQueryOptions } from './backend';
|
|
28
|
+
/**
|
|
29
|
+
* One profile entry. `id` is host-generated and stable; the human edits
|
|
30
|
+
* `label` + `configDir` freely.
|
|
31
|
+
*
|
|
32
|
+
* `isDefault` is exclusive within a provider — exactly one profile carries
|
|
33
|
+
* the flag at any time. Provider implementations enforce that invariant in
|
|
34
|
+
* `update`/`create` (when `setDefault` is true, demote the previous default).
|
|
35
|
+
*/
|
|
36
|
+
export type ProviderProfile = {
|
|
37
|
+
/** Stable identifier — host-generated UUID; never edited by user. */
|
|
38
|
+
id: string;
|
|
39
|
+
/** User-facing display label ("Work", "Personal", …). */
|
|
40
|
+
label: string;
|
|
41
|
+
/** Absolute path to the runtime config dir on the host filesystem. */
|
|
42
|
+
configDir: string;
|
|
43
|
+
/** Exactly one profile per provider carries this flag. */
|
|
44
|
+
isDefault: boolean;
|
|
45
|
+
/** ISO 8601 — when the profile was first created in Jack's registry. */
|
|
46
|
+
createdAt: string;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Result of {@link ProfilesApi.probeProfile} — best-effort introspection of
|
|
50
|
+
* what's already stored under `configDir` so the UI can show the user
|
|
51
|
+
* "Connected as <X>" instead of an opaque path.
|
|
52
|
+
*
|
|
53
|
+
* Provider populates whichever fields it can read cheaply (no network
|
|
54
|
+
* round-trips) — fields it can't infer stay undefined.
|
|
55
|
+
*/
|
|
56
|
+
export type ProviderProfileProbe = {
|
|
57
|
+
/** True when the dir exists and looks like a valid runtime config. */
|
|
58
|
+
exists: boolean;
|
|
59
|
+
/** True when the dir contains usable credentials. Tri-state: false = present-but-invalid, undefined = N/A. */
|
|
60
|
+
authenticated?: boolean;
|
|
61
|
+
/** Human-readable identity hint (email, account label) when discoverable. */
|
|
62
|
+
accountLabel?: string;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Input shape for {@link ProfilesApi.create}. The `id` is host-generated by
|
|
66
|
+
* the provider implementation (typically `crypto.randomUUID()`); the caller
|
|
67
|
+
* supplies the human bits.
|
|
68
|
+
*/
|
|
69
|
+
export type CreateProfileInput = {
|
|
70
|
+
label: string;
|
|
71
|
+
configDir: string;
|
|
72
|
+
/** When true, the new profile becomes the default (demotes previous default). */
|
|
73
|
+
setDefault?: boolean;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Provider-owned profiles capability. Optional on {@link JackProvider} —
|
|
77
|
+
* absent = the provider's runtime always uses its implicit default config dir
|
|
78
|
+
* and the host hides every profiles-related affordance.
|
|
79
|
+
*/
|
|
80
|
+
export type ProfilesApi = {
|
|
81
|
+
/**
|
|
82
|
+
* Enumerate the registered profiles in stable order. Provider MUST seed
|
|
83
|
+
* a "Default" profile pointing at its implicit config dir on first call
|
|
84
|
+
* (lazy migration — preserves the user's existing setup without manual
|
|
85
|
+
* intervention).
|
|
86
|
+
*/
|
|
87
|
+
list(): Promise<ProviderProfile[]>;
|
|
88
|
+
/**
|
|
89
|
+
* Register a new profile. Provider generates the `id` and persists the
|
|
90
|
+
* row. Returns the freshly-created profile so the caller doesn't have to
|
|
91
|
+
* round-trip through `list()`.
|
|
92
|
+
*/
|
|
93
|
+
create(input: CreateProfileInput): Promise<ProviderProfile>;
|
|
94
|
+
/**
|
|
95
|
+
* Patch an existing profile. Empty patch = no-op. Setting `isDefault: true`
|
|
96
|
+
* demotes whichever profile currently holds the default flag.
|
|
97
|
+
*/
|
|
98
|
+
update(id: string, patch: Partial<Pick<ProviderProfile, 'label' | 'configDir' | 'isDefault'>>): Promise<ProviderProfile>;
|
|
99
|
+
/**
|
|
100
|
+
* Remove a profile by id. MUST refuse to remove the last remaining profile
|
|
101
|
+
* (the provider always needs a default to fall back to). MUST refuse to
|
|
102
|
+
* remove the default profile when other profiles exist — caller has to
|
|
103
|
+
* promote a replacement first.
|
|
104
|
+
*
|
|
105
|
+
* Note: this only removes the registry entry. Files inside `configDir`
|
|
106
|
+
* stay on disk untouched — destructive cleanup is the user's responsibility
|
|
107
|
+
* (we never `rm -rf` a directory the user gave us).
|
|
108
|
+
*/
|
|
109
|
+
remove(id: string): Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* Mutate spawn options in place to point the runtime at the chosen
|
|
112
|
+
* profile's `configDir`. Each provider injects its native env var
|
|
113
|
+
* (Claude: `CLAUDE_CONFIG_DIR`; Codex: `CODEX_HOME`; …) and any other
|
|
114
|
+
* spawn-time wiring the runtime needs.
|
|
115
|
+
*
|
|
116
|
+
* Called once per spawn by the host, after `applyKnowledgeContext` and
|
|
117
|
+
* `prepareSpawnOptions`. Unknown `profileId` MUST be a silent no-op
|
|
118
|
+
* (caller falls back to the implicit default behavior).
|
|
119
|
+
*/
|
|
120
|
+
applyProfile(options: AgentQueryOptions, profileId: string): Promise<void>;
|
|
121
|
+
/**
|
|
122
|
+
* Best-effort introspection of what's stored under `configDir` so the
|
|
123
|
+
* UI can show "Connected as X" / "Empty profile" hints. Provider returns
|
|
124
|
+
* what it can read cheaply (file presence, parsed credentials file) —
|
|
125
|
+
* no network calls. Optional: providers that can't introspect their
|
|
126
|
+
* own config dir omit this and the UI falls back to a path-only display.
|
|
127
|
+
*/
|
|
128
|
+
probeProfile?(configDir: string): Promise<ProviderProfileProbe>;
|
|
129
|
+
};
|
|
130
|
+
//# sourceMappingURL=profiles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profiles.d.ts","sourceRoot":"","sources":["../src/profiles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAElD;;;;;;;GAOG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,qEAAqE;IACrE,EAAE,EAAE,MAAM,CAAA;IACV,yDAAyD;IACzD,KAAK,EAAE,MAAM,CAAA;IACb,sEAAsE;IACtE,SAAS,EAAE,MAAM,CAAA;IACjB,0DAA0D;IAC1D,SAAS,EAAE,OAAO,CAAA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ities for a single provider.
|
|
3
|
+
*
|
|
4
|
+
* A "profile" is an isolated config/identity directory the provider's runtime
|
|
5
|
+
* can be pointed at via an env var (Claude `CLAUDE_CONFIG_DIR`, Codex
|
|
6
|
+
* `CODEX_HOME`, Gemini `GEMINI_CONFIG_DIR`, …). Two profiles = two distinct
|
|
7
|
+
* accounts / login states / agent customizations / history sets, all running
|
|
8
|
+
* the same provider binary.
|
|
9
|
+
*
|
|
10
|
+
* The user-facing scenario this exists for: an employee with separate
|
|
11
|
+
* "claude-personal" and "claude-work" shell aliases that point CLAUDE_CONFIG_DIR
|
|
12
|
+
* at different folders. The host turns that into a first-class concept —
|
|
13
|
+
* choosable per session, with a default per workspace-agent slot — instead of
|
|
14
|
+
* making the user re-shell their alias every time they switch context.
|
|
15
|
+
*
|
|
16
|
+
* Provider opts in by:
|
|
17
|
+
* - declaring `capabilities.profiles = true`
|
|
18
|
+
* - implementing `JackProvider.profiles` with a {@link ProfilesApi}
|
|
19
|
+
* - injecting the right env var inside `applyProfile`
|
|
20
|
+
*
|
|
21
|
+
* Storage of the profile *list* lives on the host's per-provider kv (provider
|
|
22
|
+
* stores it via `host.kv` at activation time). Storage of the profile
|
|
23
|
+
* *content* (auth, sessions, agents, history) lives inside `configDir` on
|
|
24
|
+
* disk and is the runtime's concern, not the host's — Jack never reads or
|
|
25
|
+
* writes inside `configDir`.
|
|
26
|
+
*/
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=profiles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profiles.js","sourceRoot":"","sources":["../src/profiles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG"}
|
package/dist/provider.d.ts
CHANGED
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
* it free of provider-specific imports.
|
|
17
17
|
*/
|
|
18
18
|
import type { AgentBackend, AgentPermissionMode, AgentQueryOptions, McpServerSpec } from './backend';
|
|
19
|
+
import type { HostServices } from './host';
|
|
20
|
+
import type { ProfilesApi } from './profiles';
|
|
19
21
|
import type { UsageApi } from './usage';
|
|
20
22
|
import type { ZodType } from 'zod';
|
|
21
23
|
import type { ClientToolHandler, NormalizedMessage, NormalizedToolRef, ProviderUserContentPolicy, ToolShape } from '@ottimis/jack-chat-core';
|
|
@@ -257,6 +259,17 @@ export type CapabilityMatrix = {
|
|
|
257
259
|
* usage bars and no Connect affordance is offered.
|
|
258
260
|
*/
|
|
259
261
|
usage: boolean;
|
|
262
|
+
/**
|
|
263
|
+
* Provider supports multiple isolated config/identity directories
|
|
264
|
+
* ("profiles") — distinct accounts, login states, agent customizations,
|
|
265
|
+
* and history sets all selectable per-session at runtime. When `true`,
|
|
266
|
+
* {@link JackProvider.profiles} MUST be defined; the host renders the
|
|
267
|
+
* profile picker UI and routes spawn-time `applyProfile` calls.
|
|
268
|
+
*
|
|
269
|
+
* When `false` the provider's runtime always uses its implicit default
|
|
270
|
+
* config dir; the host hides every profile-related affordance.
|
|
271
|
+
*/
|
|
272
|
+
profiles: boolean;
|
|
260
273
|
/**
|
|
261
274
|
* Permission modes the provider actually supports. Drives the
|
|
262
275
|
* Shift-Tab cycle in the renderer (`MessageInputBar`) and any
|
|
@@ -622,6 +635,37 @@ export type JackProvider = {
|
|
|
622
635
|
* decodes.
|
|
623
636
|
*/
|
|
624
637
|
usage?: UsageApi;
|
|
638
|
+
/**
|
|
639
|
+
* Multi-profile capability — multiple isolated config/identity dirs
|
|
640
|
+
* selectable per session. See {@link ProfilesApi}. Optional; when
|
|
641
|
+
* undefined `capabilities.profiles` MUST be `false` and the host hides
|
|
642
|
+
* every profile-related affordance. When defined, the host calls
|
|
643
|
+
* `applyProfile(options, profileId)` once per spawn so the provider can
|
|
644
|
+
* inject its native config-dir env var (Claude `CLAUDE_CONFIG_DIR`,
|
|
645
|
+
* Codex `CODEX_HOME`, …).
|
|
646
|
+
*/
|
|
647
|
+
profiles?: ProfilesApi;
|
|
648
|
+
/**
|
|
649
|
+
* Optional one-shot activation hook. Called once by the host during
|
|
650
|
+
* registration with a {@link HostServices} bag scoped to this
|
|
651
|
+
* provider's id (kv namespace, auth partition prefix). Providers that
|
|
652
|
+
* need host-side primitives (encrypted credential storage, child auth
|
|
653
|
+
* windows, …) store the `host` reference and use it lazily; providers
|
|
654
|
+
* that are pure (Codex, Gemini today) leave this undefined.
|
|
655
|
+
*
|
|
656
|
+
* Activation MUST be idempotent: calling `activate(host)` twice with
|
|
657
|
+
* the same host is allowed and should not duplicate state. Activation
|
|
658
|
+
* happens at registration time — well before any session spawns —
|
|
659
|
+
* but providers MUST NOT block on network or disk here. Defer all I/O
|
|
660
|
+
* to the methods that actually need it.
|
|
661
|
+
*
|
|
662
|
+
* The host calls `activate` synchronously enough that
|
|
663
|
+
* `provider.usage`, `provider.persistedPermissions`, etc. can read
|
|
664
|
+
* `host` from a closure / captured variable in subsequent invocations.
|
|
665
|
+
* Async work inside `activate` is OK but the host won't await it
|
|
666
|
+
* before exposing the provider — it's "fire and let it complete".
|
|
667
|
+
*/
|
|
668
|
+
activate?(host: HostServices): void | Promise<void>;
|
|
625
669
|
};
|
|
626
670
|
/**
|
|
627
671
|
* Provider-neutral spec for an in-process MCP server the host wants to
|
package/dist/provider.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AACpG,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AACvC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAClC,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,yBAAyB,EACzB,SAAS,EACV,MAAM,yBAAyB,CAAA;AAEhC,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AAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,sBAAsB,CAAA;IAC5B,SAAS,EAAE,sBAAsB,CAAA;IACjC,OAAO,EAAE,sBAAsB,CAAA;IAC/B,YAAY,EAAE,sBAAsB,CAAA;CACrC,CAAA;AAED;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,mBAAmB,CAAA;IAC/C,MAAM,CACJ,MAAM,EAAE,gBAAgB,EACxB,QAAQ,EAAE,kBAAkB,EAC5B,OAAO,EAAE,MAAM,EACf,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAA;IACV,GAAG,CACD,MAAM,EAAE,gBAAgB,EACxB,QAAQ,EAAE,kBAAkB,EAC5B,OAAO,EAAE,MAAM,EACf,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAA;CACX,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB;;;;;;;;;;OAUG;IACH,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/B,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC;QAClD,OAAO,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;QAC9C,OAAO,CAAC,EAAE,OAAO,CAAA;KAClB,CAAC,CAAA;CACH,CAAA"}
|
package/dist/usage.d.ts
CHANGED
|
@@ -176,28 +176,56 @@ export type UsageConnectContext = {
|
|
|
176
176
|
* Provider-owned usage capability. Optional on {@link JackProvider};
|
|
177
177
|
* absent = host hides the chip's "Connect" affordance and the
|
|
178
178
|
* capability flag is `false`.
|
|
179
|
+
*
|
|
180
|
+
* Multi-profile contract (SDK 0.7.0):
|
|
181
|
+
* Every account-level method accepts an optional `profileId`. Providers
|
|
182
|
+
* that ALSO declare `capabilities.profiles=true` MUST honor the param —
|
|
183
|
+
* different profile = different account = different credentials, polled
|
|
184
|
+
* independently. When omitted, the provider resolves to its DEFAULT
|
|
185
|
+
* profile (back-compat with hosts that don't yet thread profileId).
|
|
186
|
+
*
|
|
187
|
+
* Providers without profiles support (`capabilities.profiles=false`)
|
|
188
|
+
* MAY ignore the param and behave as if every call were singleton —
|
|
189
|
+
* the omission stays the canonical caller behavior, the param is just
|
|
190
|
+
* ignored.
|
|
191
|
+
*
|
|
192
|
+
* `formatSessionMetrics` stays profile-agnostic: per-session metrics
|
|
193
|
+
* derive from the live process's context tokens (already pinned to the
|
|
194
|
+
* session's profile via `applyProfile` at spawn time).
|
|
179
195
|
*/
|
|
180
196
|
export type UsageApi = {
|
|
181
|
-
/**
|
|
182
|
-
|
|
197
|
+
/**
|
|
198
|
+
* Current connection state — used for chip display + gating.
|
|
199
|
+
* Profile-aware: omit `profileId` to query the default profile.
|
|
200
|
+
*/
|
|
201
|
+
status(profileId?: string): Promise<UsageStatus>;
|
|
183
202
|
/**
|
|
184
203
|
* Open the provider's connect flow. Whatever modality the provider
|
|
185
204
|
* needs (login window, API-key picker, OAuth redirect) lives here.
|
|
205
|
+
* Profile-aware: omit `profileId` to bind credentials to the default
|
|
206
|
+
* profile. Different profileIds use isolated storage AND isolated
|
|
207
|
+
* login surfaces (e.g. distinct cookie partitions for Claude) so two
|
|
208
|
+
* accounts can sign in side by side.
|
|
186
209
|
*/
|
|
187
|
-
connect(ctx: UsageConnectContext): Promise<UsageConnectResult>;
|
|
210
|
+
connect(ctx: UsageConnectContext, profileId?: string): Promise<UsageConnectResult>;
|
|
188
211
|
/**
|
|
189
212
|
* When `connect()` returned `'choose'`, host calls this with the
|
|
190
213
|
* user's pick. Optional — providers that never choose omit it.
|
|
214
|
+
* Profile-aware: pass the SAME `profileId` you used for `connect()`.
|
|
215
|
+
*/
|
|
216
|
+
selectOption?(optionId: string, profileId?: string): Promise<UsageConnectResult>;
|
|
217
|
+
/**
|
|
218
|
+
* Drop credentials and stop any provider-side polling for the
|
|
219
|
+
* specified profile. Omit `profileId` to disconnect the default profile.
|
|
191
220
|
*/
|
|
192
|
-
|
|
193
|
-
/** Drop credentials and stop any provider-side polling. */
|
|
194
|
-
disconnect(): Promise<void>;
|
|
221
|
+
disconnect(profileId?: string): Promise<void>;
|
|
195
222
|
/**
|
|
196
|
-
* Fetch one fresh account-level snapshot
|
|
197
|
-
* fine when the provider has no billing surface
|
|
198
|
-
* stays `true` for the per-session bridge.
|
|
223
|
+
* Fetch one fresh account-level snapshot for the specified profile.
|
|
224
|
+
* Empty `metrics: []` is fine when the provider has no billing surface
|
|
225
|
+
* yet — the capability stays `true` for the per-session bridge.
|
|
226
|
+
* Omit `profileId` to fetch the default profile.
|
|
199
227
|
*/
|
|
200
|
-
fetch(): Promise<UsageSnapshot>;
|
|
228
|
+
fetch(profileId?: string): Promise<UsageSnapshot>;
|
|
201
229
|
/**
|
|
202
230
|
* Recommended poll cadence (seconds). Host clamps to its bounds.
|
|
203
231
|
* Optional — host falls back to its own default if unset.
|
package/dist/usage.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../src/usage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAElD;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG,gBAAgB,GAAG,sBAAsB,GAAG,kBAAkB,CAAA;AAExF;;;;;;;;GAQG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,aAAa,CAAA;IACnB,uFAAuF;IACvF,EAAE,EAAE,MAAM,CAAA;IACV,4EAA4E;IAC5E,KAAK,EAAE,MAAM,CAAA;IACb,oCAAoC;IACpC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Aa,CAAC,CAAA;IAEjD;;;OAGG;IACH,0BAA0B,CAAC,EAAE,MAAM,CAAA;IAEnC;;;;;;;;;;OAUG;IACH,oBAAoB,CAAC,CAAC,GAAG,EAAE,iBAAiB,GAAG,WAAW,EAAE,CAAA;CAC7D,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ottimis/jack-provider-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Plugin contract for AI provider integrations in Jack — backend interface, capability matrix, spawner primitives, knowledge context. Consumed both by in-tree providers and external packages.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
package/src/host.ts
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host primitives exposed to providers — handed in via
|
|
3
|
+
* {@link JackProvider.activate} so provider code never imports `electron`,
|
|
4
|
+
* `better-sqlite3`, or any other host-internal module directly.
|
|
5
|
+
*
|
|
6
|
+
* Why this exists
|
|
7
|
+
* ---------------
|
|
8
|
+
* In Jack v0.4.x the Claude provider reached into Electron (`safeStorage`,
|
|
9
|
+
* `BrowserWindow`, `session`) and Jack's settings table (`getSetting` /
|
|
10
|
+
* `setSetting`) to persist its login cookie. That breaks two goals:
|
|
11
|
+
*
|
|
12
|
+
* 1. **Out-of-tree packages.** A future `@third-party/jack-provider-foo`
|
|
13
|
+
* installed from npm shouldn't need to know about the host's storage
|
|
14
|
+
* layer or its windowing toolkit.
|
|
15
|
+
* 2. **Testability.** Provider unit tests on plain Node want a fake host
|
|
16
|
+
* that returns canned credentials, not a real `safeStorage`.
|
|
17
|
+
*
|
|
18
|
+
* `HostServices` is the contract that satisfies both: a tiny set of
|
|
19
|
+
* primitives the host implements once (with whatever it has — Electron in
|
|
20
|
+
* Jack's case, but a CLI host could use `keytar` + headless puppeteer)
|
|
21
|
+
* and providers consume through dependency injection.
|
|
22
|
+
*
|
|
23
|
+
* Surface stays intentionally small. New capabilities grow this file as
|
|
24
|
+
* specific providers need them — but the rule is "host-side knowledge
|
|
25
|
+
* doesn't leak out the SDK". A provider that needs deep host integration
|
|
26
|
+
* is a sign that the integration belongs in the host, not in the
|
|
27
|
+
* provider.
|
|
28
|
+
*
|
|
29
|
+
* Lifecycle
|
|
30
|
+
* ---------
|
|
31
|
+
* The host calls `provider.activate(host)` once during registration. The
|
|
32
|
+
* provider stores the `host` reference and uses it lazily — no host
|
|
33
|
+
* primitive may be invoked before activation. Methods that need the host
|
|
34
|
+
* must guard accordingly (typically by deferring all work to a closure).
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Per-provider key/value store. Keys are namespaced automatically by the
|
|
39
|
+
* calling provider's id, so `kv.set('token', x)` from `claudeProvider`
|
|
40
|
+
* lands in a different bucket than the same call from `codexProvider`.
|
|
41
|
+
*
|
|
42
|
+
* Values are strings — callers serialize JSON / numbers / booleans
|
|
43
|
+
* themselves. `null` from `get` / `getSecret` means "no value stored",
|
|
44
|
+
* not "value is null"; explicit removal goes through `remove`.
|
|
45
|
+
*
|
|
46
|
+
* `setSecret` / `getSecret` route through the host's OS-level keychain
|
|
47
|
+
* encryption when available (Electron's `safeStorage`, `keytar`, etc.).
|
|
48
|
+
* `setSecret` MUST throw when no secure storage is available so providers
|
|
49
|
+
* never silently degrade to plaintext on unsupported systems.
|
|
50
|
+
*/
|
|
51
|
+
export type HostKvScope = {
|
|
52
|
+
/** Plain (unencrypted) read. */
|
|
53
|
+
get(key: string): string | null
|
|
54
|
+
/** Plain (unencrypted) write. */
|
|
55
|
+
set(key: string, value: string): void
|
|
56
|
+
/** Remove the value at `key`. Idempotent (no-op when the key is absent). */
|
|
57
|
+
remove(key: string): void
|
|
58
|
+
/** Encrypted read. Returns `null` when the key is absent OR the host's secret store can't decrypt (e.g. user wiped keychain). */
|
|
59
|
+
getSecret(key: string): string | null
|
|
60
|
+
/** Encrypted write. Throws when secure storage isn't available — providers should surface a clear error to the user, not fall back to plaintext. */
|
|
61
|
+
setSecret(key: string, value: string): void
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Options for {@link HostAuthService.openCookieLoginWindow}.
|
|
66
|
+
*
|
|
67
|
+
* The host opens a child auth window at `url` and polls the cookie jar
|
|
68
|
+
* until `cookieName` appears on `cookieDomain`. When the cookie shows up
|
|
69
|
+
* the host returns its value and closes the window.
|
|
70
|
+
*
|
|
71
|
+
* Each provider's auth flow lives in its own session partition so two
|
|
72
|
+
* providers can be "logged in" simultaneously without their cookies
|
|
73
|
+
* colliding in the host's shared cookie store.
|
|
74
|
+
*/
|
|
75
|
+
export type CookieLoginOptions = {
|
|
76
|
+
/** URL to open in the child window. */
|
|
77
|
+
url: string
|
|
78
|
+
/** Name of the cookie the provider waits for (e.g. `'sessionKey'`). */
|
|
79
|
+
cookieName: string
|
|
80
|
+
/** Cookie domain to scope the lookup (e.g. `'https://claude.ai'`). */
|
|
81
|
+
cookieDomain: string
|
|
82
|
+
/**
|
|
83
|
+
* Storage partition string for session isolation. Convention:
|
|
84
|
+
* `persist:<provider-id>-<flow-name>` (e.g. `persist:claude-usage`).
|
|
85
|
+
* Different partition strings keep parallel logins independent.
|
|
86
|
+
*/
|
|
87
|
+
partition: string
|
|
88
|
+
/** Window title shown in the OS chrome. Default: `'Connect'`. */
|
|
89
|
+
title?: string
|
|
90
|
+
/** Hard timeout in milliseconds. Default: 5 minutes. */
|
|
91
|
+
timeoutMs?: number
|
|
92
|
+
/** Window width in pixels. Default: 520. */
|
|
93
|
+
width?: number
|
|
94
|
+
/** Window height in pixels. Default: 720. */
|
|
95
|
+
height?: number
|
|
96
|
+
/**
|
|
97
|
+
* Optional parent window the host narrows internally to attach
|
|
98
|
+
* modality. Typed as `unknown` so the SDK doesn't depend on Electron.
|
|
99
|
+
*/
|
|
100
|
+
parentWindow?: unknown
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Result of a cookie-login flow.
|
|
105
|
+
*
|
|
106
|
+
* - `'success'` — cookie captured; `cookieValue` is the raw value.
|
|
107
|
+
* - `'cancelled'` — user closed the window before the cookie appeared.
|
|
108
|
+
* - `'timeout'` — `timeoutMs` elapsed without the cookie being set.
|
|
109
|
+
* - `'error'` — host couldn't open the window (e.g. running headless,
|
|
110
|
+
* no display server, partition rejected). Providers should surface
|
|
111
|
+
* `error` to the user as an actionable message.
|
|
112
|
+
*/
|
|
113
|
+
export type CookieLoginResult =
|
|
114
|
+
| { kind: 'success'; cookieValue: string }
|
|
115
|
+
| { kind: 'cancelled' }
|
|
116
|
+
| { kind: 'timeout' }
|
|
117
|
+
| { kind: 'error'; error: string }
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Auth primitives the host provides. Today only cookie-based login;
|
|
121
|
+
* OAuth / device-code flows can be added as future providers need them
|
|
122
|
+
* without breaking existing implementations (`HostAuthService` is an
|
|
123
|
+
* open-shape type — additions are purely additive).
|
|
124
|
+
*/
|
|
125
|
+
export type HostAuthService = {
|
|
126
|
+
/**
|
|
127
|
+
* Open a child window at the given URL and wait for the named cookie
|
|
128
|
+
* to appear. Used by providers whose login flow is "send the user to
|
|
129
|
+
* a web page, scrape the session cookie when they sign in".
|
|
130
|
+
*
|
|
131
|
+
* The host is responsible for: opening the window, polling cookies,
|
|
132
|
+
* closing the window when the cookie shows up (or the user cancels /
|
|
133
|
+
* times out), and isolating the session partition. The provider
|
|
134
|
+
* doesn't see Electron, BrowserWindow, or any windowing detail.
|
|
135
|
+
*/
|
|
136
|
+
openCookieLoginWindow(opts: CookieLoginOptions): Promise<CookieLoginResult>
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* The bag of host services injected into a provider via
|
|
141
|
+
* {@link JackProvider.activate}. Providers store the reference and
|
|
142
|
+
* pull primitives lazily.
|
|
143
|
+
*
|
|
144
|
+
* Adding a new capability:
|
|
145
|
+
* 1. Define the new service interface in this file (or a sibling).
|
|
146
|
+
* 2. Add it as an optional field here so older providers that don't
|
|
147
|
+
* use it keep compiling.
|
|
148
|
+
* 3. Document the feature flag — providers that need the capability
|
|
149
|
+
* should guard with `if (!host.newCapability) return undefined`
|
|
150
|
+
* and the host implements it.
|
|
151
|
+
*
|
|
152
|
+
* Concrete services exposed today are documented in their own types.
|
|
153
|
+
*/
|
|
154
|
+
export type HostServices = {
|
|
155
|
+
/** Per-provider key/value store. Namespaced by provider id by the host. */
|
|
156
|
+
kv: HostKvScope
|
|
157
|
+
/** Auth flow primitives (cookie login today; OAuth / device-code in the future). */
|
|
158
|
+
auth: HostAuthService
|
|
159
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -7,13 +7,19 @@
|
|
|
7
7
|
* (not on Jack's main process internals) and Jack stays free to evolve
|
|
8
8
|
* its host code without breaking provider authors.
|
|
9
9
|
*
|
|
10
|
-
* Re-exports cover
|
|
10
|
+
* Re-exports cover four layers:
|
|
11
11
|
* - `./backend` — neutral wire-shape contract (`AgentBackend`,
|
|
12
12
|
* `AgentQueryOptions`, `AgentSession`, …)
|
|
13
13
|
* - `./spawner` — process-spawning primitives shared by every backend
|
|
14
14
|
* (`ProcessSpawner`, `ProcessHandle`, `localSpawner`, …)
|
|
15
15
|
* - `./provider` — plugin-level contract (`JackProvider`,
|
|
16
16
|
* `CapabilityMatrix`, `ToolDescriptor`, `ProviderBranding`, …)
|
|
17
|
+
* - `./usage` — provider-owned billing/usage surface (`UsageApi`,
|
|
18
|
+
* `UsageMetric`, …)
|
|
19
|
+
* - `./host` — host primitives injected at activation
|
|
20
|
+
* (`HostServices`, `HostKvScope`, `HostAuthService`, …) — providers
|
|
21
|
+
* consume these via `JackProvider.activate(host)` instead of
|
|
22
|
+
* reaching into Electron / host internals directly.
|
|
17
23
|
*
|
|
18
24
|
* Companion runtime types from `@ottimis/jack-chat-core` (`NormalizedMessage`,
|
|
19
25
|
* `ClientToolHandler`, `ToolShape`, …) are re-exported through `./provider`
|
|
@@ -25,6 +31,8 @@ export * from './backend'
|
|
|
25
31
|
export * from './spawner'
|
|
26
32
|
export * from './provider'
|
|
27
33
|
export * from './usage'
|
|
34
|
+
export * from './host'
|
|
35
|
+
export * from './profiles'
|
|
28
36
|
|
|
29
37
|
/**
|
|
30
38
|
* Re-export of `NormalizedMessage` from chat-core so consumers don't need
|
package/src/profiles.ts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Profiles — multiple isolated identities for a single provider.
|
|
3
|
+
*
|
|
4
|
+
* A "profile" is an isolated config/identity directory the provider's runtime
|
|
5
|
+
* can be pointed at via an env var (Claude `CLAUDE_CONFIG_DIR`, Codex
|
|
6
|
+
* `CODEX_HOME`, Gemini `GEMINI_CONFIG_DIR`, …). Two profiles = two distinct
|
|
7
|
+
* accounts / login states / agent customizations / history sets, all running
|
|
8
|
+
* the same provider binary.
|
|
9
|
+
*
|
|
10
|
+
* The user-facing scenario this exists for: an employee with separate
|
|
11
|
+
* "claude-personal" and "claude-work" shell aliases that point CLAUDE_CONFIG_DIR
|
|
12
|
+
* at different folders. The host turns that into a first-class concept —
|
|
13
|
+
* choosable per session, with a default per workspace-agent slot — instead of
|
|
14
|
+
* making the user re-shell their alias every time they switch context.
|
|
15
|
+
*
|
|
16
|
+
* Provider opts in by:
|
|
17
|
+
* - declaring `capabilities.profiles = true`
|
|
18
|
+
* - implementing `JackProvider.profiles` with a {@link ProfilesApi}
|
|
19
|
+
* - injecting the right env var inside `applyProfile`
|
|
20
|
+
*
|
|
21
|
+
* Storage of the profile *list* lives on the host's per-provider kv (provider
|
|
22
|
+
* stores it via `host.kv` at activation time). Storage of the profile
|
|
23
|
+
* *content* (auth, sessions, agents, history) lives inside `configDir` on
|
|
24
|
+
* disk and is the runtime's concern, not the host's — Jack never reads or
|
|
25
|
+
* writes inside `configDir`.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import type { AgentQueryOptions } from './backend'
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* One profile entry. `id` is host-generated and stable; the human edits
|
|
32
|
+
* `label` + `configDir` freely.
|
|
33
|
+
*
|
|
34
|
+
* `isDefault` is exclusive within a provider — exactly one profile carries
|
|
35
|
+
* the flag at any time. Provider implementations enforce that invariant in
|
|
36
|
+
* `update`/`create` (when `setDefault` is true, demote the previous default).
|
|
37
|
+
*/
|
|
38
|
+
export type ProviderProfile = {
|
|
39
|
+
/** Stable identifier — host-generated UUID; never edited by user. */
|
|
40
|
+
id: string
|
|
41
|
+
/** User-facing display label ("Work", "Personal", …). */
|
|
42
|
+
label: string
|
|
43
|
+
/** Absolute path to the runtime config dir on the host filesystem. */
|
|
44
|
+
configDir: string
|
|
45
|
+
/** Exactly one profile per provider carries this flag. */
|
|
46
|
+
isDefault: boolean
|
|
47
|
+
/** ISO 8601 — when the profile was first created in Jack's registry. */
|
|
48
|
+
createdAt: string
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Result of {@link ProfilesApi.probeProfile} — best-effort introspection of
|
|
53
|
+
* what's already stored under `configDir` so the UI can show the user
|
|
54
|
+
* "Connected as <X>" instead of an opaque path.
|
|
55
|
+
*
|
|
56
|
+
* Provider populates whichever fields it can read cheaply (no network
|
|
57
|
+
* round-trips) — fields it can't infer stay undefined.
|
|
58
|
+
*/
|
|
59
|
+
export type ProviderProfileProbe = {
|
|
60
|
+
/** True when the dir exists and looks like a valid runtime config. */
|
|
61
|
+
exists: boolean
|
|
62
|
+
/** True when the dir contains usable credentials. Tri-state: false = present-but-invalid, undefined = N/A. */
|
|
63
|
+
authenticated?: boolean
|
|
64
|
+
/** Human-readable identity hint (email, account label) when discoverable. */
|
|
65
|
+
accountLabel?: string
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Input shape for {@link ProfilesApi.create}. The `id` is host-generated by
|
|
70
|
+
* the provider implementation (typically `crypto.randomUUID()`); the caller
|
|
71
|
+
* supplies the human bits.
|
|
72
|
+
*/
|
|
73
|
+
export type CreateProfileInput = {
|
|
74
|
+
label: string
|
|
75
|
+
configDir: string
|
|
76
|
+
/** When true, the new profile becomes the default (demotes previous default). */
|
|
77
|
+
setDefault?: boolean
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Provider-owned profiles capability. Optional on {@link JackProvider} —
|
|
82
|
+
* absent = the provider's runtime always uses its implicit default config dir
|
|
83
|
+
* and the host hides every profiles-related affordance.
|
|
84
|
+
*/
|
|
85
|
+
export type ProfilesApi = {
|
|
86
|
+
/**
|
|
87
|
+
* Enumerate the registered profiles in stable order. Provider MUST seed
|
|
88
|
+
* a "Default" profile pointing at its implicit config dir on first call
|
|
89
|
+
* (lazy migration — preserves the user's existing setup without manual
|
|
90
|
+
* intervention).
|
|
91
|
+
*/
|
|
92
|
+
list(): Promise<ProviderProfile[]>
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Register a new profile. Provider generates the `id` and persists the
|
|
96
|
+
* row. Returns the freshly-created profile so the caller doesn't have to
|
|
97
|
+
* round-trip through `list()`.
|
|
98
|
+
*/
|
|
99
|
+
create(input: CreateProfileInput): Promise<ProviderProfile>
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Patch an existing profile. Empty patch = no-op. Setting `isDefault: true`
|
|
103
|
+
* demotes whichever profile currently holds the default flag.
|
|
104
|
+
*/
|
|
105
|
+
update(
|
|
106
|
+
id: string,
|
|
107
|
+
patch: Partial<Pick<ProviderProfile, 'label' | 'configDir' | 'isDefault'>>
|
|
108
|
+
): Promise<ProviderProfile>
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Remove a profile by id. MUST refuse to remove the last remaining profile
|
|
112
|
+
* (the provider always needs a default to fall back to). MUST refuse to
|
|
113
|
+
* remove the default profile when other profiles exist — caller has to
|
|
114
|
+
* promote a replacement first.
|
|
115
|
+
*
|
|
116
|
+
* Note: this only removes the registry entry. Files inside `configDir`
|
|
117
|
+
* stay on disk untouched — destructive cleanup is the user's responsibility
|
|
118
|
+
* (we never `rm -rf` a directory the user gave us).
|
|
119
|
+
*/
|
|
120
|
+
remove(id: string): Promise<void>
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Mutate spawn options in place to point the runtime at the chosen
|
|
124
|
+
* profile's `configDir`. Each provider injects its native env var
|
|
125
|
+
* (Claude: `CLAUDE_CONFIG_DIR`; Codex: `CODEX_HOME`; …) and any other
|
|
126
|
+
* spawn-time wiring the runtime needs.
|
|
127
|
+
*
|
|
128
|
+
* Called once per spawn by the host, after `applyKnowledgeContext` and
|
|
129
|
+
* `prepareSpawnOptions`. Unknown `profileId` MUST be a silent no-op
|
|
130
|
+
* (caller falls back to the implicit default behavior).
|
|
131
|
+
*/
|
|
132
|
+
applyProfile(options: AgentQueryOptions, profileId: string): Promise<void>
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Best-effort introspection of what's stored under `configDir` so the
|
|
136
|
+
* UI can show "Connected as X" / "Empty profile" hints. Provider returns
|
|
137
|
+
* what it can read cheaply (file presence, parsed credentials file) —
|
|
138
|
+
* no network calls. Optional: providers that can't introspect their
|
|
139
|
+
* own config dir omit this and the UI falls back to a path-only display.
|
|
140
|
+
*/
|
|
141
|
+
probeProfile?(configDir: string): Promise<ProviderProfileProbe>
|
|
142
|
+
}
|
package/src/provider.ts
CHANGED
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
import type { AgentBackend, AgentPermissionMode, AgentQueryOptions, McpServerSpec } from './backend'
|
|
20
|
+
import type { HostServices } from './host'
|
|
21
|
+
import type { ProfilesApi } from './profiles'
|
|
20
22
|
import type { UsageApi } from './usage'
|
|
21
23
|
import type { ZodType } from 'zod'
|
|
22
24
|
import type {
|
|
@@ -273,6 +275,17 @@ export type CapabilityMatrix = {
|
|
|
273
275
|
* usage bars and no Connect affordance is offered.
|
|
274
276
|
*/
|
|
275
277
|
usage: boolean
|
|
278
|
+
/**
|
|
279
|
+
* Provider supports multiple isolated config/identity directories
|
|
280
|
+
* ("profiles") — distinct accounts, login states, agent customizations,
|
|
281
|
+
* and history sets all selectable per-session at runtime. When `true`,
|
|
282
|
+
* {@link JackProvider.profiles} MUST be defined; the host renders the
|
|
283
|
+
* profile picker UI and routes spawn-time `applyProfile` calls.
|
|
284
|
+
*
|
|
285
|
+
* When `false` the provider's runtime always uses its implicit default
|
|
286
|
+
* config dir; the host hides every profile-related affordance.
|
|
287
|
+
*/
|
|
288
|
+
profiles: boolean
|
|
276
289
|
/**
|
|
277
290
|
* Permission modes the provider actually supports. Drives the
|
|
278
291
|
* Shift-Tab cycle in the renderer (`MessageInputBar`) and any
|
|
@@ -676,6 +689,37 @@ export type JackProvider = {
|
|
|
676
689
|
* decodes.
|
|
677
690
|
*/
|
|
678
691
|
usage?: UsageApi
|
|
692
|
+
/**
|
|
693
|
+
* Multi-profile capability — multiple isolated config/identity dirs
|
|
694
|
+
* selectable per session. See {@link ProfilesApi}. Optional; when
|
|
695
|
+
* undefined `capabilities.profiles` MUST be `false` and the host hides
|
|
696
|
+
* every profile-related affordance. When defined, the host calls
|
|
697
|
+
* `applyProfile(options, profileId)` once per spawn so the provider can
|
|
698
|
+
* inject its native config-dir env var (Claude `CLAUDE_CONFIG_DIR`,
|
|
699
|
+
* Codex `CODEX_HOME`, …).
|
|
700
|
+
*/
|
|
701
|
+
profiles?: ProfilesApi
|
|
702
|
+
/**
|
|
703
|
+
* Optional one-shot activation hook. Called once by the host during
|
|
704
|
+
* registration with a {@link HostServices} bag scoped to this
|
|
705
|
+
* provider's id (kv namespace, auth partition prefix). Providers that
|
|
706
|
+
* need host-side primitives (encrypted credential storage, child auth
|
|
707
|
+
* windows, …) store the `host` reference and use it lazily; providers
|
|
708
|
+
* that are pure (Codex, Gemini today) leave this undefined.
|
|
709
|
+
*
|
|
710
|
+
* Activation MUST be idempotent: calling `activate(host)` twice with
|
|
711
|
+
* the same host is allowed and should not duplicate state. Activation
|
|
712
|
+
* happens at registration time — well before any session spawns —
|
|
713
|
+
* but providers MUST NOT block on network or disk here. Defer all I/O
|
|
714
|
+
* to the methods that actually need it.
|
|
715
|
+
*
|
|
716
|
+
* The host calls `activate` synchronously enough that
|
|
717
|
+
* `provider.usage`, `provider.persistedPermissions`, etc. can read
|
|
718
|
+
* `host` from a closure / captured variable in subsequent invocations.
|
|
719
|
+
* Async work inside `activate` is OK but the host won't await it
|
|
720
|
+
* before exposing the provider — it's "fire and let it complete".
|
|
721
|
+
*/
|
|
722
|
+
activate?(host: HostServices): void | Promise<void>
|
|
679
723
|
}
|
|
680
724
|
|
|
681
725
|
/**
|
package/src/usage.ts
CHANGED
|
@@ -180,32 +180,60 @@ export type UsageConnectContext = {
|
|
|
180
180
|
* Provider-owned usage capability. Optional on {@link JackProvider};
|
|
181
181
|
* absent = host hides the chip's "Connect" affordance and the
|
|
182
182
|
* capability flag is `false`.
|
|
183
|
+
*
|
|
184
|
+
* Multi-profile contract (SDK 0.7.0):
|
|
185
|
+
* Every account-level method accepts an optional `profileId`. Providers
|
|
186
|
+
* that ALSO declare `capabilities.profiles=true` MUST honor the param —
|
|
187
|
+
* different profile = different account = different credentials, polled
|
|
188
|
+
* independently. When omitted, the provider resolves to its DEFAULT
|
|
189
|
+
* profile (back-compat with hosts that don't yet thread profileId).
|
|
190
|
+
*
|
|
191
|
+
* Providers without profiles support (`capabilities.profiles=false`)
|
|
192
|
+
* MAY ignore the param and behave as if every call were singleton —
|
|
193
|
+
* the omission stays the canonical caller behavior, the param is just
|
|
194
|
+
* ignored.
|
|
195
|
+
*
|
|
196
|
+
* `formatSessionMetrics` stays profile-agnostic: per-session metrics
|
|
197
|
+
* derive from the live process's context tokens (already pinned to the
|
|
198
|
+
* session's profile via `applyProfile` at spawn time).
|
|
183
199
|
*/
|
|
184
200
|
export type UsageApi = {
|
|
185
|
-
/**
|
|
186
|
-
|
|
201
|
+
/**
|
|
202
|
+
* Current connection state — used for chip display + gating.
|
|
203
|
+
* Profile-aware: omit `profileId` to query the default profile.
|
|
204
|
+
*/
|
|
205
|
+
status(profileId?: string): Promise<UsageStatus>
|
|
187
206
|
|
|
188
207
|
/**
|
|
189
208
|
* Open the provider's connect flow. Whatever modality the provider
|
|
190
209
|
* needs (login window, API-key picker, OAuth redirect) lives here.
|
|
210
|
+
* Profile-aware: omit `profileId` to bind credentials to the default
|
|
211
|
+
* profile. Different profileIds use isolated storage AND isolated
|
|
212
|
+
* login surfaces (e.g. distinct cookie partitions for Claude) so two
|
|
213
|
+
* accounts can sign in side by side.
|
|
191
214
|
*/
|
|
192
|
-
connect(ctx: UsageConnectContext): Promise<UsageConnectResult>
|
|
215
|
+
connect(ctx: UsageConnectContext, profileId?: string): Promise<UsageConnectResult>
|
|
193
216
|
|
|
194
217
|
/**
|
|
195
218
|
* When `connect()` returned `'choose'`, host calls this with the
|
|
196
219
|
* user's pick. Optional — providers that never choose omit it.
|
|
220
|
+
* Profile-aware: pass the SAME `profileId` you used for `connect()`.
|
|
197
221
|
*/
|
|
198
|
-
selectOption?(optionId: string): Promise<UsageConnectResult>
|
|
222
|
+
selectOption?(optionId: string, profileId?: string): Promise<UsageConnectResult>
|
|
199
223
|
|
|
200
|
-
/**
|
|
201
|
-
|
|
224
|
+
/**
|
|
225
|
+
* Drop credentials and stop any provider-side polling for the
|
|
226
|
+
* specified profile. Omit `profileId` to disconnect the default profile.
|
|
227
|
+
*/
|
|
228
|
+
disconnect(profileId?: string): Promise<void>
|
|
202
229
|
|
|
203
230
|
/**
|
|
204
|
-
* Fetch one fresh account-level snapshot
|
|
205
|
-
* fine when the provider has no billing surface
|
|
206
|
-
* stays `true` for the per-session bridge.
|
|
231
|
+
* Fetch one fresh account-level snapshot for the specified profile.
|
|
232
|
+
* Empty `metrics: []` is fine when the provider has no billing surface
|
|
233
|
+
* yet — the capability stays `true` for the per-session bridge.
|
|
234
|
+
* Omit `profileId` to fetch the default profile.
|
|
207
235
|
*/
|
|
208
|
-
fetch(): Promise<UsageSnapshot>
|
|
236
|
+
fetch(profileId?: string): Promise<UsageSnapshot>
|
|
209
237
|
|
|
210
238
|
/**
|
|
211
239
|
* Recommended poll cadence (seconds). Host clamps to its bounds.
|