@north-light/sdk 0.3.693 → 0.3.695
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 +5 -72
- package/dist/client.d.ts +12 -80
- package/dist/client.js +7 -255
- package/dist/index.d.ts +3 -7
- package/dist/index.js +1 -3
- package/dist/oauth/index.d.ts +3 -6
- package/dist/oauth/index.js +6 -11
- package/dist/resources/canvas.d.ts +2 -9
- package/dist/resources/canvas.js +1 -26
- package/dist/resources/files.d.ts +0 -10
- package/dist/resources/files.js +0 -14
- package/dist/resources/identifiers.d.ts +0 -5
- package/dist/resources/identifiers.js +3 -23
- package/dist/resources/models/credentials.d.ts +1 -3
- package/dist/resources/models/credentials.js +0 -6
- package/dist/resources/models.d.ts +0 -2
- package/dist/resources/models.js +0 -3
- package/dist/resources/run-stream.d.ts +3 -29
- package/dist/resources/run-stream.js +4 -44
- package/dist/resources/runs.d.ts +0 -3
- package/dist/resources/runs.js +0 -9
- package/dist/skill/northlight/SKILL.md +2 -2
- package/dist/types.d.ts +0 -50
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +5 -5
- package/dist/resources/activity.d.ts +0 -22
- package/dist/resources/activity.js +0 -43
- package/dist/resources/bash.d.ts +0 -9
- package/dist/resources/bash.js +0 -15
- package/dist/resources/canvas/history.d.ts +0 -11
- package/dist/resources/canvas/history.js +0 -20
- package/dist/resources/crons.d.ts +0 -15
- package/dist/resources/crons.js +0 -33
- package/dist/resources/human/inbox.d.ts +0 -14
- package/dist/resources/human/inbox.js +0 -30
- package/dist/resources/human/requests.d.ts +0 -13
- package/dist/resources/human/requests.js +0 -26
- package/dist/resources/human.d.ts +0 -8
- package/dist/resources/human.js +0 -10
- package/dist/resources/models/config.d.ts +0 -8
- package/dist/resources/models/config.js +0 -9
- package/dist/resources/node-stream.d.ts +0 -34
- package/dist/resources/node-stream.js +0 -176
- package/dist/resources/nodes/jobs.d.ts +0 -9
- package/dist/resources/nodes/jobs.js +0 -14
- package/dist/resources/nodes/result.d.ts +0 -8
- package/dist/resources/nodes/result.js +0 -11
- package/dist/resources/nodes/worktree.d.ts +0 -9
- package/dist/resources/nodes/worktree.js +0 -14
- package/dist/resources/nodes.d.ts +0 -23
- package/dist/resources/nodes.js +0 -47
- package/dist/resources/structured-requests.d.ts +0 -14
- package/dist/resources/structured-requests.js +0 -19
package/dist/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
export { Crouter as default, Crouter } from './client.js';
|
|
2
|
-
export { NodeStream } from './resources/node-stream.js';
|
|
3
2
|
export { RunStream } from './resources/run-stream.js';
|
|
4
3
|
export { CustomObjects } from './resources/custom-objects.js';
|
|
5
4
|
export { RunReply } from './resources/run-reply.js';
|
|
6
|
-
export { OAuth2Client, ConnectedCrouter,
|
|
5
|
+
export { OAuth2Client, ConnectedCrouter, MemoryConnectionStore, profileFromClaims } from './oauth/index.js';
|
|
7
6
|
export { authorizationRefusalOf, refusalOf } from './oauth/index.js';
|
|
8
7
|
export { RunWatcher } from './resources/run-watcher.js';
|
|
9
8
|
export { GrantWatcher } from './resources/grant-watcher.js';
|
|
@@ -12,7 +11,6 @@ export { parsePrivateJwk, privateKeyFromFile } from './oauth/keygen.js';
|
|
|
12
11
|
export { cursorFromRequest, forwardRunEvents } from './resources/forward.js';
|
|
13
12
|
export { INFERENCE_SCOPE, inferenceEndpoint } from './resources/inference-endpoint.js';
|
|
14
13
|
export { RUN_NOTICE_SCOPE, RunNoticeError, verifyRunNotice } from './resources/run-notice.js';
|
|
15
|
-
export { describeToolDefault, followActivity } from './resources/activity.js';
|
|
16
14
|
export { APIError, APIConnectionError, APIConnectionTimeoutError, APIUserAbortError, AuthenticationError, BadRequestError, ConflictError, CrouterError, DeadlineExceededError, InternalServerError, NoHostedRuntimeError, NotGrantedError, NotFoundError, PermissionDeniedError, RateLimitError, RuntimeVersionError, UnprocessableEntityError, mapError, } from './errors.js';
|
|
17
15
|
export { SDK_VERSION } from './version.js';
|
|
18
16
|
export { setupLink } from './setup-link.js';
|
package/dist/oauth/index.d.ts
CHANGED
|
@@ -101,7 +101,7 @@ export interface OAuth2Options {
|
|
|
101
101
|
* and every `runtime_provisioning` retry wait, including a `Retry-After`; a wait that would pass it fails at
|
|
102
102
|
* once. A refresh runs this bound while it holds the user's store lock, so the lock is held at most this long
|
|
103
103
|
* (plus the store's own time) and a hung directory cannot stall the user's other refreshes. Defaults to
|
|
104
|
-
*
|
|
104
|
+
* 10 s. The error is `DeadlineExceededError` (`code: 'deadline_exceeded'`).
|
|
105
105
|
*/
|
|
106
106
|
timeoutMs?: number;
|
|
107
107
|
}
|
|
@@ -109,9 +109,8 @@ export interface OAuth2Options {
|
|
|
109
109
|
declare const AppCrouter: new (options: CrouterOptions) => AppClient;
|
|
110
110
|
/** A runtime client on one person's stored connection (`oauth.client(userId)`): an `AppClient` that refreshes its
|
|
111
111
|
* token through the `OAuth2Client`'s store, plus whose connection it is and the runtime it calls. It offers only what
|
|
112
|
-
* the person's app listener serves. The owner-daemon namespaces (`
|
|
113
|
-
* type and throw `CrouterError` if reached anyway; `
|
|
114
|
-
* `register`, `publish` and `unregister`, and `canvas` is `watch` and `unwatch`.
|
|
112
|
+
* the person's app listener serves. The owner-daemon namespaces (`spendLimits`, `models`) are absent from its
|
|
113
|
+
* type and throw `CrouterError` if reached anyway; `customObjects` is `register`, `publish` and `unregister`.
|
|
115
114
|
* `request` still sends any route. */
|
|
116
115
|
export declare class ConnectedCrouter extends AppCrouter {
|
|
117
116
|
/** The person whose connection this client uses (`user:<id>`). */
|
|
@@ -126,8 +125,6 @@ export declare class ConnectedCrouter extends AppCrouter {
|
|
|
126
125
|
timeoutS?: number;
|
|
127
126
|
}): Promise<ExecRunDTO>;
|
|
128
127
|
}
|
|
129
|
-
/** The default deadline of one directory operation (`OAuth2Options.timeoutMs`): a discovery read is forgotten when it passes. */
|
|
130
|
-
export declare const DEFAULT_DIRECTORY_TIMEOUT_MS = 10000;
|
|
131
128
|
export declare class OAuth2Client {
|
|
132
129
|
private readonly options;
|
|
133
130
|
private readonly issuer;
|
package/dist/oauth/index.js
CHANGED
|
@@ -63,15 +63,14 @@ function httpsUrl(value) {
|
|
|
63
63
|
return undefined;
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
/** The owner-daemon namespaces a person's runtime does not serve to an app. `
|
|
67
|
-
const OWNER_ONLY = ['spendLimits', '
|
|
66
|
+
/** The owner-daemon namespaces a person's runtime does not serve to an app. `customObjects` is narrowed below, not absent. */
|
|
67
|
+
const OWNER_ONLY = ['spendLimits', 'models'];
|
|
68
68
|
/** The class `ConnectedCrouter` extends: `Crouter`'s implementation under the type of what a person's app listener serves. */
|
|
69
69
|
const AppCrouter = Crouter;
|
|
70
70
|
/** A runtime client on one person's stored connection (`oauth.client(userId)`): an `AppClient` that refreshes its
|
|
71
71
|
* token through the `OAuth2Client`'s store, plus whose connection it is and the runtime it calls. It offers only what
|
|
72
|
-
* the person's app listener serves. The owner-daemon namespaces (`
|
|
73
|
-
* type and throw `CrouterError` if reached anyway; `
|
|
74
|
-
* `register`, `publish` and `unregister`, and `canvas` is `watch` and `unwatch`.
|
|
72
|
+
* the person's app listener serves. The owner-daemon namespaces (`spendLimits`, `models`) are absent from its
|
|
73
|
+
* type and throw `CrouterError` if reached anyway; `customObjects` is `register`, `publish` and `unregister`.
|
|
75
74
|
* `request` still sends any route. */
|
|
76
75
|
export class ConnectedCrouter extends AppCrouter {
|
|
77
76
|
/** The person whose connection this client uses (`user:<id>`). */
|
|
@@ -87,12 +86,8 @@ export class ConnectedCrouter extends AppCrouter {
|
|
|
87
86
|
throw new CrouterError(`client.${name} is not served on an app's runtime connection; it belongs to the owner's own daemon (new Crouter() on its socket)`);
|
|
88
87
|
} });
|
|
89
88
|
}
|
|
90
|
-
const {
|
|
91
|
-
Object.defineProperty(this, 'files', { value: { link: files.link.bind(files) } });
|
|
92
|
-
Object.defineProperty(this, 'profiles', { value: { list: profiles.list } });
|
|
93
|
-
const { customObjects, canvas } = this;
|
|
89
|
+
const { customObjects } = this;
|
|
94
90
|
Object.defineProperty(this, 'customObjects', { value: { register: customObjects.register.bind(customObjects), publish: customObjects.publish.bind(customObjects), unregister: customObjects.unregister.bind(customObjects) } });
|
|
95
|
-
Object.defineProperty(this, 'canvas', { value: { watch: canvas.watch.bind(canvas), unwatch: canvas.unwatch.bind(canvas) } });
|
|
96
91
|
}
|
|
97
92
|
/** Run `crtr <argv…>` in this app's sandbox on the person's runtime (`POST /v1/exec`, scopes `crtr:act` and `crtr:schedule`).
|
|
98
93
|
* No shell and no stdin; the process starts in the app's files folder. A non-zero exit or a timeout resolves; a refusal
|
|
@@ -103,7 +98,7 @@ export class ConnectedCrouter extends AppCrouter {
|
|
|
103
98
|
}
|
|
104
99
|
}
|
|
105
100
|
/** The default deadline of one directory operation (`OAuth2Options.timeoutMs`): a discovery read is forgotten when it passes. */
|
|
106
|
-
|
|
101
|
+
const DEFAULT_DIRECTORY_TIMEOUT_MS = 10_000;
|
|
107
102
|
const assertionType = 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer';
|
|
108
103
|
let refusalScope;
|
|
109
104
|
function handlerScope() {
|
|
@@ -1,19 +1,12 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type WatchRequest, type WatchResultDTO, type UnwatchQuery, type UnwatchResultDTO } from '@north-light/api';
|
|
2
2
|
import type { RequestOptions } from '../types.js';
|
|
3
|
-
import { CanvasHistory } from './canvas/history.js';
|
|
4
3
|
import type { Request } from './request.js';
|
|
4
|
+
/** Link nodes to the app's objects. */
|
|
5
5
|
export declare class Canvas {
|
|
6
6
|
private readonly request;
|
|
7
|
-
readonly history: CanvasHistory;
|
|
8
7
|
constructor(request: Request);
|
|
9
|
-
attention(options?: RequestOptions): Promise<AttentionDTO>;
|
|
10
|
-
attentionCounts(body: AttentionCountsRequest, options?: RequestOptions): Promise<AttentionCountsDTO>;
|
|
11
|
-
snapshot(options?: RequestOptions): Promise<SnapshotDTO>;
|
|
12
|
-
roster(options?: RequestOptions): Promise<RosterDTO>;
|
|
13
|
-
dashboard(query?: DashboardQuery, options?: RequestOptions): Promise<DashboardDTO>;
|
|
14
8
|
/** Watch an object; `watcher` makes a custom object the receiver instead of the caller's node. */
|
|
15
9
|
watch(ref: string, body?: WatchRequest, options?: RequestOptions): Promise<WatchResultDTO>;
|
|
16
10
|
/** Remove a watch. `watcher` identifies the custom object whose watch is removed. */
|
|
17
11
|
unwatch(ref: string, query?: UnwatchQuery, options?: RequestOptions): Promise<UnwatchResultDTO>;
|
|
18
|
-
prune(body: PruneRequest, options?: RequestOptions): Promise<PruneResultDTO>;
|
|
19
12
|
}
|
package/dist/resources/canvas.js
CHANGED
|
@@ -1,32 +1,10 @@
|
|
|
1
1
|
import { routes, } from '@north-light/api';
|
|
2
|
-
import { CanvasHistory } from './canvas/history.js';
|
|
3
2
|
import { withQuery } from './request.js';
|
|
3
|
+
/** Link nodes to the app's objects. */
|
|
4
4
|
export class Canvas {
|
|
5
5
|
request;
|
|
6
|
-
history;
|
|
7
6
|
constructor(request) {
|
|
8
7
|
this.request = request;
|
|
9
|
-
this.history = new CanvasHistory(request);
|
|
10
|
-
}
|
|
11
|
-
attention(options) {
|
|
12
|
-
return this.request('GET', routes.canvasAttention(), undefined, options);
|
|
13
|
-
}
|
|
14
|
-
attentionCounts(body, options) {
|
|
15
|
-
return this.request('POST', routes.canvasAttentionCounts(), body, options);
|
|
16
|
-
}
|
|
17
|
-
snapshot(options) {
|
|
18
|
-
return this.request('GET', routes.canvasSnapshot(), undefined, options);
|
|
19
|
-
}
|
|
20
|
-
roster(options) {
|
|
21
|
-
return this.request('GET', routes.canvasRoster(), undefined, options);
|
|
22
|
-
}
|
|
23
|
-
async dashboard(query, options) {
|
|
24
|
-
const nodeQuery = query?.under === undefined ? undefined : { under: query.under };
|
|
25
|
-
const [nodes, status] = await Promise.all([
|
|
26
|
-
this.request('GET', withQuery(routes.nodes(), nodeQuery), undefined, options),
|
|
27
|
-
this.request('GET', routes.status(), undefined, options),
|
|
28
|
-
]);
|
|
29
|
-
return { nodes, counts: status.node_counts, generated_at: new Date().toISOString() };
|
|
30
8
|
}
|
|
31
9
|
/** Watch an object; `watcher` makes a custom object the receiver instead of the caller's node. */
|
|
32
10
|
watch(ref, body = {}, options) {
|
|
@@ -36,7 +14,4 @@ export class Canvas {
|
|
|
36
14
|
unwatch(ref, query, options) {
|
|
37
15
|
return this.request('DELETE', withQuery(routes.objectWatch(ref), query), undefined, options);
|
|
38
16
|
}
|
|
39
|
-
prune(body, options) {
|
|
40
|
-
return this.request('POST', routes.canvasPrune(), body, options);
|
|
41
|
-
}
|
|
42
17
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type FileEncoding, type FileListDTO, type FilePeekDTO, type FileWriteDTO } from '@north-light/api';
|
|
2
1
|
import type { RequestOptions } from '../types.js';
|
|
3
2
|
import type { Request } from './request.js';
|
|
4
3
|
/** A short-lived signed download link for a file an agent handed over with `crtr push file`. */
|
|
@@ -13,15 +12,6 @@ export interface FileLink {
|
|
|
13
12
|
export declare class Files {
|
|
14
13
|
private readonly request;
|
|
15
14
|
constructor(request: Request);
|
|
16
|
-
read(path: string, options?: {
|
|
17
|
-
encoding?: FileEncoding;
|
|
18
|
-
} & RequestOptions): Promise<FilePeekDTO>;
|
|
19
|
-
write(path: string, content: string, options?: {
|
|
20
|
-
encoding?: FileEncoding;
|
|
21
|
-
} & RequestOptions): Promise<FileWriteDTO>;
|
|
22
|
-
list(path: string, options?: {
|
|
23
|
-
limit?: number;
|
|
24
|
-
} & RequestOptions): Promise<FileListDTO>;
|
|
25
15
|
/**
|
|
26
16
|
* A signed download link for a file an agent handed over (`crtr push file`, announced by a `file.sent` run event), by its `file_id`
|
|
27
17
|
* (app listener only). The link is short-lived; call again for a new one. A file of another app, another person, or a run the app may
|
package/dist/resources/files.js
CHANGED
|
@@ -1,23 +1,9 @@
|
|
|
1
|
-
import { routes, } from '@north-light/api';
|
|
2
1
|
import { pathSegment } from './identifiers.js';
|
|
3
|
-
import { withQuery } from './request.js';
|
|
4
2
|
export class Files {
|
|
5
3
|
request;
|
|
6
4
|
constructor(request) {
|
|
7
5
|
this.request = request;
|
|
8
6
|
}
|
|
9
|
-
read(path, options) {
|
|
10
|
-
const { encoding, ...requestOptions } = options ?? {};
|
|
11
|
-
return this.request('GET', withQuery(routes.filePeek(), { path, encoding }), undefined, requestOptions);
|
|
12
|
-
}
|
|
13
|
-
write(path, content, options) {
|
|
14
|
-
const { encoding, ...requestOptions } = options ?? {};
|
|
15
|
-
return this.request('POST', routes.fileWrite(), { path, content, encoding }, requestOptions);
|
|
16
|
-
}
|
|
17
|
-
list(path, options) {
|
|
18
|
-
const { limit, ...requestOptions } = options ?? {};
|
|
19
|
-
return this.request('GET', withQuery(routes.fileList(), { path, limit }), undefined, requestOptions);
|
|
20
|
-
}
|
|
21
7
|
/**
|
|
22
8
|
* A signed download link for a file an agent handed over (`crtr push file`, announced by a `file.sent` run event), by its `file_id`
|
|
23
9
|
* (app listener only). The link is short-lived; call again for a new one. A file of another app, another person, or a run the app may
|
|
@@ -1,8 +1,3 @@
|
|
|
1
1
|
export declare class ResourceIdentifierError extends TypeError {
|
|
2
2
|
}
|
|
3
|
-
export declare function nodeId(value: string): string;
|
|
4
|
-
export declare function requestId(value: string): string;
|
|
5
|
-
export declare function cronId(value: string): string;
|
|
6
|
-
export declare function jobId(value: string): string;
|
|
7
|
-
export declare function inboxTicketId(value: string): string;
|
|
8
3
|
export declare function pathSegment(value: string, label: string): string;
|
|
@@ -1,33 +1,13 @@
|
|
|
1
|
-
import { isSafeBashJobId, isSafeCronId, isSafeNodeId } from '@north-light/api';
|
|
2
1
|
export class ResourceIdentifierError extends TypeError {
|
|
3
2
|
}
|
|
4
|
-
function validated(value, label, validator) {
|
|
5
|
-
if (!validator(value) || !isSafePathSegment(value)) {
|
|
6
|
-
throw new ResourceIdentifierError(`invalid ${label}: ${JSON.stringify(value)}`);
|
|
7
|
-
}
|
|
8
|
-
return value;
|
|
9
|
-
}
|
|
10
3
|
function isSafePathSegment(value) {
|
|
11
4
|
return typeof value === 'string'
|
|
12
5
|
&& value !== '' && value !== '.' && value !== '..'
|
|
13
6
|
&& !/[\\/\0\s?#%]/u.test(value)
|
|
14
7
|
&& new TextEncoder().encode(value).byteLength <= 128;
|
|
15
8
|
}
|
|
16
|
-
export function nodeId(value) {
|
|
17
|
-
return validated(value, 'node id', isSafeNodeId);
|
|
18
|
-
}
|
|
19
|
-
export function requestId(value) {
|
|
20
|
-
return validated(value, 'request id', isSafeNodeId);
|
|
21
|
-
}
|
|
22
|
-
export function cronId(value) {
|
|
23
|
-
return validated(value, 'cron id', isSafeCronId);
|
|
24
|
-
}
|
|
25
|
-
export function jobId(value) {
|
|
26
|
-
return validated(value, 'job id', isSafeBashJobId);
|
|
27
|
-
}
|
|
28
|
-
export function inboxTicketId(value) {
|
|
29
|
-
return validated(value, 'inbox ticket id', (ticketId) => /^[a-f0-9]{64}$/u.test(ticketId));
|
|
30
|
-
}
|
|
31
9
|
export function pathSegment(value, label) {
|
|
32
|
-
|
|
10
|
+
if (!isSafePathSegment(value))
|
|
11
|
+
throw new ResourceIdentifierError(`invalid ${label}: ${JSON.stringify(value)}`);
|
|
12
|
+
return value;
|
|
33
13
|
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type CredentialResultDTO, type InstallCredentialRequest } from '@north-light/api';
|
|
2
2
|
import type { RequestOptions } from '../../types.js';
|
|
3
3
|
import type { Request } from '../request.js';
|
|
4
4
|
export declare class ModelCredentials {
|
|
5
5
|
private readonly request;
|
|
6
6
|
constructor(request: Request);
|
|
7
|
-
list(options?: RequestOptions): Promise<ModelAuthListDTO>;
|
|
8
7
|
install(provider: string, body: InstallCredentialRequest, options?: RequestOptions): Promise<CredentialResultDTO>;
|
|
9
|
-
remove(provider: string, options?: RequestOptions): Promise<CredentialRemovalResultDTO>;
|
|
10
8
|
}
|
|
@@ -5,13 +5,7 @@ export class ModelCredentials {
|
|
|
5
5
|
constructor(request) {
|
|
6
6
|
this.request = request;
|
|
7
7
|
}
|
|
8
|
-
list(options) {
|
|
9
|
-
return this.request('GET', routes.modelAuths(), undefined, options);
|
|
10
|
-
}
|
|
11
8
|
async install(provider, body, options) {
|
|
12
9
|
return this.request('PUT', routes.modelAuth(pathSegment(provider, 'provider')), body, options);
|
|
13
10
|
}
|
|
14
|
-
async remove(provider, options) {
|
|
15
|
-
return this.request('DELETE', routes.modelAuth(pathSegment(provider, 'provider')), undefined, options);
|
|
16
|
-
}
|
|
17
11
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { ModelConfig } from './models/config.js';
|
|
2
1
|
import { ModelCredentials } from './models/credentials.js';
|
|
3
2
|
import type { Request } from './request.js';
|
|
4
3
|
export declare class Models {
|
|
5
4
|
readonly credentials: ModelCredentials;
|
|
6
|
-
readonly config: ModelConfig;
|
|
7
5
|
constructor(request: Request);
|
|
8
6
|
}
|
package/dist/resources/models.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import { ModelConfig } from './models/config.js';
|
|
2
1
|
import { ModelCredentials } from './models/credentials.js';
|
|
3
2
|
export class Models {
|
|
4
3
|
credentials;
|
|
5
|
-
config;
|
|
6
4
|
constructor(request) {
|
|
7
5
|
this.credentials = new ModelCredentials(request);
|
|
8
|
-
this.config = new ModelConfig(request);
|
|
9
6
|
}
|
|
10
7
|
}
|
|
@@ -1,61 +1,35 @@
|
|
|
1
1
|
import type { RunEvent, RunEventBaseDTO, RunEventOf, RunEventType } from '@north-light/api';
|
|
2
2
|
/** Every run event, discriminated on `type`: the daemon declares the union once and the SDK re-exports it. */
|
|
3
3
|
export type { RunEvent, RunEventOf, RunEventType };
|
|
4
|
-
export type RunEventListener<T extends RunEventType = RunEventType> = (event: RunEventOf<T>) => void;
|
|
5
4
|
/** An event under a type this SDK version does not declare (a newer daemon's), or read by field name. */
|
|
6
5
|
export type UnknownRunEvent = RunEventBaseDTO & {
|
|
7
6
|
type: string;
|
|
8
7
|
[field: string]: unknown;
|
|
9
8
|
};
|
|
10
|
-
/** How a `RunStream` ended without an error: the run `settled`, or the runtime closed an `idle` stream
|
|
11
|
-
* (no running turn and no new event for its quiet window) and `cursor` is where to reopen it. */
|
|
12
|
-
export interface RunStreamEnd {
|
|
13
|
-
reason: 'settled' | 'idle';
|
|
14
|
-
cursor: number;
|
|
15
|
-
}
|
|
16
9
|
/** A resumable run event stream. Closing it does not stop the run.
|
|
17
10
|
*
|
|
18
11
|
* Iteration ends normally in exactly two cases, told apart by `idle`: the run settled (`idle` is false) or the
|
|
19
|
-
* runtime sent `event: idle` and closed (`idle` is true: the run is quiet, nothing is lost, and `
|
|
20
|
-
* reopen with `runs.events(runId, {after:
|
|
12
|
+
* runtime sent `event: idle` and closed (`idle` is true: the run is quiet, nothing is lost, and `position` is where to
|
|
13
|
+
* reopen with `runs.events(runId, {after: position})` when there is something to read). After the idle frame the
|
|
21
14
|
* stream does not reconnect on its own. A transport or protocol failure throws instead, as before. */
|
|
22
15
|
export declare class RunStream implements AsyncIterable<RunEvent> {
|
|
23
16
|
private readonly open;
|
|
24
17
|
private readonly onReconnect?;
|
|
25
18
|
private readonly controller;
|
|
26
|
-
private readonly listeners;
|
|
27
19
|
private cursor;
|
|
28
|
-
private readonly outcome;
|
|
29
|
-
private resolveOutcome;
|
|
30
|
-
private rejectOutcome;
|
|
31
20
|
private finished;
|
|
32
21
|
private readonly events;
|
|
33
22
|
private wake?;
|
|
34
23
|
private failure;
|
|
35
24
|
private idled;
|
|
36
|
-
private readonly ended;
|
|
37
|
-
private resolveEnded;
|
|
38
|
-
private rejectEnded;
|
|
39
25
|
constructor(open: (after: number, signal: AbortSignal) => Promise<Response>, after?: number, signal?: AbortSignal, onReconnect?: ((state: "reconnecting" | "reconnected", error?: unknown) => void) | undefined);
|
|
40
|
-
on<T extends RunEventType>(type: T, listener: RunEventListener<T>): this;
|
|
41
|
-
on(type: string, listener: (event: RunEvent | UnknownRunEvent) => void): this;
|
|
42
|
-
off<T extends RunEventType>(type: T, listener: RunEventListener<T>): this;
|
|
43
|
-
off(type: string, listener: (event: RunEvent | UnknownRunEvent) => void): this;
|
|
44
26
|
abort(): void;
|
|
45
27
|
/** True once the runtime sent `event: idle` and closed the stream: the run has had no running turn and no new
|
|
46
28
|
* event for the runtime's quiet window. The stream has ended and will not reconnect. */
|
|
47
29
|
get idle(): boolean;
|
|
48
30
|
/** The `sequence_number` of the last event delivered (the `after` this stream was given until one arrives).
|
|
49
|
-
* After `idle`, reopen with `runs.events(runId, {after: stream.
|
|
31
|
+
* After `idle`, reopen with `runs.events(runId, {after: stream.position})`. */
|
|
50
32
|
get position(): number;
|
|
51
|
-
/** Resolves when the stream ends without an error: `{reason: 'settled', cursor}` after `node.settled`, or
|
|
52
|
-
* `{reason: 'idle', cursor}` after the runtime's idle close. Rejects with the transport or protocol failure, or
|
|
53
|
-
* `APIUserAbortError` after `abort()`. */
|
|
54
|
-
whenEnded(): Promise<RunStreamEnd>;
|
|
55
|
-
/** Resolves to the run's `node.settled` event. */
|
|
56
|
-
finalOutcome(): Promise<RunEventOf<'node.settled'>>;
|
|
57
|
-
/** The run's `waiting_on_user` events: each carries a question (`question_id, initiating_app, title, subtitle?, steps, slots`). */
|
|
58
|
-
waitingOnUser(): AsyncIterable<RunEventOf<'waiting_on_user'>>;
|
|
59
33
|
[Symbol.asyncIterator](): AsyncIterator<RunEvent>;
|
|
60
34
|
private finish;
|
|
61
35
|
private deliver;
|
|
@@ -2,68 +2,38 @@ import { APIError, APIUserAbortError, mapError } from '../errors.js';
|
|
|
2
2
|
/** A resumable run event stream. Closing it does not stop the run.
|
|
3
3
|
*
|
|
4
4
|
* Iteration ends normally in exactly two cases, told apart by `idle`: the run settled (`idle` is false) or the
|
|
5
|
-
* runtime sent `event: idle` and closed (`idle` is true: the run is quiet, nothing is lost, and `
|
|
6
|
-
* reopen with `runs.events(runId, {after:
|
|
5
|
+
* runtime sent `event: idle` and closed (`idle` is true: the run is quiet, nothing is lost, and `position` is where to
|
|
6
|
+
* reopen with `runs.events(runId, {after: position})` when there is something to read). After the idle frame the
|
|
7
7
|
* stream does not reconnect on its own. A transport or protocol failure throws instead, as before. */
|
|
8
8
|
export class RunStream {
|
|
9
9
|
open;
|
|
10
10
|
onReconnect;
|
|
11
11
|
controller = new AbortController();
|
|
12
|
-
listeners = new Map();
|
|
13
12
|
cursor;
|
|
14
|
-
outcome;
|
|
15
|
-
resolveOutcome;
|
|
16
|
-
rejectOutcome;
|
|
17
13
|
finished = false;
|
|
18
14
|
events = [];
|
|
19
15
|
wake;
|
|
20
16
|
failure;
|
|
21
17
|
idled = false;
|
|
22
|
-
ended;
|
|
23
|
-
resolveEnded;
|
|
24
|
-
rejectEnded;
|
|
25
18
|
constructor(open, after = 0, signal, onReconnect) {
|
|
26
19
|
this.open = open;
|
|
27
20
|
this.onReconnect = onReconnect;
|
|
28
21
|
if (!Number.isSafeInteger(after) || after < 0)
|
|
29
22
|
throw new RangeError('after must be a non-negative safe integer');
|
|
30
23
|
this.cursor = after;
|
|
31
|
-
this.outcome = new Promise((resolve, reject) => { this.resolveOutcome = resolve; this.rejectOutcome = reject; });
|
|
32
|
-
void this.outcome.catch(() => undefined);
|
|
33
|
-
this.ended = new Promise((resolve, reject) => { this.resolveEnded = resolve; this.rejectEnded = reject; });
|
|
34
|
-
void this.ended.catch(() => undefined);
|
|
35
24
|
if (signal?.aborted)
|
|
36
25
|
this.controller.abort(signal.reason);
|
|
37
26
|
else
|
|
38
27
|
signal?.addEventListener('abort', () => this.controller.abort(signal.reason), { once: true });
|
|
39
28
|
void this.consume();
|
|
40
29
|
}
|
|
41
|
-
on(type, listener) {
|
|
42
|
-
const set = this.listeners.get(type) ?? new Set();
|
|
43
|
-
set.add(listener);
|
|
44
|
-
this.listeners.set(type, set);
|
|
45
|
-
return this;
|
|
46
|
-
}
|
|
47
|
-
off(type, listener) { this.listeners.get(type)?.delete(listener); return this; }
|
|
48
30
|
abort() { this.controller.abort(); }
|
|
49
31
|
/** True once the runtime sent `event: idle` and closed the stream: the run has had no running turn and no new
|
|
50
32
|
* event for the runtime's quiet window. The stream has ended and will not reconnect. */
|
|
51
33
|
get idle() { return this.idled; }
|
|
52
34
|
/** The `sequence_number` of the last event delivered (the `after` this stream was given until one arrives).
|
|
53
|
-
* After `idle`, reopen with `runs.events(runId, {after: stream.
|
|
35
|
+
* After `idle`, reopen with `runs.events(runId, {after: stream.position})`. */
|
|
54
36
|
get position() { return this.cursor; }
|
|
55
|
-
/** Resolves when the stream ends without an error: `{reason: 'settled', cursor}` after `node.settled`, or
|
|
56
|
-
* `{reason: 'idle', cursor}` after the runtime's idle close. Rejects with the transport or protocol failure, or
|
|
57
|
-
* `APIUserAbortError` after `abort()`. */
|
|
58
|
-
whenEnded() { return this.ended; }
|
|
59
|
-
/** Resolves to the run's `node.settled` event. */
|
|
60
|
-
finalOutcome() { return this.outcome; }
|
|
61
|
-
/** The run's `waiting_on_user` events: each carries a question (`question_id, initiating_app, title, subtitle?, steps, slots`). */
|
|
62
|
-
async *waitingOnUser() {
|
|
63
|
-
for await (const event of this)
|
|
64
|
-
if (event.type === 'waiting_on_user')
|
|
65
|
-
yield event;
|
|
66
|
-
}
|
|
67
37
|
async *[Symbol.asyncIterator]() {
|
|
68
38
|
for (;;) {
|
|
69
39
|
if (this.events.length) {
|
|
@@ -83,12 +53,6 @@ export class RunStream {
|
|
|
83
53
|
return;
|
|
84
54
|
this.finished = true;
|
|
85
55
|
this.failure = error;
|
|
86
|
-
if (error) {
|
|
87
|
-
this.rejectOutcome(error);
|
|
88
|
-
this.rejectEnded(error);
|
|
89
|
-
}
|
|
90
|
-
else
|
|
91
|
-
this.resolveEnded({ reason: this.idled ? 'idle' : 'settled', cursor: this.cursor });
|
|
92
56
|
this.wake?.();
|
|
93
57
|
this.wake = undefined;
|
|
94
58
|
}
|
|
@@ -97,14 +61,10 @@ export class RunStream {
|
|
|
97
61
|
return;
|
|
98
62
|
this.cursor = event.sequence_number;
|
|
99
63
|
this.events.push(event);
|
|
100
|
-
for (const listener of this.listeners.get(event.type) ?? [])
|
|
101
|
-
listener(event);
|
|
102
64
|
this.wake?.();
|
|
103
65
|
this.wake = undefined;
|
|
104
|
-
if (event.type === 'node.settled')
|
|
105
|
-
this.resolveOutcome(event);
|
|
66
|
+
if (event.type === 'node.settled')
|
|
106
67
|
this.finish();
|
|
107
|
-
}
|
|
108
68
|
}
|
|
109
69
|
async consume() {
|
|
110
70
|
let attempt = 0;
|
package/dist/resources/runs.d.ts
CHANGED
|
@@ -214,9 +214,6 @@ export declare class Runs {
|
|
|
214
214
|
reply(runId: string, sent: SentRunMessage, options?: {
|
|
215
215
|
signal?: AbortSignal;
|
|
216
216
|
}): RunReply;
|
|
217
|
-
stream(params: RunStartParams, options?: RequestOptions & {
|
|
218
|
-
idempotencyKey?: string;
|
|
219
|
-
}): RunStream;
|
|
220
217
|
/** Long-polls `runs.get` until the run is no longer `running` (`settled`, `waiting_on_user`, `idle`, or a status a
|
|
221
218
|
* newer runtime added, which counts as at rest), and returns that response unchanged (`result` is not parsed). Aborting `signal` rejects with its reason and leaves the run as it is. */
|
|
222
219
|
wait(runId: string, options?: RequestOptions): Promise<RunObject>;
|
package/dist/resources/runs.js
CHANGED
|
@@ -129,15 +129,6 @@ export class Runs {
|
|
|
129
129
|
throw new TypeError('sent belongs to a different run');
|
|
130
130
|
return new RunReply((after) => this.events(runId, { after, signal: options.signal }), sent);
|
|
131
131
|
}
|
|
132
|
-
stream(params, options = {}) {
|
|
133
|
-
const controller = new AbortController();
|
|
134
|
-
options.signal?.addEventListener('abort', () => controller.abort(), { once: true });
|
|
135
|
-
const started = this.start(params, options);
|
|
136
|
-
return new RunStream(async (after, signal) => {
|
|
137
|
-
const run = await started;
|
|
138
|
-
return this.openEvents(run.run_id, after, signal);
|
|
139
|
-
}, 0, controller.signal);
|
|
140
|
-
}
|
|
141
132
|
/** Long-polls `runs.get` until the run is no longer `running` (`settled`, `waiting_on_user`, `idle`, or a status a
|
|
142
133
|
* newer runtime added, which counts as at rest), and returns that response unchanged (`result` is not parsed). Aborting `signal` rejects with its reason and leaves the run as it is. */
|
|
143
134
|
async wait(runId, options = {}) {
|
|
@@ -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.695"
|
|
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.695`. 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/types.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { CloseRequest, CreateNodeRequest, EnsureProfileRequest, NodeEventsQuery, ModelAuthReadinessDTO, ModelAuthReadinessQuery, NodeOutcomeDTO, SendMessageRequest, StartupPhaseDTO } from '@north-light/api';
|
|
2
1
|
/** A JSON Schema object. The daemon validates structured results against it. */
|
|
3
2
|
export type JsonSchema = Record<string, unknown>;
|
|
4
3
|
/**
|
|
@@ -8,10 +7,6 @@ export type JsonSchema = Record<string, unknown>;
|
|
|
8
7
|
export type OutputSchema = string | JsonSchema | {
|
|
9
8
|
toJSONSchema(): JsonSchema;
|
|
10
9
|
};
|
|
11
|
-
/** The daemon's create request, widening `output_schema` to accept schema objects. */
|
|
12
|
-
export type NodeCreateParams = Omit<CreateNodeRequest, 'output_schema'> & {
|
|
13
|
-
output_schema?: OutputSchema;
|
|
14
|
-
};
|
|
15
10
|
/** The final argument of every request-capable method. */
|
|
16
11
|
export interface RequestOptions {
|
|
17
12
|
/** Merged into this request's headers. */
|
|
@@ -31,28 +26,6 @@ export interface RequestOptions {
|
|
|
31
26
|
* With `budgetMs` too, the earlier wins. */
|
|
32
27
|
deadlineAt?: number;
|
|
33
28
|
}
|
|
34
|
-
/** Options for one outcome poll. */
|
|
35
|
-
export interface NodeOutcomeOptions extends RequestOptions {
|
|
36
|
-
/** One daemon long poll in seconds, from 0 through 25. */
|
|
37
|
-
wait?: number;
|
|
38
|
-
}
|
|
39
|
-
/** Options for an existing node's event stream. Streams have no wall-clock timeout. */
|
|
40
|
-
export interface NodeEventsOptions extends Omit<RequestOptions, 'timeout'>, NodeEventsQuery {
|
|
41
|
-
}
|
|
42
|
-
/** A message to a running node. The sender is filled in by the client. */
|
|
43
|
-
export type MessageParams = Omit<SendMessageRequest, 'from'>;
|
|
44
|
-
/** What `nodes.cancel` closes, including whether to cascade to descendants. */
|
|
45
|
-
export type CancelParams = CloseRequest;
|
|
46
|
-
/** The outcome of a `parse` run, with the structured result typed from the schema. */
|
|
47
|
-
export type ParsedOutcome<T> = (Extract<NodeOutcomeDTO, {
|
|
48
|
-
kind: 'result';
|
|
49
|
-
}> & {
|
|
50
|
-
output_parsed: T;
|
|
51
|
-
}) | (Exclude<NodeOutcomeDTO, {
|
|
52
|
-
kind: 'result';
|
|
53
|
-
}> & {
|
|
54
|
-
output_parsed: null;
|
|
55
|
-
});
|
|
56
29
|
/** The value type an `OutputSchema` describes, inferred from a Zod or Standard Schema object. */
|
|
57
30
|
export type SchemaOutput<T> = T extends {
|
|
58
31
|
_output: infer Output;
|
|
@@ -63,26 +36,3 @@ export type SchemaOutput<T> = T extends {
|
|
|
63
36
|
};
|
|
64
37
|
};
|
|
65
38
|
} ? Output : unknown;
|
|
66
|
-
/** The profile settings `profiles.ensure` creates or updates. */
|
|
67
|
-
export type EnsureProfileParams = EnsureProfileRequest;
|
|
68
|
-
/** The launch-selecting fields used to resolve the provider readiness check. */
|
|
69
|
-
export type AuthStatusParams = ModelAuthReadinessQuery;
|
|
70
|
-
/** Whether this client can reach a daemon that can run a model, and what to do if it cannot. */
|
|
71
|
-
export interface AuthStatus {
|
|
72
|
-
/** The client holds a transport and the daemon answered. */
|
|
73
|
-
connected: boolean;
|
|
74
|
-
/** Present only when connected. */
|
|
75
|
-
daemon: {
|
|
76
|
-
base_url: string;
|
|
77
|
-
runtime_version: string;
|
|
78
|
-
api_version: string;
|
|
79
|
-
startup_phase: StartupPhaseDTO;
|
|
80
|
-
tcp: string | null;
|
|
81
|
-
} | null;
|
|
82
|
-
/** Present only when connected. */
|
|
83
|
-
model: ModelAuthReadinessDTO | null;
|
|
84
|
-
/** The one thing the application should do next, or null when ready. */
|
|
85
|
-
next_step: 'connect' | 'login' | null;
|
|
86
|
-
/** Literal text the application shows the user for `next_step`. */
|
|
87
|
-
instructions: string | null;
|
|
88
|
-
}
|
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.695";
|
|
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.695';
|
|
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.695",
|
|
4
|
+
"crouterContract": "1.65",
|
|
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.695",
|
|
48
|
+
"@north-light/identity": "0.3.695",
|
|
49
|
+
"@north-light/plugin": "0.3.695",
|
|
50
50
|
"jose": "^6.2.1"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|