@north-light/sdk 0.3.844 → 0.3.846
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/dist/oauth/index.d.ts +9 -0
- package/dist/oauth/index.js +20 -0
- package/dist/resources/providers.d.ts +14 -3
- package/dist/resources/providers.js +8 -3
- package/dist/skill/northlight/SKILL.md +2 -2
- package/dist/testing/cloud.d.ts +5 -1
- package/dist/testing/cloud.js +30 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +5 -5
package/dist/oauth/index.d.ts
CHANGED
|
@@ -132,6 +132,7 @@ export declare class OAuth2Client {
|
|
|
132
132
|
private readonly timeoutMs;
|
|
133
133
|
private readonly store;
|
|
134
134
|
private readonly appTokens;
|
|
135
|
+
private readonly appSelfTokens;
|
|
135
136
|
private readonly directoryApiTokens;
|
|
136
137
|
private jwks?;
|
|
137
138
|
private discoveryPromise?;
|
|
@@ -249,6 +250,14 @@ export declare class OAuth2Client {
|
|
|
249
250
|
* `retryable` true; `invalid_client` is a 401 `unauthorized` naming the key.
|
|
250
251
|
*/
|
|
251
252
|
appClient(userId: string): Promise<ConnectedCrouter>;
|
|
253
|
+
/**
|
|
254
|
+
* A runtime client for the app itself: the app signs a `client_credentials` request for `sub=app:<clientId>` and the directory
|
|
255
|
+
* answers a token for the fleet runtime (`runtimeUrl` on the client). No person, grant or stored connection is involved, so the
|
|
256
|
+
* `userId` on the client is `app:<clientId>`. Tokens are cached until a minute before they expire; the client mints again on
|
|
257
|
+
* expiry and once on a 401. Errors are the token request's, as for `appClient`.
|
|
258
|
+
*/
|
|
259
|
+
appSelfClient(): Promise<ConnectedCrouter>;
|
|
260
|
+
private mintAppSelfToken;
|
|
252
261
|
private mintAppToken;
|
|
253
262
|
private mintDirectoryApiToken;
|
|
254
263
|
/**
|
package/dist/oauth/index.js
CHANGED
|
@@ -115,6 +115,7 @@ export class OAuth2Client {
|
|
|
115
115
|
timeoutMs;
|
|
116
116
|
store;
|
|
117
117
|
appTokens = new AppTokenCache((userId) => this.mintAppToken(userId));
|
|
118
|
+
appSelfTokens = new AppTokenCache(() => this.mintAppSelfToken());
|
|
118
119
|
directoryApiTokens = new AppTokenCache(() => this.mintDirectoryApiToken());
|
|
119
120
|
jwks;
|
|
120
121
|
discoveryPromise;
|
|
@@ -458,6 +459,25 @@ export class OAuth2Client {
|
|
|
458
459
|
...(this.options.fetch ? { fetch: this.options.fetch } : {}),
|
|
459
460
|
});
|
|
460
461
|
}
|
|
462
|
+
/**
|
|
463
|
+
* A runtime client for the app itself: the app signs a `client_credentials` request for `sub=app:<clientId>` and the directory
|
|
464
|
+
* answers a token for the fleet runtime (`runtimeUrl` on the client). No person, grant or stored connection is involved, so the
|
|
465
|
+
* `userId` on the client is `app:<clientId>`. Tokens are cached until a minute before they expire; the client mints again on
|
|
466
|
+
* expiry and once on a 401. Errors are the token request's, as for `appClient`.
|
|
467
|
+
*/
|
|
468
|
+
async appSelfClient() {
|
|
469
|
+
const key = `app:${this.options.clientId}`;
|
|
470
|
+
const { runtimeUrl } = await this.appSelfTokens.get(key);
|
|
471
|
+
let used;
|
|
472
|
+
return new ConnectedCrouter({ userId: key, runtimeUrl }, {
|
|
473
|
+
tokenSource: async () => { used = (await this.appSelfTokens.get(key)).accessToken; return used; },
|
|
474
|
+
onUnauthorized: async () => { await this.appSelfTokens.get(key, used); },
|
|
475
|
+
...(this.options.fetch ? { fetch: this.options.fetch } : {}),
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
async mintAppSelfToken() {
|
|
479
|
+
return appTokenFrom(await this.tokenResponse({ grant_type: 'client_credentials', sub: `app:${this.options.clientId}` }));
|
|
480
|
+
}
|
|
461
481
|
async mintAppToken(userId) {
|
|
462
482
|
return appTokenFrom(await this.tokenResponse({ grant_type: 'client_credentials', sub: userId }));
|
|
463
483
|
}
|
|
@@ -44,9 +44,10 @@ export declare class Providers {
|
|
|
44
44
|
* The daemon checks scope, mints an outbound token and calls the provider.
|
|
45
45
|
*
|
|
46
46
|
* `machine` names which of the account's devices takes the call (a `machine_id`, `runtime:` prefix optional). Only a provider
|
|
47
|
-
* served by a machine, such as `device`, accepts it.
|
|
48
|
-
*
|
|
49
|
-
* device here and repeat the call.
|
|
47
|
+
* served by a machine, such as `device`, accepts it. A call that names none goes to the account's chosen machine for the leaf's group when one is set (a
|
|
48
|
+
* chosen machine that was removed is refused `machine_required`); otherwise to the only device, or, for `device`'s `browser libs`, to the most recently seen
|
|
49
|
+
* machine; with several devices and no choice the runtime refuses `machine_required` rather than guessing, so name the device here and repeat the call.
|
|
50
|
+
* A stateful caller resolves the machine once with `machine()` and passes the returned `machine_id` on every call.
|
|
50
51
|
*/
|
|
51
52
|
call(input: {
|
|
52
53
|
provider: string;
|
|
@@ -56,4 +57,14 @@ export declare class Providers {
|
|
|
56
57
|
approval?: string;
|
|
57
58
|
machine?: string;
|
|
58
59
|
}, options?: RequestOptions): Promise<unknown>;
|
|
60
|
+
/** Which machine a call to this tool would go to, by the same selection `call` runs; nothing is sent to it. Refusals (`machine_required` with `details.reason`, `provider_not_connected`, ...) surface as `APIError`. */
|
|
61
|
+
machine(input: {
|
|
62
|
+
provider: string;
|
|
63
|
+
tool: string;
|
|
64
|
+
machine?: string;
|
|
65
|
+
}, options?: RequestOptions): Promise<{
|
|
66
|
+
machine_id: string;
|
|
67
|
+
name: string;
|
|
68
|
+
chosen_by: 'named' | 'account' | 'only_device' | 'newest';
|
|
69
|
+
}>;
|
|
59
70
|
}
|
|
@@ -12,11 +12,16 @@ export class Providers {
|
|
|
12
12
|
* The daemon checks scope, mints an outbound token and calls the provider.
|
|
13
13
|
*
|
|
14
14
|
* `machine` names which of the account's devices takes the call (a `machine_id`, `runtime:` prefix optional). Only a provider
|
|
15
|
-
* served by a machine, such as `device`, accepts it.
|
|
16
|
-
*
|
|
17
|
-
* device here and repeat the call.
|
|
15
|
+
* served by a machine, such as `device`, accepts it. A call that names none goes to the account's chosen machine for the leaf's group when one is set (a
|
|
16
|
+
* chosen machine that was removed is refused `machine_required`); otherwise to the only device, or, for `device`'s `browser libs`, to the most recently seen
|
|
17
|
+
* machine; with several devices and no choice the runtime refuses `machine_required` rather than guessing, so name the device here and repeat the call.
|
|
18
|
+
* A stateful caller resolves the machine once with `machine()` and passes the returned `machine_id` on every call.
|
|
18
19
|
*/
|
|
19
20
|
call(input, options) {
|
|
20
21
|
return this.request('POST', '/v1/provider/call', input, options);
|
|
21
22
|
}
|
|
23
|
+
/** Which machine a call to this tool would go to, by the same selection `call` runs; nothing is sent to it. Refusals (`machine_required` with `details.reason`, `provider_not_connected`, ...) surface as `APIError`. */
|
|
24
|
+
machine(input, options) {
|
|
25
|
+
return this.request('POST', '/v1/provider/machine', input, options);
|
|
26
|
+
}
|
|
22
27
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: northlight
|
|
3
3
|
description: "Use when building, debugging or shipping an app that signs people in with Northlight, starts runs on their Northlight runtime, or calls Northlight providers (sms, search, integrations, context, device) with @north-light/sdk."
|
|
4
4
|
metadata:
|
|
5
|
-
sdk-version: "0.3.
|
|
5
|
+
sdk-version: "0.3.846"
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# Building a Northlight app
|
|
@@ -27,7 +27,7 @@ Never text a person first: Comms refuses a send to anyone who has not texted you
|
|
|
27
27
|
|
|
28
28
|
## First: check this skill matches the SDK
|
|
29
29
|
|
|
30
|
-
This skill is for SDK version `0.3.
|
|
30
|
+
This skill is for SDK version `0.3.846`. If the project has `node_modules/@north-light/sdk/package.json`, compare its `version` with that number. If they differ, run `npx @north-light/sdk skill` in the project, then read the rewritten `.agents/skills/northlight/SKILL.md` (or `.claude/skills/northlight/SKILL.md`) instead of this copy. It needs no account. A project that has no SDK yet starts with `npx @north-light/sdk@latest init <dir>`.
|
|
31
31
|
|
|
32
32
|
## Where things run
|
|
33
33
|
|
package/dist/testing/cloud.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { type SpaceOp } from './space.js';
|
|
|
7
7
|
import { type FakeRefusalCode, type FakeScope, type FakeUser, type Responder } from './users.js';
|
|
8
8
|
import { type FakeError } from './wire.js';
|
|
9
9
|
/** A runtime operation, named as the daemon's `OPERATIONS` table names it. */
|
|
10
|
-
export type FakeOp = 'grant.get' | 'run.start' | 'run.list' | 'run.get' | 'run.message' | 'run.events' | 'run.interrupt' | 'run.cancel' | 'run.delete' | 'run.rename' | 'question.get' | 'question.answer' | 'question.cancel' | 'trace.get' | 'memory.list' | 'memory.get' | 'provider.tools' | 'provider.call' | 'profile.list' | 'exec' | SpaceOp;
|
|
10
|
+
export type FakeOp = 'grant.get' | 'run.start' | 'run.list' | 'run.get' | 'run.message' | 'run.events' | 'run.interrupt' | 'run.cancel' | 'run.delete' | 'run.rename' | 'question.get' | 'question.answer' | 'question.cancel' | 'trace.get' | 'memory.list' | 'memory.get' | 'provider.tools' | 'provider.call' | 'provider.machine' | 'profile.list' | 'exec' | SpaceOp;
|
|
11
11
|
/** A directory operation. */
|
|
12
12
|
export type FakeDirectoryOp = 'directory.discovery' | 'directory.token' | 'directory.jwks';
|
|
13
13
|
/** What `intercept` / `failNext` / `gate` match: a runtime operation, `'*'` (every runtime operation), or a directory operation. */
|
|
@@ -67,6 +67,8 @@ export interface FakeProvider {
|
|
|
67
67
|
/** `available` (default), or an install state: listed with `error`, calls answer 503 `provider_unavailable`. */
|
|
68
68
|
status?: 'available' | 'installing' | 'install_failed';
|
|
69
69
|
error?: string;
|
|
70
|
+
/** `machine`: the provider is served by the account's device machines (as `device` is). The fake has none, so `providers.machine` answers `provider_not_connected`; any other provider answers `invalid_argument`. */
|
|
71
|
+
transport?: 'machine';
|
|
70
72
|
tools: Record<string, {
|
|
71
73
|
group?: string;
|
|
72
74
|
description?: string;
|
|
@@ -328,5 +330,7 @@ export declare class FakeCloud {
|
|
|
328
330
|
private providerEntry;
|
|
329
331
|
private providerTools;
|
|
330
332
|
private execCall;
|
|
333
|
+
/** The fake has no devices: a machine-served provider answers `provider_not_connected`, as an account with no device machine does. */
|
|
334
|
+
private providerMachine;
|
|
331
335
|
private providerCall;
|
|
332
336
|
}
|
package/dist/testing/cloud.js
CHANGED
|
@@ -35,6 +35,7 @@ const ROUTES = [
|
|
|
35
35
|
['GET', /^\/v1\/providers\/tools$/, 'provider.tools'],
|
|
36
36
|
['GET', /^\/v1\/providers\/([^/]+)\/tools$/, 'provider.tools'],
|
|
37
37
|
['POST', /^\/v1\/provider\/call$/, 'provider.call'],
|
|
38
|
+
['POST', /^\/v1\/provider\/machine$/, 'provider.machine'],
|
|
38
39
|
['GET', /^\/v1\/profiles$/, 'profile.list'],
|
|
39
40
|
['POST', /^\/v1\/exec$/, 'exec'],
|
|
40
41
|
['POST', /^\/v1\/schemas$/, 'schema.register'],
|
|
@@ -830,6 +831,7 @@ export class FakeCloud {
|
|
|
830
831
|
}
|
|
831
832
|
case 'provider.tools': return this.providerTools(user, id);
|
|
832
833
|
case 'provider.call': return this.providerCall(user, body, signal);
|
|
834
|
+
case 'provider.machine': return this.providerMachine(user, body);
|
|
833
835
|
case 'exec': return this.execCall(user, body, signal);
|
|
834
836
|
case 'profile.list': return { status: 200, body: { profiles: [{ profile_id: 'default', name: 'default', grantee: this.host.grantee, default_kind: 'general', default: true }] } };
|
|
835
837
|
default:
|
|
@@ -1116,6 +1118,34 @@ export class FakeCloud {
|
|
|
1116
1118
|
this.liveExecs--;
|
|
1117
1119
|
}
|
|
1118
1120
|
}
|
|
1121
|
+
/** The fake has no devices: a machine-served provider answers `provider_not_connected`, as an account with no device machine does. */
|
|
1122
|
+
providerMachine(user, body) {
|
|
1123
|
+
const params = objectBody(body);
|
|
1124
|
+
const provider = params['provider'];
|
|
1125
|
+
if (typeof provider !== 'string' || !PROVIDER_ID.test(provider) || provider === 'crtr')
|
|
1126
|
+
throw invalid('provider must be a provider id', 'provider');
|
|
1127
|
+
const tool = params['tool'];
|
|
1128
|
+
if (typeof tool !== 'string' || !tool.trim())
|
|
1129
|
+
throw invalid('tool must be a non-empty string', 'tool');
|
|
1130
|
+
const machine = params['machine'];
|
|
1131
|
+
if (machine !== undefined && (typeof machine !== 'string' || !machine.trim()))
|
|
1132
|
+
throw invalid('machine must be a machine id', 'machine');
|
|
1133
|
+
const definition = this.providerDefs.get(provider);
|
|
1134
|
+
if (!definition)
|
|
1135
|
+
throw refuse(503, 'provider_unavailable', `provider "${provider}" unavailable: bundle installation pending`);
|
|
1136
|
+
if (definition.status && definition.status !== 'available') {
|
|
1137
|
+
throw refuse(503, 'provider_unavailable', `provider "${provider}" unavailable: ${definition.error ?? 'bundle installation pending'}`);
|
|
1138
|
+
}
|
|
1139
|
+
const spec = definition.tools[tool.trim()];
|
|
1140
|
+
if (!spec)
|
|
1141
|
+
throw refuse(404, 'not_found', `tool "${tool}" is not in provider "${provider}"`, { param: 'tool' });
|
|
1142
|
+
const scope = `${provider}:${spec.group ?? tool.trim()}`;
|
|
1143
|
+
if (!user.scopeStrings().includes(scope))
|
|
1144
|
+
throw refuse(403, 'scope_missing', `missing scope ${scope}`, { scope });
|
|
1145
|
+
if (definition.transport !== 'machine')
|
|
1146
|
+
throw invalid(`provider "${provider}" is not served by a device, so it has no machine`, 'provider');
|
|
1147
|
+
throw refuse(403, 'provider_not_connected', 'no device machine is signed in to this account');
|
|
1148
|
+
}
|
|
1119
1149
|
async providerCall(user, body, signal) {
|
|
1120
1150
|
const params = objectBody(body);
|
|
1121
1151
|
const provider = params['provider'];
|
package/dist/version.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** This SDK's release version. Informational only: compatibility is the contract level, not this number. */
|
|
2
|
-
export declare const SDK_VERSION = "0.3.
|
|
2
|
+
export declare const SDK_VERSION = "0.3.846";
|
|
3
3
|
/** The release sent in `Crouter-Minimum-Runtime-Version` on every request. It is frozen, so a runtime from before the
|
|
4
4
|
* contract level existed (which only knows this header) refuses this SDK, while every later runtime accepts it. */
|
|
5
5
|
export declare const LEGACY_FLOOR = "0.3.423";
|
package/dist/version.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// SDK_VERSION is written by scripts/release-version.mjs on every release; do not edit by hand.
|
|
2
2
|
/** This SDK's release version. Informational only: compatibility is the contract level, not this number. */
|
|
3
|
-
export const SDK_VERSION = '0.3.
|
|
3
|
+
export const SDK_VERSION = '0.3.846';
|
|
4
4
|
// LEGACY_FLOOR is written once by `scripts/contract.mjs release`, at the first release that carries the contract level
|
|
5
5
|
// (the `0.0.0` placeholder is replaced there and never again); do not edit by hand.
|
|
6
6
|
/** The release sent in `Crouter-Minimum-Runtime-Version` on every request. It is frozen, so a runtime from before the
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/sdk",
|
|
3
|
-
"version": "0.3.
|
|
4
|
-
"crouterContract": "1.
|
|
3
|
+
"version": "0.3.846",
|
|
4
|
+
"crouterContract": "1.99",
|
|
5
5
|
"description": "Typed Node and browser client for running crouter agents through the crtrd /v1 API.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.js",
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
"prepublishOnly": "node -e \"if (process.env.npm_config_tag !== 'next') { console.error('@north-light/sdk publishes only with --tag next; scripts/promote-sdk.mjs is the only mover of latest.'); process.exit(1); }\""
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@north-light/api": "0.3.
|
|
48
|
-
"@north-light/identity": "0.3.
|
|
49
|
-
"@north-light/plugin": "0.3.
|
|
47
|
+
"@north-light/api": "0.3.846",
|
|
48
|
+
"@north-light/identity": "0.3.846",
|
|
49
|
+
"@north-light/plugin": "0.3.846",
|
|
50
50
|
"jose": "^6.2.1"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|