pi-plus-sdk 0.1.3 → 0.1.4

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.
Files changed (4) hide show
  1. package/README.md +8 -0
  2. package/api.d.ts +72 -3
  3. package/api.js +22 -17
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -37,6 +37,14 @@ await session.prompt("Review this repository");
37
37
  `materializeProfile/removeProfileDir/profileDirFor/AGENT_DIR/
38
38
  syncProfilePackagesToSource` for the per-profile agent dirs. Hosts get the
39
39
  exact contract the `pipi` CLI dispatches instead of reimplementing it.
40
+ - Provider login ships as a library (`src/auth.ts`): `loginProvider(providerId, { agentDir?, interaction?, signal?, method? })`
41
+ runs pi's model-runtime login flow (OAuth login page / API-key setup — the same
42
+ flow `pipi profile add <name> -p <provider>` triggers) and persists the credential
43
+ to `<agentDir>/auth.json`; `createTerminalAuthInteraction()` provides the readline
44
+ terminal UI for CLI use, and hosts pass their own `AuthInteraction` to drive the
45
+ prompts from a custom UI. pi-plus disables the TUI `/login` (the `interactive-mode`
46
+ and `slash-commands` core redirects are baked in here too), so this is the login
47
+ entry for the whole product.
40
48
  - `createPlusAgentSession()` extends the upstream `createAgentSession` (re-exported,
41
49
  with the whole upstream SDK surface) and always binds extensions once — do not call
42
50
  `session.bindExtensions()` yourself. Pass `ui` dialog handlers to get working
package/api.d.ts CHANGED
@@ -76,9 +76,6 @@ export interface AgentSettingsData {
76
76
 
77
77
  export declare const THINKING_LEVELS: string[];
78
78
 
79
- /** Marker stored in `profiles.json` `default` meaning "no profile, run plain pi". */
80
- export declare const BUILT_IN_DEFAULT: "__builtin__";
81
-
82
79
  /** Source agent dir (PI_CODING_AGENT_DIR or ~/.pi/agent): profiles without an applied profile. */
83
80
  export declare const AGENT_DIR: string;
84
81
 
@@ -95,3 +92,75 @@ export declare function profileDirFor(name: string): string;
95
92
  export declare function materializeProfile(name: string, profile: Profile): string;
96
93
  export declare function removeProfileDir(name: string): void;
97
94
  export declare function syncProfilePackagesToSource(profileDir: string): boolean;
95
+
96
+ /**
97
+ * Provider login: pi-plus's programmatic provider login bundled into api.js
98
+ * (packages/plus/src/auth/login.ts) — pi's interactive /login equivalent,
99
+ * which pi-plus disables in the TUI. The credential is persisted to
100
+ * <agentDir>/auth.json, the same store pi reads at launch. The auth
101
+ * vocabulary is declared inline because pi-ai is not a dependency of this
102
+ * package — keep it in sync with packages/ai/src/auth/types.ts.
103
+ */
104
+ export type AuthType = "api_key" | "oauth";
105
+
106
+ export interface ApiKeyCredential {
107
+ type: "api_key";
108
+ key?: string;
109
+ env?: Record<string, string>;
110
+ }
111
+
112
+ export interface OAuthCredential {
113
+ type: "oauth";
114
+ refresh: string;
115
+ access: string;
116
+ expires: number;
117
+ [key: string]: unknown;
118
+ }
119
+
120
+ export type Credential = ApiKeyCredential | OAuthCredential;
121
+
122
+ export interface AuthInfoLink {
123
+ url: string;
124
+ label?: string;
125
+ }
126
+
127
+ export type AuthPrompt = { signal?: AbortSignal } & (
128
+ | { type: "text"; message: string; placeholder?: string }
129
+ | { type: "secret"; message: string; placeholder?: string }
130
+ | { type: "select"; message: string; options: readonly { id: string; label: string; description?: string }[] }
131
+ | { type: "manual_code"; message: string; placeholder?: string }
132
+ );
133
+
134
+ export type AuthEvent =
135
+ | { type: "info"; message: string; links?: readonly AuthInfoLink[] }
136
+ | { type: "auth_url"; url: string; instructions?: string }
137
+ | {
138
+ type: "device_code";
139
+ userCode: string;
140
+ verificationUri: string;
141
+ intervalSeconds?: number;
142
+ expiresInSeconds?: number;
143
+ }
144
+ | { type: "progress"; message: string };
145
+
146
+ export interface AuthInteraction {
147
+ signal?: AbortSignal;
148
+ prompt(prompt: AuthPrompt): Promise<string>;
149
+ notify(event: AuthEvent): void;
150
+ }
151
+
152
+ export interface LoginProviderOptions {
153
+ /** Agent dir whose auth.json stores the credential. Defaults to the active agent dir. */
154
+ agentDir?: string;
155
+ /** Flow UI callbacks. Defaults to a terminal interaction (stdin prompts + browser). */
156
+ interaction?: AuthInteraction;
157
+ /** Cancels the flow. */
158
+ signal?: AbortSignal;
159
+ /** Force a login method; defaults to oauth when the provider offers it, then api_key. */
160
+ method?: AuthType;
161
+ }
162
+
163
+ export declare function loginProvider(providerId: string, options?: LoginProviderOptions): Promise<Credential>;
164
+
165
+ /** Readline-based AuthInteraction for terminal use (prompts on stdin, auth URLs opened in the browser). */
166
+ export declare function createTerminalAuthInteraction(): AuthInteraction;