@north-light/sdk 0.3.781 → 0.3.783

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 CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  It is a client, not a runtime. It never runs an agent itself, and it does not bundle a model: the runtime it talks to does. The runtime is the Northlight cloud control plane; the client needs its URL and a bearer token. The lower-level contract it is built on is [`@north-light/api`](https://www.npmjs.com/package/@north-light/api); most applications should install this package instead.
12
12
 
13
- [Docs](https://sdk.docs.northlight.ai) · [Quick setup](https://sdk.docs.northlight.ai/docs/quickstart) · [Guides](https://sdk.docs.northlight.ai/docs/guides/typed-results) · [Errors](https://sdk.docs.northlight.ai/docs/errors) · [Release notes](https://sdk.docs.northlight.ai/docs/release-notes) · [Running a daemon yourself](https://crouter.docs.northlight.ai/docs/sdk) · [crouter repository](https://github.com/Northlight-Systems/crouter)
13
+ [Docs](https://sdk.docs.northlight.ai) · [Quick setup](https://sdk.docs.northlight.ai/docs/quickstart) · [Guides](https://sdk.docs.northlight.ai/docs/guides/typed-results) · [Errors](https://sdk.docs.northlight.ai/docs/errors) · [Release notes](https://sdk.docs.northlight.ai/docs/release-notes) · [crouter repository](https://github.com/Northlight-Systems/crouter)
14
14
 
15
15
  ## Start an app with the CLI
16
16
 
@@ -119,7 +119,7 @@ CREATE INDEX connection_updated_at_idx ON connection (updated_at, user_id);
119
119
 
120
120
  ## Reference
121
121
 
122
- The [app builder docs](https://sdk.docs.northlight.ai) cover quick setup, concepts, guides, providers, errors and the generated reference. For the client's own reference, the [SDK guide](https://crouter.docs.northlight.ai/docs/sdk) covers [client construction](https://crouter.docs.northlight.ai/docs/sdk/client), [Docker](https://crouter.docs.northlight.ai/docs/sdk/docker), [daemon errors](https://crouter.docs.northlight.ai/docs/sdk/errors), and the complete [resource map](https://crouter.docs.northlight.ai/docs/sdk/resources).
122
+ The [app builder docs](https://sdk.docs.northlight.ai) cover quick setup, concepts, guides, providers, errors and the generated reference.
123
123
 
124
124
  `@north-light/sdk/errors` exports `errorCodes`/`ErrorCode` (the daemon's codes), `sdkErrorCodes`/`SdkErrorCode` (the codes the SDK raises itself, such as `oauth_state_mismatch`; `CrouterError.code` is typed with them), and `mapError`, which turns a plain `APIError` into its status class (`NotFoundError`, …) for app tests.
125
125
 
@@ -128,7 +128,7 @@ The SDK re-exports its public DTO types, so you do not also install `@north-ligh
128
128
  ## Related
129
129
 
130
130
  - [`@north-light/api`](https://www.npmjs.com/package/@north-light/api): the `/v1` contract this client is built on.
131
- - [`@north-light/env-docker`](https://www.npmjs.com/package/@north-light/env-docker): start a `crtrd` container and get a `Connection` to pass to `new Crouter(...)`.
131
+ - [`@north-light/env-docker`](https://www.npmjs.com/package/@north-light/env-docker): Northlight-internal helper that starts the `crtrd` CI image for the pr-review workflow. It is not a way to run or self-host crtr.
132
132
  - [`@north-light/plugin`](https://www.npmjs.com/package/@north-light/plugin): expose your own commands to agents as `crtr` commands.
133
133
  - [Main repository](https://github.com/Northlight-Systems/crouter): the `crtr` CLI, the `crtrd` daemon,.
134
134
 
package/dist/index.d.ts CHANGED
@@ -41,6 +41,8 @@ export { APIError, APIConnectionError, APIConnectionTimeoutError, APIUserAbortEr
41
41
  export type { DeadlineDetails, RuntimeVersionDetails } from './errors.js';
42
42
  export type { CapExhaustedDetails } from '@north-light/api';
43
43
  export { SDK_VERSION } from './version.js';
44
+ export { sourcing, SourcingUnavailableError, SOURCING_RUN_RULE } from './sourcing.js';
45
+ export type { SourcingAttempt, SourcingClient, SourcingOptions, SourcingRead, SourcingRequest, SourcingResult, SourcingServedBy, SourcingUnavailableDetails } from './sourcing.js';
44
46
  export { setupLink } from './setup-link.js';
45
47
  export { sdkErrorCodes } from './error-codes.js';
46
48
  export type { SdkErrorCode } from './error-codes.js';
package/dist/index.js CHANGED
@@ -14,5 +14,6 @@ export { INFERENCE_SCOPE, inferenceEndpoint } from './resources/inference-endpoi
14
14
  export { RUN_NOTICE_SCOPE, RunNoticeError, verifyRunNotice } from './resources/run-notice.js';
15
15
  export { APIError, APIConnectionError, APIConnectionTimeoutError, APIUserAbortError, AuthenticationError, BadRequestError, ConflictError, CrouterError, DeadlineExceededError, InternalServerError, NoHostedRuntimeError, NotGrantedError, NotFoundError, PermissionDeniedError, RateLimitError, RuntimeVersionError, UnprocessableEntityError, mapError, } from './errors.js';
16
16
  export { SDK_VERSION } from './version.js';
17
+ export { sourcing, SourcingUnavailableError, SOURCING_RUN_RULE } from './sourcing.js';
17
18
  export { setupLink } from './setup-link.js';
18
19
  export { sdkErrorCodes } from './error-codes.js';
@@ -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.781"
5
+ sdk-version: "0.3.783"
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.781`. 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.783`. 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
 
@@ -0,0 +1,146 @@
1
+ import { APIError } from './errors.js';
2
+ import type { Providers } from './resources/providers.js';
3
+ /**
4
+ * `sourcing.read`: one read of a person, company or page, from the person's own Mac first and from Northlight's hosted
5
+ * search second. Reads only: there is no write path, and a write never falls back. The router never sleeps, retries or
6
+ * meters; it classifies each failure, returns one result shape, or raises `SourcingUnavailableError`.
7
+ * Design: the approved "sourcing capabilities" design (route table and routing rule).
8
+ */
9
+ export type SourcingServedBy = 'device' | 'integrations' | 'hosted';
10
+ /** One read. The `read` name picks the row of the route table. */
11
+ export type SourcingRequest = {
12
+ read: 'linkedin.profile';
13
+ identifier?: string;
14
+ url?: string;
15
+ sections?: string[];
16
+ } | {
17
+ read: 'linkedin.search';
18
+ keywords?: string;
19
+ filter?: Record<string, unknown>;
20
+ limit?: number;
21
+ } | {
22
+ read: 'linkedin.company';
23
+ company: string;
24
+ } | {
25
+ read: 'x.profile';
26
+ user: string;
27
+ } | {
28
+ read: 'x.search';
29
+ query: string;
30
+ limit?: number;
31
+ } | {
32
+ read: 'x.posts';
33
+ query: string;
34
+ numResults?: number;
35
+ } | {
36
+ read: 'github.user';
37
+ login: string;
38
+ } | {
39
+ read: 'github.repos';
40
+ login: string;
41
+ } | {
42
+ read: 'web.search';
43
+ query: string;
44
+ numResults?: number;
45
+ includeDomains?: string[];
46
+ } | {
47
+ read: 'web.contents';
48
+ urls: string[];
49
+ } | {
50
+ read: 'web.answer';
51
+ query: string;
52
+ } | {
53
+ read: 'email.work';
54
+ name: string;
55
+ domain: string;
56
+ linkedin?: string;
57
+ };
58
+ export type SourcingRead = SourcingRequest['read'];
59
+ export interface SourcingResult {
60
+ served_by: SourcingServedBy;
61
+ data: unknown;
62
+ /** USD the hosted call cost, when the hosted answer reports it (`cost_usd`). Never set for `device` or `integrations`. */
63
+ cost_usd?: number;
64
+ /** Why path 1 did not serve it: the failure code, or `skipped:<reason>` when path 1 was not called. Set only when `served_by` is `hosted`. */
65
+ fallback_reason?: string;
66
+ }
67
+ export interface SourcingOptions {
68
+ /** The scopes the app's grant holds. When given, path 1 is skipped without a call if it lacks `device:browser` / `integrations:github_read`. */
69
+ scopes?: readonly string[];
70
+ /** The app's last device probe: `false` skips the device path without a call (ATS `macPresence(...).browser === false`). */
71
+ browser?: boolean;
72
+ /** Names which Mac takes device calls (`providers.call`'s `machine`). */
73
+ machine?: string;
74
+ /** The linked GitHub account label, needed only when the person has several. */
75
+ githubAccount?: string;
76
+ /** Per-exec budget on the Mac, in ms (default 30000). */
77
+ execTimeoutMs?: number;
78
+ /** Clock for `retry_at` (default `Date.now`). */
79
+ now?: () => number;
80
+ signal?: AbortSignal;
81
+ }
82
+ /** The slice of the SDK client the router uses: `client.providers.call`. */
83
+ export interface SourcingClient {
84
+ providers: Pick<Providers, 'call'>;
85
+ }
86
+ export interface SourcingAttempt {
87
+ path: SourcingServedBy;
88
+ /** The error code, or `skipped:no_scope` / `skipped:no_browser` when the path was not called. */
89
+ code: string;
90
+ retry_after_s?: number;
91
+ reset_at?: string;
92
+ }
93
+ /** `SourcingUnavailableError.details`. */
94
+ export interface SourcingUnavailableDetails {
95
+ /** One entry per path the route table lists for the read. */
96
+ attempts: SourcingAttempt[];
97
+ /** ISO time of the earliest retry across the attempts (`retry_after_s` from now, or a hosted `reset_at`), or `null` when none gave one. */
98
+ retry_at: string | null;
99
+ /** `true` when the hosted refusal was a 402 (limit or cap reached). */
100
+ budget: boolean;
101
+ }
102
+ /** Every path for the read was skipped or failed in a way that means "not now". Retryable when any attempt was transient.
103
+ * `code` is `sourcing_unavailable`, `status` 503. The app decides what to do; the router never retries. */
104
+ export declare class SourcingUnavailableError extends APIError {
105
+ get attempts(): SourcingAttempt[];
106
+ get retryAt(): string | null;
107
+ get budget(): boolean;
108
+ }
109
+ interface DeviceRoute {
110
+ kind: 'device';
111
+ site: 'linkedin' | 'x';
112
+ fn: string;
113
+ args: Record<string, unknown>;
114
+ }
115
+ interface IntegrationsRoute {
116
+ kind: 'integrations';
117
+ tool: string;
118
+ input: Record<string, unknown>;
119
+ }
120
+ interface HostedRoute {
121
+ tool: string;
122
+ arguments: Record<string, unknown>;
123
+ }
124
+ interface Route {
125
+ first?: DeviceRoute | IntegrationsRoute;
126
+ hosted?: HostedRoute;
127
+ }
128
+ /** The one place that says, for each read, which paths exist and in what order. LinkedIn has no hosted path. */
129
+ export declare function routeOf(r: SourcingRequest): Route;
130
+ /**
131
+ * Reads one thing: path 1 (the person's Mac, or their GitHub account), then the hosted search provider, per the route table.
132
+ *
133
+ * - Resolves `{served_by, data, cost_usd?, fallback_reason?}`.
134
+ * - Throws `SourcingUnavailableError` when every path was skipped or failed with "not now" (including a hosted 402, `budget: true`).
135
+ * - Throws path 1's own error when it is the answer (`not_found`, a site `NotFound`/`Validation`/`PermissionDenied`, `scope_missing`, or any code the rule does not list).
136
+ * - Throws the hosted error itself for `price_over_maximum` and any hosted failure the rule does not list.
137
+ */
138
+ declare function read(client: SourcingClient, request: SourcingRequest, options?: SourcingOptions): Promise<SourcingResult>;
139
+ export declare const sourcing: {
140
+ read: typeof read;
141
+ };
142
+ /**
143
+ * The same rule, for agent runs. Append it to the prompt of any run that holds `device:browser`.
144
+ */
145
+ export declare const SOURCING_RUN_RULE: string;
146
+ export {};
@@ -0,0 +1,189 @@
1
+ import { APIError } from './errors.js';
2
+ /** Every path for the read was skipped or failed in a way that means "not now". Retryable when any attempt was transient.
3
+ * `code` is `sourcing_unavailable`, `status` 503. The app decides what to do; the router never retries. */
4
+ export class SourcingUnavailableError extends APIError {
5
+ get attempts() { return this.details.attempts; }
6
+ get retryAt() { return this.details.retry_at; }
7
+ get budget() { return this.details.budget; }
8
+ }
9
+ // ---- the routing rule -----------------------------------------------------------------------------------------------
10
+ /** Path 1 returned one of these: the Mac or the site cannot be used now, so try the next path. */
11
+ const FALL_THROUGH = new Set([
12
+ 'device_offline', 'device_timeout', 'provider_not_connected', 'machine_required', 'helper_not_installed', 'browser_profile_not_open',
13
+ 'site_signed_out', 'wrong_site', 'rate_limited', 'lib_broken',
14
+ // Integrations: the person's GitHub account is not linked or needs reconnecting (the same "cannot be used now" as provider_not_connected).
15
+ 'account_not_linked', 'account_reconnect_required',
16
+ // Reads never return outcome_unknown; if one appears it is treated as js_exception.
17
+ 'js_exception', 'outcome_unknown',
18
+ ]);
19
+ /** A site-function error class that is the answer itself: the page does not exist, or the input is bad. */
20
+ const ANSWER_CLASS = /^(NotFound|Validation|PermissionDenied)\b/;
21
+ const HOSTED_BUDGET = new Set(['limit_reached', 'payment_required', 'cap_exhausted']);
22
+ const HOSTED_TRANSIENT = new Set(['provider_rate_limited', 'provider_capacity', 'vendor_unavailable']);
23
+ /** Codes that mean "later may work", for `retryable`. */
24
+ const TRANSIENT = new Set([
25
+ 'device_offline', 'device_timeout', 'rate_limited', 'browser_profile_not_open', 'provider_rate_limited', 'provider_capacity', 'vendor_unavailable',
26
+ ]);
27
+ function codeOf(error) {
28
+ if (!(error instanceof APIError))
29
+ throw error; // not a provider answer (a bug or an abort): never classified
30
+ const inner = error.details?.code;
31
+ return error.code === 'provider_error' && typeof inner === 'string' ? inner : error.code;
32
+ }
33
+ function fallsThrough(error) {
34
+ const code = codeOf(error);
35
+ if (!FALL_THROUGH.has(code))
36
+ return false;
37
+ if (code === 'js_exception' && ANSWER_CLASS.test(error.message))
38
+ return false;
39
+ return true;
40
+ }
41
+ /** The refusal's reset time: the envelope's `reset_at`, else the `x-reset-at` header, else `details.reset_at` (a directory 402 carries it in `payment`). */
42
+ const resetAtOf = (e) => {
43
+ if (e.resetAt !== undefined)
44
+ return e.resetAt;
45
+ const header = e.headers.get('x-reset-at'); // search sends its monthly reset as a header on a 402
46
+ if (header && !Number.isNaN(Date.parse(header)))
47
+ return header;
48
+ const d = e.details;
49
+ const v = d?.reset_at ?? d?.payment?.reset_at;
50
+ return typeof v === 'string' ? v : undefined;
51
+ };
52
+ const attemptOf = (path, error) => {
53
+ const e = error;
54
+ return { path, code: codeOf(error), ...(e.retryAfterS === undefined ? {} : { retry_after_s: e.retryAfterS }), ...(resetAtOf(e) === undefined ? {} : { reset_at: resetAtOf(e) }) };
55
+ };
56
+ // ---- the route table ------------------------------------------------------------------------------------------------
57
+ const DEVICE_SCOPE = 'device:browser';
58
+ const GITHUB_SCOPE = 'integrations:github_read';
59
+ const compact = (o) => Object.fromEntries(Object.entries(o).filter(([, v]) => v !== undefined));
60
+ /** The one place that says, for each read, which paths exist and in what order. LinkedIn has no hosted path. */
61
+ export function routeOf(r) {
62
+ switch (r.read) {
63
+ case 'linkedin.profile': return { first: { kind: 'device', site: 'linkedin', fn: 'getProfile', args: compact({ identifier: r.identifier ?? r.url, sections: r.sections }) } };
64
+ case 'linkedin.search': return { first: { kind: 'device', site: 'linkedin', fn: 'searchPeople', args: compact({ keywords: r.keywords, filter: r.filter, limit: r.limit }) } };
65
+ case 'linkedin.company': return { first: { kind: 'device', site: 'linkedin', fn: 'getCompany', args: { company: r.company } } };
66
+ case 'x.profile': return { first: { kind: 'device', site: 'x', fn: 'getProfile', args: { user: r.user } }, hosted: { tool: 'people x-profile', arguments: { handle: r.user.replace(/^@/, '') } } };
67
+ case 'x.search': return { first: { kind: 'device', site: 'x', fn: 'searchUsers', args: compact({ query: r.query, limit: r.limit }) } };
68
+ case 'x.posts': return {
69
+ first: { kind: 'device', site: 'x', fn: 'searchPosts', args: compact({ query: r.query, limit: r.numResults }) },
70
+ hosted: { tool: 'search', arguments: compact({ query: r.query, includeDomains: ['x.com'], numResults: r.numResults }) },
71
+ };
72
+ case 'github.user': return { first: { kind: 'integrations', tool: 'GITHUB_GET_A_USER', input: { username: r.login } }, hosted: { tool: 'people github-user', arguments: { login: r.login } } };
73
+ // No hosted path: a user profile is not a repository list.
74
+ case 'github.repos': return { first: { kind: 'integrations', tool: 'GITHUB_LIST_REPOSITORIES_FOR_A_USER', input: { username: r.login } } };
75
+ case 'web.search': return { hosted: { tool: 'search', arguments: compact({ query: r.query, numResults: r.numResults, includeDomains: r.includeDomains }) } };
76
+ case 'web.contents': return { hosted: { tool: 'contents', arguments: { urls: r.urls } } };
77
+ case 'web.answer': return { hosted: { tool: 'answer', arguments: { query: r.query } } };
78
+ case 'email.work': return { hosted: { tool: 'people work-email', arguments: compact({ name: r.name, domain: r.domain, linkedin: r.linkedin }) } };
79
+ }
80
+ }
81
+ // ---- the calls --------------------------------------------------------------------------------------------------------
82
+ const SITE_URL = { linkedin: 'https://www.linkedin.com/', x: 'https://x.com/' };
83
+ const isRecord = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
84
+ async function readOnDevice(client, route, o) {
85
+ const call = (tool, args) => client.providers.call({ provider: 'device', tool, arguments: args, ...(o.machine ? { machine: o.machine } : {}) }, o.signal ? { signal: o.signal } : undefined);
86
+ const created = await call('browser executor create', { url: SITE_URL[route.site], mode: 'hidden' });
87
+ const executor = isRecord(created) && isRecord(created['executor']) ? created['executor']['name'] : undefined;
88
+ if (typeof executor !== 'string')
89
+ throw new APIError(502, 'provider_bad_response', 'browser executor create named no executor');
90
+ try {
91
+ const code = `import { ${route.fn} } from "@northlight/${route.site}";\nreturn await ${route.fn}(${JSON.stringify(route.args)});`;
92
+ const out = await call('browser executor exec', { executor, code, timeoutMs: o.execTimeoutMs ?? 30_000 });
93
+ return isRecord(out) && 'result' in out ? out['result'] : out;
94
+ }
95
+ finally {
96
+ // The executor is only a tab we opened; a failed close cannot change what the read returned.
97
+ await call('browser executor close', { executor }).catch(() => undefined);
98
+ }
99
+ }
100
+ async function readOnIntegrations(client, route, o) {
101
+ const out = await client.providers.call({
102
+ provider: 'integrations', tool: 'github read',
103
+ arguments: compact({ tool: route.tool, account: o.githubAccount, input: JSON.stringify(route.input) }),
104
+ }, o.signal ? { signal: o.signal } : undefined);
105
+ return isRecord(out) && 'data' in out ? out['data'] : out;
106
+ }
107
+ /** Why path 1 is not called, or `null` when it should be. */
108
+ function skipReason(first, o) {
109
+ const scope = first.kind === 'device' ? DEVICE_SCOPE : GITHUB_SCOPE;
110
+ if (o.scopes && !o.scopes.includes(scope))
111
+ return 'skipped:no_scope';
112
+ if (first.kind === 'device' && o.browser === false)
113
+ return 'skipped:no_browser';
114
+ return null;
115
+ }
116
+ function unavailable(attempts, budget, now) {
117
+ const times = attempts.flatMap((a) => [
118
+ ...(a.retry_after_s === undefined ? [] : [now + a.retry_after_s * 1000]),
119
+ ...(a.reset_at === undefined || Number.isNaN(Date.parse(a.reset_at)) ? [] : [Date.parse(a.reset_at)]),
120
+ ]);
121
+ const details = { attempts, retry_at: times.length ? new Date(Math.min(...times)).toISOString() : null, budget };
122
+ const retryable = attempts.some((a) => TRANSIENT.has(a.code) || a.retry_after_s !== undefined || a.reset_at !== undefined);
123
+ const summary = attempts.map((a) => `${a.path}: ${a.code}`).join('; ');
124
+ return new SourcingUnavailableError(503, 'sourcing_unavailable', `no sourcing path is available (${summary})`, details, undefined, { type: 'server_error', retryable, ...(details.retry_at ? { reset_at: details.retry_at } : {}) });
125
+ }
126
+ /**
127
+ * Reads one thing: path 1 (the person's Mac, or their GitHub account), then the hosted search provider, per the route table.
128
+ *
129
+ * - Resolves `{served_by, data, cost_usd?, fallback_reason?}`.
130
+ * - Throws `SourcingUnavailableError` when every path was skipped or failed with "not now" (including a hosted 402, `budget: true`).
131
+ * - Throws path 1's own error when it is the answer (`not_found`, a site `NotFound`/`Validation`/`PermissionDenied`, `scope_missing`, or any code the rule does not list).
132
+ * - Throws the hosted error itself for `price_over_maximum` and any hosted failure the rule does not list.
133
+ */
134
+ async function read(client, request, options = {}) {
135
+ const route = routeOf(request);
136
+ const now = (options.now ?? Date.now)();
137
+ const attempts = [];
138
+ let fallback;
139
+ if (route.first) {
140
+ const path = route.first.kind;
141
+ const skip = skipReason(route.first, options);
142
+ if (skip) {
143
+ attempts.push({ path, code: skip });
144
+ fallback = skip;
145
+ }
146
+ else {
147
+ try {
148
+ const data = route.first.kind === 'device' ? await readOnDevice(client, route.first, options) : await readOnIntegrations(client, route.first, options);
149
+ return { served_by: path, data };
150
+ }
151
+ catch (error) {
152
+ if (!fallsThrough(error))
153
+ throw error;
154
+ attempts.push(attemptOf(path, error));
155
+ fallback = codeOf(error);
156
+ }
157
+ }
158
+ }
159
+ if (!route.hosted)
160
+ throw unavailable(attempts, false, now);
161
+ try {
162
+ const out = await client.providers.call({ provider: 'search', tool: route.hosted.tool, arguments: route.hosted.arguments }, options.signal ? { signal: options.signal } : undefined);
163
+ const cost = isRecord(out) && typeof out['cost_usd'] === 'number' ? out['cost_usd'] : undefined;
164
+ return { served_by: 'hosted', data: out, ...(cost === undefined ? {} : { cost_usd: cost }), ...(fallback === undefined ? {} : { fallback_reason: fallback }) };
165
+ }
166
+ catch (error) {
167
+ const code = codeOf(error);
168
+ if (HOSTED_BUDGET.has(code) || (error.status === 402 && code !== 'price_over_maximum')) {
169
+ throw unavailable([...attempts, attemptOf('hosted', error)], true, now);
170
+ }
171
+ if (HOSTED_TRANSIENT.has(code))
172
+ throw unavailable([...attempts, attemptOf('hosted', error)], false, now);
173
+ throw error;
174
+ }
175
+ }
176
+ export const sourcing = { read };
177
+ /**
178
+ * The same rule, for agent runs. Append it to the prompt of any run that holds `device:browser`.
179
+ */
180
+ export const SOURCING_RUN_RULE = [
181
+ 'Sourcing rule. Read people and pages from the person\'s own Mac first, and from Northlight\'s hosted search second. Reads only: never send, post, connect, follow or change anything.',
182
+ '- LinkedIn: use only `crtr device browser` (the site functions `getProfile`, `searchPeople`, `getCompany`). There is no hosted LinkedIn path: never search for a way around it. If the Mac cannot be used, skip LinkedIn, say so in your run log, and carry on with web search (`crtr search search`, which can surface public LinkedIn URLs) and GitHub.',
183
+ '- X profile or posts, and GitHub: try the Mac (X) or the linked account (`crtr integrations github read`) first; use `crtr search people x-profile` / `people github-user` (or `crtr search search --include-domains x.com` for posts) only after that failed with a code below.',
184
+ '- Web pages, companies, talks: `crtr search search`, `contents` and `answer`; there is no Mac path.',
185
+ '- Work email and phone: `crtr search people work-email`, only when the person was shown interest; there is no Mac path.',
186
+ 'Fall to the next path on: `device_offline`, `device_timeout`, `provider_not_connected`, `machine_required`, `helper_not_installed`, `browser_profile_not_open`, `site_signed_out`, `wrong_site`, `rate_limited`, `lib_broken`, `js_exception`.',
187
+ 'Do not fall to the next path on `NotFound`, `Validation`, `PermissionDenied` or `scope_missing`: that is the answer. Report it.',
188
+ 'On `rate_limited`, stop using that site; do not retry in a loop, and note the `retry_after_s`. On a hosted 402 (`limit_reached`, `payment_required`, `cap_exhausted`) or `price_over_maximum`, stop hosted calls and report the budget as used up. Never sleep and retry.',
189
+ ].join('\n');
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.781";
2
+ export declare const SDK_VERSION = "0.3.783";
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.781';
3
+ export const SDK_VERSION = '0.3.783';
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.781",
4
- "crouterContract": "1.84",
3
+ "version": "0.3.783",
4
+ "crouterContract": "1.86",
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.781",
48
- "@north-light/identity": "0.3.781",
49
- "@north-light/plugin": "0.3.781",
47
+ "@north-light/api": "0.3.783",
48
+ "@north-light/identity": "0.3.783",
49
+ "@north-light/plugin": "0.3.783",
50
50
  "jose": "^6.2.1"
51
51
  },
52
52
  "peerDependencies": {