pi-plus-sdk 0.1.2 → 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 +17 -2
  2. package/api.d.ts +122 -0
  3. package/api.js +156 -148
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -28,8 +28,23 @@ await session.prompt("Review this repository");
28
28
  baked into `api.js` by the shared bundle-time redirect plugin, and the nine
29
29
  non-TUI pi-plus extensions (subagent, tasks, memory, plan, ask-user, hooks,
30
30
  context-guard, `/cd`, `/init`) are registered exactly as the CLI wrapper registers them. No CLI
31
- logic ships in this artifact: no hub dispatch, no completion, no pipi help text,
32
- no banner/vim/tab-title/plain-tools.
31
+ logic ships in this artifact: no hub command dispatch (`pipi profile ...`), no
32
+ completion, no pipi help text, no banner/vim/tab-title/plain-tools.
33
+ - Profile management ships as a library: the curated `@earendil-works/pi-hub`
34
+ surface is re-exported (`src/profiles.ts`) — `loadProfiles/findProfile/
35
+ addProfile/updateProfile/removeProfile/renameProfile/setDefaultProfile/
36
+ clearDefaultProfile/getDefaultProfileName` for `~/.pi/profiles.json`, and
37
+ `materializeProfile/removeProfileDir/profileDirFor/AGENT_DIR/
38
+ syncProfilePackagesToSource` for the per-profile agent dirs. Hosts get the
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.
33
48
  - `createPlusAgentSession()` extends the upstream `createAgentSession` (re-exported,
34
49
  with the whole upstream SDK surface) and always binds extensions once — do not call
35
50
  `session.bindExtensions()` yourself. Pass `ui` dialog handlers to get working
package/api.d.ts CHANGED
@@ -42,3 +42,125 @@ export interface CreatePlusAgentSessionOptions extends CreateAgentSessionOptions
42
42
  export declare function createPlusAgentSession(
43
43
  options?: CreatePlusAgentSessionOptions,
44
44
  ): Promise<CreateAgentSessionResult>;
45
+
46
+ /**
47
+ * Profile management: the curated @earendil-works/pi-hub surface bundled into
48
+ * api.js (profiles.json CRUD + per-profile materialized agent dirs). Types are
49
+ * declared inline because pi-hub is not a dependency of this package — keep
50
+ * them in sync with packages/hub/src/types.ts.
51
+ */
52
+ export interface Profile {
53
+ provider?: string;
54
+ model?: string;
55
+ models?: string[];
56
+ thinking?: string;
57
+ token?: string;
58
+ url?: string;
59
+ /** Arbitrary settings.json overrides, merged over the source agent settings.
60
+ * A null value deletes the key from the materialized settings.json. */
61
+ settings?: Record<string, unknown>;
62
+ }
63
+
64
+ export interface ProfilesData {
65
+ profiles: Record<string, Profile>;
66
+ default?: string;
67
+ }
68
+
69
+ export interface AgentSettingsData {
70
+ defaultProvider?: string;
71
+ defaultModel?: string;
72
+ defaultThinkingLevel?: string;
73
+ skills?: unknown;
74
+ [key: string]: unknown;
75
+ }
76
+
77
+ export declare const THINKING_LEVELS: string[];
78
+
79
+ /** Source agent dir (PI_CODING_AGENT_DIR or ~/.pi/agent): profiles without an applied profile. */
80
+ export declare const AGENT_DIR: string;
81
+
82
+ export declare function loadProfiles(): ProfilesData;
83
+ export declare function findProfile(name: string): Profile | undefined;
84
+ export declare function getDefaultProfileName(): string | undefined;
85
+ export declare function setDefaultProfile(name: string): void;
86
+ export declare function clearDefaultProfile(): void;
87
+ export declare function addProfile(name: string, profile: Profile): void;
88
+ export declare function updateProfile(name: string, profile: Profile): void;
89
+ export declare function removeProfile(name: string): void;
90
+ export declare function renameProfile(oldName: string, newName: string): void;
91
+ export declare function profileDirFor(name: string): string;
92
+ export declare function materializeProfile(name: string, profile: Profile): string;
93
+ export declare function removeProfileDir(name: string): void;
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;