@north-light/sdk 0.3.899 → 0.3.901

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/index.d.ts CHANGED
@@ -6,7 +6,7 @@ export type { CustomDeliveryStream, ReceiveOptions } from './resources/custom-ob
6
6
  export type { RunEvent, RunEventOf, RunEventType, UnknownRunEvent } from './resources/run-stream.js';
7
7
  export { RunReply } from './resources/run-reply.js';
8
8
  export type { RunReplyCollectOptions, RunReplyEnding, RunReplyEvent, RunReplyResult, SentRunMessage } from './resources/run-reply.js';
9
- export type { AppMachine, AppProfile, RunActivity, RunDeleteResult, RunImportParams, RunImportResult, RunObject, RunParsedOutcome, RunParseOptions, RunParseParams, RunRecap, RunStartParams, RunStartResult, StopHook, RunStatus, RunTrace } from './resources/runs.js';
9
+ export type { AppMachine, AppProfile, RunActivity, RunDeleteResult, RunImportParams, RunImportResult, OpenItem, RunObject, RunParsedOutcome, RunParseOptions, RunParseParams, RunRecap, RunStartParams, RunStartResult, RunSummary, StopHook, RunStatus, RunTrace } from './resources/runs.js';
10
10
  export type { FileLink } from './resources/files.js';
11
11
  export type { Upload, UploadCreateParams } from './resources/uploads.js';
12
12
  export type { AttachmentLink } from './resources/attachments.js';
