@nathapp/nax-ai 0.1.2 → 0.1.3
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 +31 -0
- package/dist/auth/login-errors.d.ts +24 -0
- package/dist/auth/login-errors.d.ts.map +1 -0
- package/dist/auth/login-errors.js +40 -0
- package/dist/auth/login-errors.js.map +1 -0
- package/dist/auth/login-types.d.ts +90 -0
- package/dist/auth/login-types.d.ts.map +1 -0
- package/dist/auth/login-types.js +10 -0
- package/dist/auth/login-types.js.map +1 -0
- package/dist/auth/login.d.ts +15 -0
- package/dist/auth/login.d.ts.map +1 -0
- package/dist/auth/login.js +84 -0
- package/dist/auth/login.js.map +1 -0
- package/dist/auth/oauth-policy.d.ts.map +1 -1
- package/dist/auth/oauth-policy.js +2 -5
- package/dist/auth/oauth-policy.js.map +1 -1
- package/dist/auth/pi-auth.d.ts +45 -2
- package/dist/auth/pi-auth.d.ts.map +1 -1
- package/dist/auth/pi-auth.js +153 -0
- package/dist/auth/pi-auth.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -33,6 +33,37 @@ While the API is unstable, `latest` and `next` both point at the current 0.x rel
|
|
|
33
33
|
|
|
34
34
|
A `ToolDefinition` can carry an optional `constrainedSampling: { type: "json_schema"; strict: "prefer" | "require" }` to ask the provider to constrain a tool's arguments to its schema. Support is per-model, not caller-controllable — some models simply cannot honour it. `"prefer"` degrades silently to an unconstrained tool when the model lacks support, so a well-formed response is not evidence the constraint was applied; `"require"` throws instead of degrading.
|
|
35
35
|
|
|
36
|
+
### Logging in
|
|
37
|
+
|
|
38
|
+
`login()` obtains a credential and writes it to the store you pass. It covers
|
|
39
|
+
both api-key entry and OAuth, choosing between them when a provider offers
|
|
40
|
+
both, and returns metadata rather than the credential — the store already has
|
|
41
|
+
it.
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import { createFileCredentialStore, login } from "@nathapp/nax-ai";
|
|
45
|
+
|
|
46
|
+
const credentials = createFileCredentialStore({ path: `${homedir()}/.nax/credentials` });
|
|
47
|
+
|
|
48
|
+
const result = await login({
|
|
49
|
+
providerId: "openrouter",
|
|
50
|
+
credentials,
|
|
51
|
+
interaction: {
|
|
52
|
+
prompt: async (prompt) => ask(prompt.message), // your UI
|
|
53
|
+
notify: (event) => render(event),
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
// result: { providerId: "openrouter", method: "oauth", kind: "oauth" }
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Permitted OAuth flows are `openai-codex` and `openrouter`; see
|
|
60
|
+
`PERMITTED_OAUTH_FLOWS`. A provider outside that list keeps its api-key login.
|
|
61
|
+
|
|
62
|
+
There is no `logout`: removing a credential is `credentials.delete(providerId)`.
|
|
63
|
+
Note that nothing is revoked upstream — the provider-side token stays valid
|
|
64
|
+
until it expires, so a UI should say the credential was removed locally rather
|
|
65
|
+
than that the user was logged out.
|
|
66
|
+
|
|
36
67
|
## Scope
|
|
37
68
|
|
|
38
69
|
This package speaks a generic LLM vocabulary — models, messages, tool calls, usage, credentials. It knows nothing about any consumer's domain concepts, and that direction is one-way by design: consumers map onto their own types at their own boundary.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ProviderId } from "../types.ts";
|
|
2
|
+
import type { LoginMethod } from "./login-types.ts";
|
|
3
|
+
/**
|
|
4
|
+
* The provider offers no login method this package can run — either none at
|
|
5
|
+
* all, or not the one the caller named. Distinct from a policy refusal, which
|
|
6
|
+
* raises OAuthFlowProhibitedError: an absence and a prohibition send a reader
|
|
7
|
+
* to different problems.
|
|
8
|
+
*/
|
|
9
|
+
export declare class AuthMethodUnavailableError extends Error {
|
|
10
|
+
readonly providerId: ProviderId;
|
|
11
|
+
readonly requested: LoginMethod | undefined;
|
|
12
|
+
constructor(providerId: ProviderId, requested?: LoginMethod);
|
|
13
|
+
}
|
|
14
|
+
/** The user cancelled, or the caller aborted. Not a failure. */
|
|
15
|
+
export declare class LoginCancelledError extends Error {
|
|
16
|
+
readonly providerId: ProviderId;
|
|
17
|
+
constructor(providerId: ProviderId);
|
|
18
|
+
}
|
|
19
|
+
/** The flow ran and did not produce a usable credential. */
|
|
20
|
+
export declare class LoginFailedError extends Error {
|
|
21
|
+
readonly providerId: ProviderId;
|
|
22
|
+
constructor(providerId: ProviderId, reason: string);
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=login-errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login-errors.d.ts","sourceRoot":"","sources":["../../src/auth/login-errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;;;;GAKG;AACH,qBAAa,0BAA2B,SAAQ,KAAK;IACnD,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAIhC,QAAQ,CAAC,SAAS,EAAE,WAAW,GAAG,SAAS,CAAC;IAE5C,YAAY,UAAU,EAAE,UAAU,EAAE,SAAS,CAAC,EAAE,WAAW,EAS1D;CACF;AAED,gEAAgE;AAChE,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAEhC,YAAY,UAAU,EAAE,UAAU,EAIjC;CACF;AAED,4DAA4D;AAC5D,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAEhC,YAAY,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAIjD;CACF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The provider offers no login method this package can run — either none at
|
|
3
|
+
* all, or not the one the caller named. Distinct from a policy refusal, which
|
|
4
|
+
* raises OAuthFlowProhibitedError: an absence and a prohibition send a reader
|
|
5
|
+
* to different problems.
|
|
6
|
+
*/
|
|
7
|
+
export class AuthMethodUnavailableError extends Error {
|
|
8
|
+
providerId;
|
|
9
|
+
// Declared as `| undefined` rather than optional: under
|
|
10
|
+
// exactOptionalPropertyTypes, assigning a possibly-undefined parameter to an
|
|
11
|
+
// optional field is a type error.
|
|
12
|
+
requested;
|
|
13
|
+
constructor(providerId, requested) {
|
|
14
|
+
super(requested === undefined
|
|
15
|
+
? `Provider "${providerId}" offers no login method this package can run.`
|
|
16
|
+
: `Provider "${providerId}" does not offer "${requested}" login.`);
|
|
17
|
+
this.name = "AuthMethodUnavailableError";
|
|
18
|
+
this.providerId = providerId;
|
|
19
|
+
this.requested = requested;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** The user cancelled, or the caller aborted. Not a failure. */
|
|
23
|
+
export class LoginCancelledError extends Error {
|
|
24
|
+
providerId;
|
|
25
|
+
constructor(providerId) {
|
|
26
|
+
super(`Login to "${providerId}" was cancelled.`);
|
|
27
|
+
this.name = "LoginCancelledError";
|
|
28
|
+
this.providerId = providerId;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** The flow ran and did not produce a usable credential. */
|
|
32
|
+
export class LoginFailedError extends Error {
|
|
33
|
+
providerId;
|
|
34
|
+
constructor(providerId, reason) {
|
|
35
|
+
super(`Login to "${providerId}" failed: ${reason}`);
|
|
36
|
+
this.name = "LoginFailedError";
|
|
37
|
+
this.providerId = providerId;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=login-errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login-errors.js","sourceRoot":"","sources":["../../src/auth/login-errors.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IAC1C,UAAU,CAAa;IAChC,wDAAwD;IACxD,6EAA6E;IAC7E,kCAAkC;IACzB,SAAS,CAA0B;IAE5C,YAAY,UAAsB,EAAE,SAAuB;QACzD,KAAK,CACH,SAAS,KAAK,SAAS;YACrB,CAAC,CAAC,aAAa,UAAU,gDAAgD;YACzE,CAAC,CAAC,aAAa,UAAU,qBAAqB,SAAS,UAAU,CACpE,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;QACzC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CACF;AAED,gEAAgE;AAChE,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IACnC,UAAU,CAAa;IAEhC,YAAY,UAAsB;QAChC,KAAK,CAAC,aAAa,UAAU,kBAAkB,CAAC,CAAC;QACjD,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;QAClC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF;AAED,4DAA4D;AAC5D,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAChC,UAAU,CAAa;IAEhC,YAAY,UAAsB,EAAE,MAAc;QAChD,KAAK,CAAC,aAAa,UAAU,aAAa,MAAM,EAAE,CAAC,CAAC;QACpD,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The vocabulary of a login, in nax-ai's own terms.
|
|
3
|
+
*
|
|
4
|
+
* pi-ai's equivalents are snake_case (`auth_url`, `device_code`, `manual_code`,
|
|
5
|
+
* `api_key`); these are kebab-case, matching `ProtocolError.kind`'s
|
|
6
|
+
* `rate-limit` and `bad-request`. That translation is the boundary: it is what
|
|
7
|
+
* keeps a rename upstream from becoming a breaking change here.
|
|
8
|
+
*/
|
|
9
|
+
import type { CredentialStore, ProviderId, StoredCredential } from "../types.ts";
|
|
10
|
+
export type LoginMethod = "api-key" | "oauth";
|
|
11
|
+
export interface LoginOption {
|
|
12
|
+
readonly id: string;
|
|
13
|
+
readonly label: string;
|
|
14
|
+
readonly description?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* `signal` cancels this one prompt — a flow uses it when an out-of-band event
|
|
18
|
+
* resolves the step, e.g. a manual-code prompt raced against a callback
|
|
19
|
+
* server. It is not the whole login's signal, which lives on `LoginOptions`.
|
|
20
|
+
*/
|
|
21
|
+
export type LoginPrompt = {
|
|
22
|
+
readonly signal?: AbortSignal;
|
|
23
|
+
} & ({
|
|
24
|
+
readonly type: "text";
|
|
25
|
+
readonly message: string;
|
|
26
|
+
readonly placeholder?: string;
|
|
27
|
+
} | {
|
|
28
|
+
readonly type: "secret";
|
|
29
|
+
readonly message: string;
|
|
30
|
+
readonly placeholder?: string;
|
|
31
|
+
} | {
|
|
32
|
+
readonly type: "select";
|
|
33
|
+
readonly message: string;
|
|
34
|
+
readonly options: readonly LoginOption[];
|
|
35
|
+
} | {
|
|
36
|
+
readonly type: "manual-code";
|
|
37
|
+
readonly message: string;
|
|
38
|
+
readonly placeholder?: string;
|
|
39
|
+
});
|
|
40
|
+
export interface LoginLink {
|
|
41
|
+
readonly url: string;
|
|
42
|
+
readonly label?: string;
|
|
43
|
+
}
|
|
44
|
+
export type LoginEvent = {
|
|
45
|
+
readonly type: "info";
|
|
46
|
+
readonly message: string;
|
|
47
|
+
readonly links?: readonly LoginLink[];
|
|
48
|
+
} | {
|
|
49
|
+
readonly type: "auth-url";
|
|
50
|
+
readonly url: string;
|
|
51
|
+
readonly instructions?: string;
|
|
52
|
+
} | {
|
|
53
|
+
readonly type: "device-code";
|
|
54
|
+
readonly userCode: string;
|
|
55
|
+
readonly verificationUri: string;
|
|
56
|
+
readonly intervalSeconds?: number;
|
|
57
|
+
readonly expiresInSeconds?: number;
|
|
58
|
+
} | {
|
|
59
|
+
readonly type: "progress";
|
|
60
|
+
readonly message: string;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Login interaction, serving both api-key and OAuth flows.
|
|
64
|
+
*
|
|
65
|
+
* `prompt()` returns the entered text or, for `select`, the chosen option id.
|
|
66
|
+
* Reject it to cancel.
|
|
67
|
+
*/
|
|
68
|
+
export interface LoginInteraction {
|
|
69
|
+
prompt(prompt: LoginPrompt): Promise<string>;
|
|
70
|
+
notify(event: LoginEvent): void;
|
|
71
|
+
}
|
|
72
|
+
export interface LoginOptions {
|
|
73
|
+
readonly providerId: ProviderId;
|
|
74
|
+
readonly credentials: CredentialStore;
|
|
75
|
+
readonly interaction: LoginInteraction;
|
|
76
|
+
/** Skips the method prompt. Throws if the named method is unavailable. */
|
|
77
|
+
readonly method?: LoginMethod;
|
|
78
|
+
readonly signal?: AbortSignal;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Metadata, deliberately not the credential: `login()` has already written it
|
|
82
|
+
* to the store, and returning the secret would create a second copy with no
|
|
83
|
+
* consumer. A caller that cannot obtain it cannot leak it.
|
|
84
|
+
*/
|
|
85
|
+
export interface LoginResult {
|
|
86
|
+
readonly providerId: ProviderId;
|
|
87
|
+
readonly method: LoginMethod;
|
|
88
|
+
readonly kind: StoredCredential["kind"];
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=login-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login-types.d.ts","sourceRoot":"","sources":["../../src/auth/login-types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEjF,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,OAAO,CAAC;AAE9C,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,WAAW,CAAC,EAAE,MA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a,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;CACpC,GACD;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5D;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B,MAAM,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7C,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;CACjC;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,WAAW,EAAE,eAAe,CAAC;IACtC,QAAQ,CAAC,WAAW,EAAE,gBAAgB,CAAC;IACvC,0EAA0E;IAC1E,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC/B;AAED;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;CACzC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The vocabulary of a login, in nax-ai's own terms.
|
|
3
|
+
*
|
|
4
|
+
* pi-ai's equivalents are snake_case (`auth_url`, `device_code`, `manual_code`,
|
|
5
|
+
* `api_key`); these are kebab-case, matching `ProtocolError.kind`'s
|
|
6
|
+
* `rate-limit` and `bad-request`. That translation is the boundary: it is what
|
|
7
|
+
* keeps a rename upstream from becoming a breaking change here.
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=login-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login-types.js","sourceRoot":"","sources":["../../src/auth/login-types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Obtaining a credential, as opposed to holding or using one.
|
|
3
|
+
*
|
|
4
|
+
* This module never imports pi-ai: every provider-specific step is behind a
|
|
5
|
+
* LoginRunner that pi-auth.ts resolved. The credential is written to the
|
|
6
|
+
* caller's store before this returns, and never handed back.
|
|
7
|
+
*/
|
|
8
|
+
import type { LoginOptions, LoginResult } from "./login-types.ts";
|
|
9
|
+
import { resolveLoginTarget } from "./pi-auth.ts";
|
|
10
|
+
/** Test seam. */
|
|
11
|
+
export declare const _resolveTarget: {
|
|
12
|
+
resolve: typeof resolveLoginTarget;
|
|
13
|
+
};
|
|
14
|
+
export declare function login(options: LoginOptions): Promise<LoginResult>;
|
|
15
|
+
//# sourceMappingURL=login.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/auth/login.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAe,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/E,OAAO,EAAoB,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEpE,iBAAiB;AACjB,eAAO,MAAM,cAAc;IAAK,OAAO;CAAsB,CAAC;AA8C9D,wBAAsB,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,CAgCvE"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Obtaining a credential, as opposed to holding or using one.
|
|
3
|
+
*
|
|
4
|
+
* This module never imports pi-ai: every provider-specific step is behind a
|
|
5
|
+
* LoginRunner that pi-auth.ts resolved. The credential is written to the
|
|
6
|
+
* caller's store before this returns, and never handed back.
|
|
7
|
+
*/
|
|
8
|
+
import { AuthMethodUnavailableError, LoginCancelledError, LoginFailedError } from "./login-errors.js";
|
|
9
|
+
import { OAuthFlowProhibitedError } from "./oauth-policy.js";
|
|
10
|
+
import { resolveLoginTarget } from "./pi-auth.js";
|
|
11
|
+
/** Test seam. */
|
|
12
|
+
export const _resolveTarget = { resolve: resolveLoginTarget };
|
|
13
|
+
async function select(available, options, signal) {
|
|
14
|
+
const { providerId, method, interaction } = options;
|
|
15
|
+
if (method !== undefined) {
|
|
16
|
+
const named = available.find((choice) => choice.method === method);
|
|
17
|
+
if (named === undefined)
|
|
18
|
+
throw new AuthMethodUnavailableError(providerId, method);
|
|
19
|
+
return named;
|
|
20
|
+
}
|
|
21
|
+
const only = available.length === 1 ? available[0] : undefined;
|
|
22
|
+
if (only !== undefined)
|
|
23
|
+
return only;
|
|
24
|
+
const answer = await interaction.prompt({
|
|
25
|
+
type: "select",
|
|
26
|
+
message: `How do you want to sign in to "${providerId}"?`,
|
|
27
|
+
options: available.map((choice) => ({ id: choice.method, label: choice.runner.label })),
|
|
28
|
+
...(signal !== undefined ? { signal } : {}),
|
|
29
|
+
});
|
|
30
|
+
const picked = available.find((choice) => choice.method === answer);
|
|
31
|
+
// An unrecognised answer is not a reason to guess: falling back to the first
|
|
32
|
+
// method would bill against a credential path the user did not choose.
|
|
33
|
+
if (picked === undefined)
|
|
34
|
+
throw new AuthMethodUnavailableError(providerId);
|
|
35
|
+
return picked;
|
|
36
|
+
}
|
|
37
|
+
function isCancellation(error, signal) {
|
|
38
|
+
if (signal.aborted)
|
|
39
|
+
return true;
|
|
40
|
+
return error instanceof Error && error.name === "AbortError";
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A credential whose key is empty is not a credential. The store would accept
|
|
44
|
+
* it and every later call would fail with an auth error pointing nowhere near
|
|
45
|
+
* this login.
|
|
46
|
+
*/
|
|
47
|
+
function assertUsable(credential, providerId) {
|
|
48
|
+
if (credential.kind === "api-key" && credential.key.length === 0) {
|
|
49
|
+
throw new LoginFailedError(providerId, "the flow returned an empty API key");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export async function login(options) {
|
|
53
|
+
const { providerId, credentials, interaction, signal } = options;
|
|
54
|
+
const target = await _resolveTarget.resolve(providerId);
|
|
55
|
+
const available = [];
|
|
56
|
+
if (target.apiKey !== undefined)
|
|
57
|
+
available.push({ method: "api-key", runner: target.apiKey });
|
|
58
|
+
if (target.oauth !== undefined)
|
|
59
|
+
available.push({ method: "oauth", runner: target.oauth });
|
|
60
|
+
if (available.length === 0)
|
|
61
|
+
throw new AuthMethodUnavailableError(providerId);
|
|
62
|
+
const abort = signal ?? new AbortController().signal;
|
|
63
|
+
let chosen;
|
|
64
|
+
let credential;
|
|
65
|
+
try {
|
|
66
|
+
chosen = await select(available, options, abort);
|
|
67
|
+
credential = await chosen.runner.run(interaction, abort);
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
// A policy refusal keeps its own identity: its recorded reason is the
|
|
71
|
+
// point, and a generic failure would discard it.
|
|
72
|
+
if (error instanceof OAuthFlowProhibitedError)
|
|
73
|
+
throw error;
|
|
74
|
+
if (isCancellation(error, abort))
|
|
75
|
+
throw new LoginCancelledError(providerId);
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
assertUsable(credential, providerId);
|
|
79
|
+
// modify, never a bare write: it is what holds the store's lock across the
|
|
80
|
+
// whole read-modify-write.
|
|
81
|
+
await credentials.modify(providerId, async () => credential);
|
|
82
|
+
return { providerId, method: chosen.method, kind: credential.kind };
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=login.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login.js","sourceRoot":"","sources":["../../src/auth/login.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;A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CAAC;AAE9C;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,EAAE,SAAS,UAAU,
|
|
1
|
+
{"version":3,"file":"oauth-policy.d.ts","sourceRoot":"","sources":["../../src/auth/oauth-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,EAAE,SAAS,UAAU,EAAkD,CAAC;AAE1G;;;GAGG;AACH,eAAO,MAAM,sBAAsB,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,CAKtE,CAAC;AAEH,qBAAa,wBAAyB,SAAQ,KAAK;IACjD,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAEhC,YAAY,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAIjD;CACF;AAED,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAEpE;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAQrE"}
|
|
@@ -20,17 +20,14 @@
|
|
|
20
20
|
* provider whose terms permit third-party OAuth use, or whose flow is a
|
|
21
21
|
* first-party developer credential rather than a consumer subscription.
|
|
22
22
|
*/
|
|
23
|
-
export const PERMITTED_OAUTH_FLOWS = Object.freeze([
|
|
24
|
-
"openai-codex",
|
|
25
|
-
"github-copilot",
|
|
26
|
-
"openrouter",
|
|
27
|
-
]);
|
|
23
|
+
export const PERMITTED_OAUTH_FLOWS = Object.freeze(["openai-codex", "openrouter"]);
|
|
28
24
|
/**
|
|
29
25
|
* OAuth flows that must never be registered, with the reason recorded so a
|
|
30
26
|
* future reader does not "fix" the omission.
|
|
31
27
|
*/
|
|
32
28
|
export const PROHIBITED_OAUTH_FLOWS = Object.freeze({
|
|
33
29
|
anthropic: "Anthropic subscription OAuth outside the official Claude CLI is server-blocked and a Consumer ToS violation. Route Claude subscription traffic through the official CLI instead.",
|
|
30
|
+
"github-copilot": "Not cleared: the upstream catalog marks this flow isSubscription: true, which fails this allowlist's 'first-party developer credential rather than a consumer subscription' clause, and its terms were never checked against the other one. This is an unresolved terms question, not an established violation like anthropic's — a review may reverse it on evidence. The provider's api-key login is unaffected.",
|
|
34
31
|
});
|
|
35
32
|
export class OAuthFlowProhibitedError extends Error {
|
|
36
33
|
providerId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth-policy.js","sourceRoot":"","sources":["../../src/auth/oauth-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAA0B,MAAM,CAAC,MAAM,CAAC
|
|
1
|
+
{"version":3,"file":"oauth-policy.js","sourceRoot":"","sources":["../../src/auth/oauth-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAA0B,MAAM,CAAC,MAAM,CAAC,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC,CAAC;AAE1G;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAyC,MAAM,CAAC,MAAM,CAAC;IACxF,SAAS,EACP,kLAAkL;IACpL,gBAAgB,EACd,oZAAoZ;CACvZ,CAAC,CAAC;AAEH,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACxC,UAAU,CAAa;IAEhC,YAAY,UAAsB,EAAE,MAAc;QAChD,KAAK,CAAC,mBAAmB,UAAU,oBAAoB,MAAM,EAAE,CAAC,CAAC;QACjE,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;QACvC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF;AAED,MAAM,UAAU,oBAAoB,CAAC,UAAsB;IACzD,OAAO,qBAAqB,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;AACpD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CAAC,UAAsB;IAC7D,MAAM,gBAAgB,GAAG,sBAAsB,CAAC,UAAU,CAAC,CAAC;IAC5D,IAAI,gBAAgB,KAAK,SAAS,EAAE,CAAC;QACnC,MAAM,IAAI,wBAAwB,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAAC;IACnE,CAAC;IACD,IAAI,CAAC,oBAAoB,CAAC,UAAU,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,uBAAuB,UAAU,uBAAuB,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC/G,CAAC;AACH,CAAC"}
|
package/dist/auth/pi-auth.d.ts
CHANGED
|
@@ -4,9 +4,52 @@
|
|
|
4
4
|
* On the ALLOWED list in scripts/check-pi-ai-imports.ts. Nothing here leaks a
|
|
5
5
|
* pi-ai type through an export a consumer sees.
|
|
6
6
|
*/
|
|
7
|
-
import type { MutableModels, CredentialStore as PiCredentialStore } from "@earendil-works/pi-ai";
|
|
8
|
-
import type { CredentialStore } from "../types.ts";
|
|
7
|
+
import type { MutableModels, CredentialStore as PiCredentialStore, Provider as PiProvider } from "@earendil-works/pi-ai";
|
|
8
|
+
import type { CredentialStore, ProviderId, StoredCredential } from "../types.ts";
|
|
9
|
+
import type { LoginInteraction } from "./login-types.ts";
|
|
9
10
|
import type { AuthResolver } from "./resolver.ts";
|
|
10
11
|
export declare function toPiCredentialStore(store: CredentialStore): PiCredentialStore;
|
|
11
12
|
export declare function createPiAuthResolver(models: MutableModels): AuthResolver;
|
|
13
|
+
export interface LoginRunner {
|
|
14
|
+
/** Shown in the method prompt when a provider offers both. */
|
|
15
|
+
readonly label: string;
|
|
16
|
+
run(interaction: LoginInteraction, signal: AbortSignal): Promise<StoredCredential>;
|
|
17
|
+
}
|
|
18
|
+
export interface LoginTarget {
|
|
19
|
+
readonly apiKey?: LoginRunner;
|
|
20
|
+
readonly oauth?: LoginRunner;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Test seam. The real read is a dynamic import because pi-ai's provider table
|
|
24
|
+
* is large and only login needs it, matching pi-catalog.ts's own pattern.
|
|
25
|
+
*/
|
|
26
|
+
export declare const _loginDeps: {
|
|
27
|
+
providers: () => Promise<readonly PiProvider[]>;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Resolves which logins a provider can actually run.
|
|
31
|
+
*
|
|
32
|
+
* Reads pi's own two auth fields, NOT ResolvedProvider.auth: toProviderAuth
|
|
33
|
+
* resolves api-key over oauth when a provider declares both, which hides
|
|
34
|
+
* openrouter's OAuth flow (wrong) and anthropic's (right) indistinguishably.
|
|
35
|
+
*
|
|
36
|
+
* The allowlist is applied per method, not per provider, so a provider with a
|
|
37
|
+
* disallowed OAuth flow keeps its api-key login.
|
|
38
|
+
*/
|
|
39
|
+
export declare function resolveLoginTarget(providerId: ProviderId): Promise<LoginTarget>;
|
|
40
|
+
/**
|
|
41
|
+
* Whether ambient auth alone would satisfy this provider.
|
|
42
|
+
*
|
|
43
|
+
* Enumerating env var names cannot answer this: ProviderAuth.env is
|
|
44
|
+
* descriptive only, often absent, and never read by auth resolution. pi's own
|
|
45
|
+
* resolve() returns undefined when a provider is not configured and already
|
|
46
|
+
* merges env vars, AWS profiles and ADC files, so asking it with no credential
|
|
47
|
+
* is the question exactly. check() is the side-effect-free variant, preferred
|
|
48
|
+
* because resolve() may execute commands.
|
|
49
|
+
*
|
|
50
|
+
* A probe that throws is reported as "not available" rather than propagated:
|
|
51
|
+
* this only ever decorates a diagnostic, and breaking the command it decorates
|
|
52
|
+
* would be worse than a missing warning.
|
|
53
|
+
*/
|
|
54
|
+
export declare function ambientAuthAvailable(providerId: ProviderId): Promise<boolean>;
|
|
12
55
|
//# sourceMappingURL=pi-auth.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pi-auth.d.ts","sourceRoot":"","sources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,CAAC,OAAO,CAAC,CAiBnF"}
|
package/dist/auth/pi-auth.js
CHANGED
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
* On the ALLOWED list in scripts/check-pi-ai-imports.ts. Nothing here leaks a
|
|
5
5
|
* pi-ai type through an export a consumer sees.
|
|
6
6
|
*/
|
|
7
|
+
import { defaultProviderAuthContext } from "@earendil-works/pi-ai";
|
|
8
|
+
import { AuthMethodUnavailableError, LoginFailedError } from "./login-errors.js";
|
|
9
|
+
import { assertOAuthFlowPermitted, isOAuthFlowPermitted } from "./oauth-policy.js";
|
|
7
10
|
function toPi(credential) {
|
|
8
11
|
if (credential === undefined)
|
|
9
12
|
return undefined;
|
|
@@ -81,4 +84,154 @@ export function createPiAuthResolver(models) {
|
|
|
81
84
|
},
|
|
82
85
|
};
|
|
83
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Test seam. The real read is a dynamic import because pi-ai's provider table
|
|
89
|
+
* is large and only login needs it, matching pi-catalog.ts's own pattern.
|
|
90
|
+
*/
|
|
91
|
+
export const _loginDeps = {
|
|
92
|
+
providers: async () => {
|
|
93
|
+
const { builtinProviders } = await import("@earendil-works/pi-ai/providers/all");
|
|
94
|
+
return builtinProviders();
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
function required(credential, providerId) {
|
|
98
|
+
const stored = fromPi(credential);
|
|
99
|
+
if (stored === undefined)
|
|
100
|
+
throw new LoginFailedError(providerId, "the flow returned no credential");
|
|
101
|
+
return stored;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Resolves which logins a provider can actually run.
|
|
105
|
+
*
|
|
106
|
+
* Reads pi's own two auth fields, NOT ResolvedProvider.auth: toProviderAuth
|
|
107
|
+
* resolves api-key over oauth when a provider declares both, which hides
|
|
108
|
+
* openrouter's OAuth flow (wrong) and anthropic's (right) indistinguishably.
|
|
109
|
+
*
|
|
110
|
+
* The allowlist is applied per method, not per provider, so a provider with a
|
|
111
|
+
* disallowed OAuth flow keeps its api-key login.
|
|
112
|
+
*/
|
|
113
|
+
export async function resolveLoginTarget(providerId) {
|
|
114
|
+
const provider = (await _loginDeps.providers()).find((candidate) => candidate.id === providerId);
|
|
115
|
+
if (provider === undefined)
|
|
116
|
+
throw new AuthMethodUnavailableError(providerId);
|
|
117
|
+
const target = {};
|
|
118
|
+
const apiKeyAuth = provider.auth.apiKey;
|
|
119
|
+
if (apiKeyAuth?.login !== undefined) {
|
|
120
|
+
// bind rather than call detached: pi's flows are object methods and may
|
|
121
|
+
// read `this`.
|
|
122
|
+
const run = apiKeyAuth.login.bind(apiKeyAuth);
|
|
123
|
+
target.apiKey = {
|
|
124
|
+
label: apiKeyAuth.name,
|
|
125
|
+
run: async (interaction, signal) => required(await run({ ...toPiInteraction(interaction), signal }), providerId),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
const oauthAuth = provider.auth.oauth;
|
|
129
|
+
if (oauthAuth !== undefined && isOAuthFlowPermitted(providerId)) {
|
|
130
|
+
const run = oauthAuth.login.bind(oauthAuth);
|
|
131
|
+
target.oauth = {
|
|
132
|
+
label: oauthAuth.loginLabel ?? oauthAuth.name,
|
|
133
|
+
run: async (interaction, signal) => {
|
|
134
|
+
// Before the loader is touched, not after: pi bundles every flow behind
|
|
135
|
+
// one lazy loader, so the gate must sit in front of it.
|
|
136
|
+
assertOAuthFlowPermitted(providerId);
|
|
137
|
+
return required(await run({ ...toPiInteraction(interaction), signal }), providerId);
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
if (target.apiKey === undefined && provider.auth.oauth !== undefined) {
|
|
142
|
+
// The provider's only method is an OAuth flow this package refuses to run.
|
|
143
|
+
// A policy refusal must not read as an absence: throw the policy error
|
|
144
|
+
// rather than AuthMethodUnavailableError. assertOAuthFlowPermitted
|
|
145
|
+
// distinguishes prohibited (OAuthFlowProhibitedError) from unknown.
|
|
146
|
+
assertOAuthFlowPermitted(providerId);
|
|
147
|
+
}
|
|
148
|
+
return target;
|
|
149
|
+
}
|
|
150
|
+
function fromPiPrompt(prompt) {
|
|
151
|
+
const signal = prompt.signal !== undefined ? { signal: prompt.signal } : {};
|
|
152
|
+
switch (prompt.type) {
|
|
153
|
+
case "manual_code":
|
|
154
|
+
return {
|
|
155
|
+
...signal,
|
|
156
|
+
type: "manual-code",
|
|
157
|
+
message: prompt.message,
|
|
158
|
+
...(prompt.placeholder !== undefined ? { placeholder: prompt.placeholder } : {}),
|
|
159
|
+
};
|
|
160
|
+
case "select":
|
|
161
|
+
return { ...signal, type: "select", message: prompt.message, options: prompt.options };
|
|
162
|
+
default:
|
|
163
|
+
return {
|
|
164
|
+
...signal,
|
|
165
|
+
type: prompt.type,
|
|
166
|
+
message: prompt.message,
|
|
167
|
+
...(prompt.placeholder !== undefined ? { placeholder: prompt.placeholder } : {}),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function fromPiEvent(event) {
|
|
172
|
+
switch (event.type) {
|
|
173
|
+
case "auth_url":
|
|
174
|
+
return {
|
|
175
|
+
type: "auth-url",
|
|
176
|
+
url: event.url,
|
|
177
|
+
...(event.instructions !== undefined ? { instructions: event.instructions } : {}),
|
|
178
|
+
};
|
|
179
|
+
case "device_code":
|
|
180
|
+
return {
|
|
181
|
+
type: "device-code",
|
|
182
|
+
userCode: event.userCode,
|
|
183
|
+
verificationUri: event.verificationUri,
|
|
184
|
+
...(event.intervalSeconds !== undefined ? { intervalSeconds: event.intervalSeconds } : {}),
|
|
185
|
+
...(event.expiresInSeconds !== undefined ? { expiresInSeconds: event.expiresInSeconds } : {}),
|
|
186
|
+
};
|
|
187
|
+
case "info":
|
|
188
|
+
return { type: "info", message: event.message, ...(event.links !== undefined ? { links: event.links } : {}) };
|
|
189
|
+
default:
|
|
190
|
+
return { type: "progress", message: event.message };
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Presents a consumer's LoginInteraction to pi. pi calls us, so this maps
|
|
195
|
+
* inward: pi's snake_case names become nax-ai's kebab-case ones.
|
|
196
|
+
*/
|
|
197
|
+
function toPiInteraction(interaction) {
|
|
198
|
+
return {
|
|
199
|
+
prompt: async (prompt) => interaction.prompt(fromPiPrompt(prompt)),
|
|
200
|
+
notify: (event) => {
|
|
201
|
+
interaction.notify(fromPiEvent(event));
|
|
202
|
+
},
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Whether ambient auth alone would satisfy this provider.
|
|
207
|
+
*
|
|
208
|
+
* Enumerating env var names cannot answer this: ProviderAuth.env is
|
|
209
|
+
* descriptive only, often absent, and never read by auth resolution. pi's own
|
|
210
|
+
* resolve() returns undefined when a provider is not configured and already
|
|
211
|
+
* merges env vars, AWS profiles and ADC files, so asking it with no credential
|
|
212
|
+
* is the question exactly. check() is the side-effect-free variant, preferred
|
|
213
|
+
* because resolve() may execute commands.
|
|
214
|
+
*
|
|
215
|
+
* A probe that throws is reported as "not available" rather than propagated:
|
|
216
|
+
* this only ever decorates a diagnostic, and breaking the command it decorates
|
|
217
|
+
* would be worse than a missing warning.
|
|
218
|
+
*/
|
|
219
|
+
export async function ambientAuthAvailable(providerId) {
|
|
220
|
+
const provider = (await _loginDeps.providers()).find((candidate) => candidate.id === providerId);
|
|
221
|
+
const apiKey = provider?.auth.apiKey;
|
|
222
|
+
if (apiKey === undefined)
|
|
223
|
+
return false;
|
|
224
|
+
const ctx = defaultProviderAuthContext();
|
|
225
|
+
const signal = new AbortController().signal;
|
|
226
|
+
try {
|
|
227
|
+
// Bind rather than call detached: pi's auth objects are methods that may read `this`.
|
|
228
|
+
if (apiKey.check !== undefined) {
|
|
229
|
+
return (await apiKey.check.bind(apiKey)({ ctx, signal })) !== undefined;
|
|
230
|
+
}
|
|
231
|
+
return (await apiKey.resolve.bind(apiKey)({ ctx, signal })) !== undefined;
|
|
232
|
+
}
|
|
233
|
+
catch {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
84
237
|
//# sourceMappingURL=pi-auth.js.map
|
package/dist/auth/pi-auth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pi-auth.js","sourceRoot":"","sources":["../../src/auth/pi-auth.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"pi-auth.js","sourceRoot":"","sources":["../../src/auth/pi-auth.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAUH,OAAO,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAEnE,OAAO,EAAE,0BAA0B,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAEjF,OAAO,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAGnF,SAAS,IAAI,CAAC,UAAwC;IACpD,IAAI,UAAU,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC/C,IAAI,UAAU,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAClC,OAAO;YACL,IAAI,EAAE,SAAS;YACf,GAAG,EAAE,UAAU,CAAC,GAAG;YACnB,GAAG,CAAC,UAAU,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACxE,CAAC;IACJ,CAAC;IACD,OAAO;QACL,IAAI,EAAE,OAAO;QACb,MAAM,EAAE,UAAU,CAAC,MAAM;QACzB,OAAO,EAAE,UAAU,CAAC,OAAO;QAC3B,OAAO,EAAE,UAAU,CAAC,OAAO;KAC5B,CAAC;AACJ,CAAC;AAED,SAAS,MAAM,CAAC,UAAkC;IAChD,IAAI,UAAU,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC/C,IAAI,UAAU,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAClC,OAAO;YACL,IAAI,EAAE,SAAS;YACf,GAAG,EAAE,UAAU,CA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
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,11 @@
|
|
|
11
11
|
* this surface to be replaced — provider by provider — without consumers
|
|
12
12
|
* noticing.
|
|
13
13
|
*/
|
|
14
|
+
export { login } from "./auth/login.ts";
|
|
15
|
+
export { AuthMethodUnavailableError, LoginCancelledError, LoginFailedError, } from "./auth/login-errors.ts";
|
|
16
|
+
export type { LoginEvent, LoginInteraction, LoginLink, LoginMethod, LoginOption, LoginOptions, LoginPrompt, LoginResult, } from "./auth/login-types.ts";
|
|
14
17
|
export { assertOAuthFlowPermitted, isOAuthFlowPermitted, OAuthFlowProhibitedError, PERMITTED_OAUTH_FLOWS, PROHIBITED_OAUTH_FLOWS, } from "./auth/oauth-policy.ts";
|
|
18
|
+
export { ambientAuthAvailable } from "./auth/pi-auth.ts";
|
|
15
19
|
export type { AuthResolver, ResolvedAuth } from "./auth/resolver.ts";
|
|
16
20
|
export { type Client, type ClientOptions, type ClientRequest, createClient } from "./client.ts";
|
|
17
21
|
export { createFileCredentialStore, type FileCredentialStoreOptions, } from "./credentials/file-store.ts";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,EACxB,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAChC,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,aAAa,EAAE,KAAK,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChG,OAAO,EACL,yBAAyB,EACzB,KAAK,0BAA0B,GAChC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,aA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EAAE,gBAAgB,EAAE,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACzG,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,YAAY,EACV,OAAO,EACP,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,eAAe,EACf,cAAc,EACd,eAAe,EACf,OAAO,EACP,WAAW,EACX,QAAQ,EACR,UAAU,EACV,UAAU,EACV,gBAAgB,EAChB,UAAU,GACX,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -11,7 +11,10 @@
|
|
|
11
11
|
* this surface to be replaced — provider by provider — without consumers
|
|
12
12
|
* noticing.
|
|
13
13
|
*/
|
|
14
|
+
export { login } from "./auth/login.js";
|
|
15
|
+
export { AuthMethodUnavailableError, LoginCancelledError, LoginFailedError, } from "./auth/login-errors.js";
|
|
14
16
|
export { assertOAuthFlowPermitted, isOAuthFlowPermitted, OAuthFlowProhibitedError, PERMITTED_OAUTH_FLOWS, PROHIBITED_OAUTH_FLOWS, } from "./auth/oauth-policy.js";
|
|
17
|
+
export { ambientAuthAvailable } from "./auth/pi-auth.js";
|
|
15
18
|
export { createClient } from "./client.js";
|
|
16
19
|
export { createFileCredentialStore, } from "./credentials/file-store.js";
|
|
17
20
|
export { createMemoryCredentialStore } from "./credentials/memory-store.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,EACxB,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EACL,0BAA0B,EAC1B,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,wBAAwB,CAAC;AAWhC,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,EACxB,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEzD,OAAO,EAAuD,YAAY,EAAE,MAAM,aAAa,CAAC;AAChG,OAAO,EACL,yBAAyB,GAE1B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC5E,OAAO,EACL,iBAAiB,EAGjB,WAAW,GACZ,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAGL,cAAc,EAGd,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAgB7D,OAAO,EAAgB,gBAAgB,EAAmC,MAAM,wBAAwB,CAAC;AACzG,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAsBxD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAsB,MAAM,YAAY,CAAC"}
|
package/package.json
CHANGED