@@ -271,6 +271,30 @@ export declare class OAuth2Client {
271
271
  * token request's: `invalid_client` is a 401 `unauthorized` naming the key, a directory 5xx or a 429 has `retryable` true.
272
272
  */
273
273
  directoryToken(rejected?: string): Promise<string>;
274
+ /**
275
+ * One request to the directory's `/v1` routes as the app itself (bearer `directoryToken()`): `/v1/account/*` (setup state,
276
+ * research result, payment and billing state), `/v1/provider`, `/v1/receipts`. A 401 re-mints the token once. Any directory
277
+ * answer resolves as `{status, body}` (`body` is the parsed JSON, or `undefined` when the answer is not JSON), so the caller
278
+ * decides what a 404 or 409 means; a transport failure, a directory token failure or the deadline (`timeoutMs`) throws.
279
+ * `query` is appended to `path`.
280
+ */
281
+ directoryRequest(method: 'GET' | 'POST' | 'PUT' | 'DELETE', path: string, options?: {
282
+ query?: Record<string, string>;
283
+ body?: unknown;
284
+ }): Promise<{
285
+ status: number;
286
+ body: unknown;
287
+ }>;
288
+ /** The directory's public marketplace listing (`GET /v1/marketplace/apps`, no token). Resolves as `{status, body}` like `directoryRequest`. */
289
+ marketplaceApps(): Promise<{
290
+ status: number;
291
+ body: unknown;
292
+ }>;
293
+ /** The app's own provider row (`GET /v1/provider`). Resolves as `{status, body}` like `directoryRequest`. */
294
+ provider(): Promise<{
295
+ status: number;
296
+ body: unknown;
297
+ }>;
274
298
  /**
275
299
  * Whether `userId` (`user:<id>`) is on the team that holds this app, and their role on it (`GET /v1/apps/self/members/:user_id`
276
300
  * as the app itself, bearer `directoryToken()`). For an app's own staff pages: the directory answers from its current
@@ -497,6 +497,46 @@ export class OAuth2Client {
497
497
  directoryToken(rejected) {
498
498
  return this.directoryApiTokens.get('directory', rejected).then((token) => token.accessToken);
499
499
  }
500
+ /**
501
+ * One request to the directory's `/v1` routes as the app itself (bearer `directoryToken()`): `/v1/account/*` (setup state,
502
+ * research result, payment and billing state), `/v1/provider`, `/v1/receipts`. A 401 re-mints the token once. Any directory
503
+ * answer resolves as `{status, body}` (`body` is the parsed JSON, or `undefined` when the answer is not JSON), so the caller
504
+ * decides what a 404 or 409 means; a transport failure, a directory token failure or the deadline (`timeoutMs`) throws.
505
+ * `query` is appended to `path`.
506
+ */
507
+ async directoryRequest(method, path, options = {}) {
508
+ if (!path.startsWith('/v1/'))
509
+ throw new CrouterError(`directoryRequest needs a /v1 path, got ${JSON.stringify(path)}`);
510
+ const url = new URL(`${this.issuer.replace(/\/$/, '')}${path}`);
511
+ for (const [key, value] of Object.entries(options.query ?? {}))
512
+ url.searchParams.set(key, value);
513
+ const deadlineAt = Date.now() + this.timeoutMs;
514
+ const ask = async (token) => this.bounded(url.toString(), {
515
+ method,
516
+ headers: { accept: 'application/json', authorization: `Bearer ${token}`, ...(options.body === undefined ? {} : { 'content-type': 'application/json' }) },
517
+ ...(options.body === undefined ? {} : { body: JSON.stringify(options.body) }),
518
+ }, deadlineAt, async (response) => ({ status: response.status, body: await response.json().catch(() => undefined) }));
519
+ const mint = async (rejected) => {
520
+ try {
521
+ return await withinDeadline(this.directoryToken(rejected), deadlineAt);
522
+ }
523
+ catch (error) {
524
+ throw error instanceof APIError ? mapError(error) : error;
525
+ }
526
+ };
527
+ const token = await mint();
528
+ const first = await ask(token);
529
+ return first.status === 401 ? ask(await mint(token)) : first;
530
+ }
531
+ /** The directory's public marketplace listing (`GET /v1/marketplace/apps`, no token). Resolves as `{status, body}` like `directoryRequest`. */
532
+ async marketplaceApps() {
533
+ const deadlineAt = Date.now() + this.timeoutMs;
534
+ return this.bounded(`${this.issuer.replace(/\/$/, '')}/v1/marketplace/apps`, { headers: { accept: 'application/json' } }, deadlineAt, async (response) => ({ status: response.status, body: await response.json().catch(() => undefined) }));
535
+ }
536
+ /** The app's own provider row (`GET /v1/provider`). Resolves as `{status, body}` like `directoryRequest`. */
537
+ provider() {
538
+ return this.directoryRequest('GET', '/v1/provider');
539
+ }
500
540
  /**
501
541
  * Whether `userId` (`user:<id>`) is on the team that holds this app, and their role on it (`GET /v1/apps/self/members/:user_id`
502
542
  * as the app itself, bearer `directoryToken()`). For an app's own staff pages: the directory answers from its current
@@ -119,6 +119,44 @@ export interface RunObject {
119
119
  branch: string;
120
120
  } | null;
121
121
  }
122
+ /** One chat in `runs.summaries`: the cheap list row. Activity, last report, usage, outcome and worktree stay on `runs.get`. */
123
+ export interface RunSummary {
124
+ run_id: string;
125
+ /** The runtime's generated title; null before it writes one. */
126
+ title: string | null;
127
+ status: RunStatus;
128
+ created_at: string;
129
+ last_activity_at: string | null;
130
+ /** Open decisions (not notices) of the run and its child agents; 0 when settled. */
131
+ pending_question_count: number;
132
+ /** Open display-only notices; 0 when settled. */
133
+ open_notice_count: number;
134
+ recap?: {
135
+ goal: string;
136
+ state: string;
137
+ };
138
+ }
139
+ /** One open question, notice or review in `runs.openItems`. `steps`, `slots`, `provider` and `tool` are `questions.get`'s values (decisions and notices); `document` is a review's document name. */
140
+ export interface OpenItem {
141
+ id: string;
142
+ kind: 'decision' | 'notice' | 'review';
143
+ /** The chat root, also for an item a child agent asked. */
144
+ run_id: string;
145
+ node_id: string;
146
+ created_at: string;
147
+ title: string;
148
+ subtitle?: string;
149
+ steps?: number;
150
+ slots?: Array<{
151
+ id?: string;
152
+ kind: string;
153
+ step: number;
154
+ config: Record<string, unknown>;
155
+ }>;
156
+ provider?: string;
157
+ tool?: string;
158
+ document?: string;
159
+ }
122
160
  /** `RunObject.recap`. */
123
161
  export interface RunRecap {
124
162
  goal: string;
@@ -202,15 +240,36 @@ export declare class Runs {
202
240
  status?: RunStatus;
203
241
  after?: string;
204
242
  limit?: number;
243
+ app?: string;
244
+ cron_id?: string;
205
245
  }, options?: RequestOptions): Promise<{
206
246
  runs: RunObject[];
207
247
  next: string | null;
208
248
  }>;
249
+ /** The caller's chats as cheap rows, newest activity first, one statement on the runtime. `limit` 1 to 1000 (default 1000); filter by status on the returned rows. */
250
+ summaries(filters?: {
251
+ after?: string;
252
+ limit?: number;
253
+ app?: string;
254
+ }, options?: RequestOptions): Promise<{
255
+ runs: RunSummary[];
256
+ next: string | null;
257
+ }>;
258
+ /** Open questions, notices and reviews of the caller's chats (child agents' included), oldest first; `run_id` limits to one chat. At most 500: `truncated` is true past that. */
259
+ openItems(filters?: {
260
+ run_id?: string;
261
+ app?: string;
262
+ }, options?: RequestOptions): Promise<{
263
+ items: OpenItem[];
264
+ truncated: boolean;
265
+ }>;
209
266
  /** Every run across pages, most recently active first: `for await (const run of runs.listAll())`. Fetches
210
267
  * the next page (`limit` per page) only as you iterate; `break` stops fetching. */
211
268
  listAll(filters?: {
212
269
  status?: RunStatus;
213
270
  limit?: number;
271
+ app?: string;
272
+ cron_id?: string;
214
273
  }, options?: RequestOptions): AsyncGenerator<RunObject, void, undefined>;
215
274
  /** Send a message to a run. `start_turn: true` (the default) answers it in its
216
275
  * turn. A running run reads it at its next step unless `steer: false` opts out
@@ -29,6 +29,14 @@ export class Runs {
29
29
  list(filters = {}, options) {
30
30
  return this.request('GET', `/v1/runs${query(filters)}`, undefined, options);
31
31
  }
32
+ /** The caller's chats as cheap rows, newest activity first, one statement on the runtime. `limit` 1 to 1000 (default 1000); filter by status on the returned rows. */
33
+ summaries(filters = {}, options) {
34
+ return this.request('GET', `/v1/runs/summaries${query(filters)}`, undefined, options);
35
+ }
36
+ /** Open questions, notices and reviews of the caller's chats (child agents' included), oldest first; `run_id` limits to one chat. At most 500: `truncated` is true past that. */
37
+ openItems(filters = {}, options) {
38
+ return this.request('GET', `/v1/open-items${query(filters)}`, undefined, options);
39
+ }
32
40
  /** Every run across pages, most recently active first: `for await (const run of runs.listAll())`. Fetches
33
41
  * the next page (`limit` per page) only as you iterate; `break` stops fetching. */
34
42
  async *listAll(filters = {}, 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.899"
5
+ sdk-version: "0.3.901"
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.899`. 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>`.
30
+ This skill is for SDK version `0.3.901`. 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
 
@@ -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.cancel_node' | 'run.job.kill' | 'run.delete' | 'run.rename' | 'question.get' | 'question.answer' | 'question.cancel' | 'question.history' | 'review.list' | 'review.get' | 'review.submit' | 'review.cancel' | 'discuss.ticket.get' | 'discuss.ticket.post' | 'discuss.review.get' | 'discuss.review.post' | 'trace.get' | 'memory.list' | 'memory.get' | 'provider.tools' | 'provider.call' | 'provider.machine' | 'profile.list' | 'exec' | SpaceOp;
10
+ export type FakeOp = 'grant.get' | 'run.start' | 'run.list' | 'run.summaries' | 'run.open_items' | 'run.get' | 'run.message' | 'run.events' | 'run.interrupt' | 'run.cancel' | 'run.cancel_node' | 'run.job.kill' | 'run.delete' | 'run.rename' | 'question.get' | 'question.answer' | 'question.cancel' | 'question.history' | 'review.list' | 'review.get' | 'review.submit' | 'review.cancel' | 'discuss.ticket.get' | 'discuss.ticket.post' | 'discuss.review.get' | 'discuss.review.post' | '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. */
@@ -19,6 +19,8 @@ const ROUTES = [
19
19
  ['GET', /^\/v1\/grant$/, 'grant.get'],
20
20
  ['POST', /^\/v1\/runs$/, 'run.start'],
21
21
  ['GET', /^\/v1\/runs$/, 'run.list'],
22
+ ['GET', /^\/v1\/runs\/summaries$/, 'run.summaries'],
23
+ ['GET', /^\/v1\/open-items$/, 'run.open_items'],
22
24
  ['GET', /^\/v1\/runs\/([^/]+)$/, 'run.get'],
23
25
  ['DELETE', /^\/v1\/runs\/([^/]+)$/, 'run.delete'],
24
26
  ['POST', /^\/v1\/runs\/([^/]+)\/messages$/, 'run.message'],
@@ -754,6 +756,19 @@ export class FakeCloud {
754
756
  const last = page.at(-1);
755
757
  return { status: 200, body: { runs: page.map((run) => run.toObject()), next: rows.length > limit && last ? Buffer.from(JSON.stringify({ activity: last.lastActivityAt, id: last.id })).toString('base64url') : null } };
756
758
  }
759
+ case 'run.summaries': {
760
+ const limit = integerParam(query.get('limit'), 'limit', 1, 1000, 1000);
761
+ const rows = user.runs.filter((run) => !run.deleted)
762
+ .sort((a, b) => (a.lastActivityAt === b.lastActivityAt ? (a.id < b.id ? 1 : -1) : a.lastActivityAt < b.lastActivityAt ? 1 : -1));
763
+ const page = rows.slice(0, limit);
764
+ const last = page.at(-1);
765
+ return { status: 200, body: { runs: page.map((run) => run.toSummary()), next: rows.length > limit && last ? Buffer.from(JSON.stringify({ activity: last.lastActivityAt, id: last.id })).toString('base64url') : null } };
766
+ }
767
+ case 'run.open_items': {
768
+ const runId = query.get('run_id');
769
+ const items = user.runs.filter((run) => !run.deleted && (runId === null || run.id === runId)).flatMap((run) => run.openItems());
770
+ return { status: 200, body: { items: items.slice(0, 500), truncated: items.length > 500 } };
771
+ }
757
772
  case 'run.get': {
758
773
  const wait = waitSeconds(query);
759
774
  const run = this.ownedRun(user, id);
@@ -123,6 +123,10 @@ export declare class FakeRun {
123
123
  get status(): RunStatusDTO;
124
124
  /** What the root is doing, derived from the event log as `runActivity` derives it with no open streaming block. */
125
125
  get activity(): RunActivityDTO | null;
126
+ /** A `runs.summaries` row. */
127
+ toSummary(): Record<string, unknown>;
128
+ /** The open questions and notices of this run as `runs.openItems` items. */
129
+ openItems(): Record<string, unknown>[];
126
130
  /** `run.get`'s body. */
127
131
  toObject(): Record<string, unknown>;
128
132
  /** Append any run event; `nodeId` defaults to the root (another id is a child node's event). */
@@ -108,6 +108,22 @@ export class FakeRun {
108
108
  }
109
109
  return { phase: 'thinking' };
110
110
  }
111
+ /** A `runs.summaries` row. */
112
+ toSummary() {
113
+ const status = this.status;
114
+ const settled = status === 'settled';
115
+ return { run_id: this.id, title: null, status, created_at: this.createdAt, last_activity_at: this.lastActivityAt,
116
+ pending_question_count: settled ? 0 : this.pendingQuestionIds.length, open_notice_count: settled ? 0 : this.openNoticeIds.length };
117
+ }
118
+ /** The open questions and notices of this run as `runs.openItems` items. */
119
+ openItems() {
120
+ if (this.status === 'settled')
121
+ return [];
122
+ return [...this.pendingQuestionIds, ...this.openNoticeIds].map((id) => {
123
+ const q = this.questions.get(id);
124
+ return { id, kind: q.kind, run_id: this.id, node_id: this.id, created_at: this.createdAt, title: q.title, ...(q.subtitle === undefined ? {} : { subtitle: q.subtitle }), steps: q.steps, slots: q.slots };
125
+ });
126
+ }
111
127
  /** `run.get`'s body. */
112
128
  toObject() {
113
129
  const status = this.status;
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.899";
2
+ export declare const SDK_VERSION = "0.3.901";
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.899';
3
+ export const SDK_VERSION = '0.3.901';
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/sdk",
3
- "version": "0.3.899",
3
+ "version": "0.3.901",
4
4
  "crouterContract": "1.119",
5
5
  "description": "Typed Node and browser client for running crouter agents through the crtrd /v1 API.",
6
6
  "type": "module",
@@ -50,9 +50,9 @@
50
50
  "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); }\""
51
51
  },
52
52
  "dependencies": {
53
- "@north-light/api": "0.3.899",
54
- "@north-light/identity": "0.3.899",
55
- "@north-light/plugin": "0.3.899",
53
+ "@north-light/api": "0.3.901",
54
+ "@north-light/identity": "0.3.901",
55
+ "@north-light/plugin": "0.3.901",
56
56
  "jose": "^6.2.1"
57
57
  },
58
58
  "peerDependencies": {