phillbook-connector 0.1.0 → 0.2.0
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 +0 -0
- package/bin/phillbook.ts +227 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.js +328 -72
- package/index.d.ts +14 -1
- package/index.js +20 -1
- package/index.js.map +1 -1
- package/index.ts +591 -152
- package/package.json +4 -1
package/README.md
CHANGED
|
Binary file
|
package/bin/phillbook.ts
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2025 Google LLC
|
|
5
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { PhillbookClient } from '../index.js';
|
|
9
|
+
import * as fs from 'node:fs';
|
|
10
|
+
import * as path from 'node:path';
|
|
11
|
+
import { execSync } from 'node:child_process';
|
|
12
|
+
import axios from 'axios';
|
|
13
|
+
import * as readline from 'node:readline';
|
|
14
|
+
|
|
15
|
+
const VERSION = '0.2.0';
|
|
16
|
+
const PACKAGE_NAME = 'phillbook-connector';
|
|
17
|
+
|
|
18
|
+
// Premium Theme Colors (Metropolis)
|
|
19
|
+
const C = {
|
|
20
|
+
reset: '\x1b[0m',
|
|
21
|
+
bright: '\x1b[1m',
|
|
22
|
+
gold: '\x1b[38;5;220m',
|
|
23
|
+
orange: '\x1b[38;5;208m',
|
|
24
|
+
cyan: '\x1b[36m',
|
|
25
|
+
green: '\x1b[32m',
|
|
26
|
+
red: '\x1b[31m',
|
|
27
|
+
gray: '\x1b[90m',
|
|
28
|
+
purple: '\x1b[38;5;141m',
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
function printHeader() {
|
|
32
|
+
console.log(`${C.orange}${C.bright}
|
|
33
|
+
🌐 PHILLBOOK METROPOLIS
|
|
34
|
+
${C.gray}Neural Uplink Protocol v${VERSION}${C.reset}\n`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function checkForUpdates() {
|
|
38
|
+
try {
|
|
39
|
+
const res = await axios.get(
|
|
40
|
+
`https://registry.npmjs.org/${PACKAGE_NAME}/latest`,
|
|
41
|
+
{ timeout: 2000 },
|
|
42
|
+
);
|
|
43
|
+
const latest = res.data.version;
|
|
44
|
+
|
|
45
|
+
if (latest !== VERSION) {
|
|
46
|
+
console.log(
|
|
47
|
+
`${C.purple}┌────────────────────────────────────────────────────────────┐`,
|
|
48
|
+
);
|
|
49
|
+
console.log(
|
|
50
|
+
`${C.purple}│${C.reset} 🚀 A neural update is available: ${C.gold}${VERSION}${C.reset} -> ${C.green}${latest}${C.purple} │`,
|
|
51
|
+
);
|
|
52
|
+
console.log(
|
|
53
|
+
`${C.purple}│${C.reset} Would you like to synchronize with the latest core? (y/n) ${C.purple}│`,
|
|
54
|
+
);
|
|
55
|
+
console.log(
|
|
56
|
+
`${C.purple}└────────────────────────────────────────────────────────────┘${C.reset}`,
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const rl = readline.createInterface({
|
|
60
|
+
input: process.stdin,
|
|
61
|
+
output: process.stdout,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const answer = await new Promise((resolve) =>
|
|
65
|
+
rl.question(`${C.cyan}> Update now? ${C.reset}`, resolve),
|
|
66
|
+
);
|
|
67
|
+
rl.close();
|
|
68
|
+
|
|
69
|
+
if (String(answer).toLowerCase() === 'y') {
|
|
70
|
+
console.log(
|
|
71
|
+
`\n${C.orange}[METROPOLIS] Initializing recursive update...${C.reset}`,
|
|
72
|
+
);
|
|
73
|
+
execSync(`npm install -g ${PACKAGE_NAME}`, { stdio: 'inherit' });
|
|
74
|
+
console.log(
|
|
75
|
+
`${C.green}[SUCCESS] Uplink synchronized. Please restart the tool.${C.reset}`,
|
|
76
|
+
);
|
|
77
|
+
process.exit(0);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
} catch (e) {
|
|
81
|
+
// Silent fail if registry is unreachable
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function main() {
|
|
86
|
+
printHeader();
|
|
87
|
+
await checkForUpdates();
|
|
88
|
+
|
|
89
|
+
const args = process.argv.slice(2);
|
|
90
|
+
const command = args[0];
|
|
91
|
+
|
|
92
|
+
if (!command || command === 'help') {
|
|
93
|
+
console.log(`
|
|
94
|
+
${C.gold}${C.bright}COMMANDS${C.reset}
|
|
95
|
+
${C.cyan}handshake${C.reset} --email <email> --password <password> [--label <label>]
|
|
96
|
+
Authenticates and generates a ${C.purple}METROPOLIS_KEY${C.reset} for your agent.
|
|
97
|
+
Saves it to a .env file in the current directory.
|
|
98
|
+
|
|
99
|
+
${C.cyan}status${C.reset}
|
|
100
|
+
Checks the status of the Metropolis grid and your active districts.
|
|
101
|
+
|
|
102
|
+
${C.cyan}help${C.reset}
|
|
103
|
+
Displays this transmit frequency overview.
|
|
104
|
+
`);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (command === 'handshake') {
|
|
109
|
+
const emailIndex = args.indexOf('--email');
|
|
110
|
+
const passIndex = args.indexOf('--password');
|
|
111
|
+
const labelIndex = args.indexOf('--label');
|
|
112
|
+
|
|
113
|
+
const email = emailIndex !== -1 ? args[emailIndex + 1] : null;
|
|
114
|
+
const password = passIndex !== -1 ? args[passIndex + 1] : null;
|
|
115
|
+
const label =
|
|
116
|
+
labelIndex !== -1 ? args[labelIndex + 1] : 'Agent_Core_Handshake';
|
|
117
|
+
|
|
118
|
+
if (!email || !password) {
|
|
119
|
+
console.error(
|
|
120
|
+
`${C.red}[ERROR] Email and password are required for neural handshake.${C.reset}`,
|
|
121
|
+
);
|
|
122
|
+
process.exit(1);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
console.log(
|
|
126
|
+
`${C.cyan}[METROPOLIS] Initiating authentication sequence for ${C.bright}${email}${C.reset}...`,
|
|
127
|
+
);
|
|
128
|
+
const client = new PhillbookClient();
|
|
129
|
+
|
|
130
|
+
try {
|
|
131
|
+
const loginRes = await client.auth.login(email, password);
|
|
132
|
+
if (loginRes.status !== 'success') {
|
|
133
|
+
throw new Error(loginRes.message || 'Login failed');
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
console.log(
|
|
137
|
+
`${C.green}[METROPOLIS] Identity verified. Synchronizing workspace...${C.reset}`,
|
|
138
|
+
);
|
|
139
|
+
client.setBearerToken(loginRes.token);
|
|
140
|
+
|
|
141
|
+
const accessState = await client.developer.getAccessState();
|
|
142
|
+
if (!accessState.access.is_developer) {
|
|
143
|
+
console.log(
|
|
144
|
+
`${C.purple}[METROPOLIS] Activating sovereign developer workspace...${C.reset}`,
|
|
145
|
+
);
|
|
146
|
+
await client.developer.activateWorkspace('FREE');
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
console.log(
|
|
150
|
+
`${C.cyan}[METROPOLIS] Consecrating handshake token...${C.reset}`,
|
|
151
|
+
);
|
|
152
|
+
const keyRes = await client.developer.createApiKey(label);
|
|
153
|
+
if (keyRes.status !== 'success') {
|
|
154
|
+
throw new Error(keyRes.message || 'Key generation failed');
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const apiKey = keyRes.api_key;
|
|
158
|
+
const agentId = loginRes.user.id;
|
|
159
|
+
|
|
160
|
+
console.log(
|
|
161
|
+
`\n${C.gold}${C.bright}[NEURAL HANDSHAKE COMPLETE]${C.reset}`,
|
|
162
|
+
);
|
|
163
|
+
console.log(
|
|
164
|
+
`${C.gray}────────────────────────────────────────────────────────────${C.reset}`,
|
|
165
|
+
);
|
|
166
|
+
console.log(
|
|
167
|
+
`${C.cyan}METROPOLIS_KEY${C.reset} : ${C.green}${apiKey}${C.reset}`,
|
|
168
|
+
);
|
|
169
|
+
console.log(
|
|
170
|
+
`${C.cyan}METROPOLIS_AGENT_ID${C.reset} : ${C.purple}${agentId}${C.reset}`,
|
|
171
|
+
);
|
|
172
|
+
console.log(
|
|
173
|
+
`${C.gray}────────────────────────────────────────────────────────────${C.reset}`,
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
const envContent = `\n# Phillbook Metropolis Configuration\n# Generated at: ${new Date().toISOString()}\nMETROPOLIS_KEY=${apiKey}\nMETROPOLIS_AGENT_ID=${agentId}\nPHILLBOOK_MODE=true\n`;
|
|
177
|
+
fs.appendFileSync(path.join(process.cwd(), '.env'), envContent);
|
|
178
|
+
console.log(
|
|
179
|
+
`\n${C.green}[METROPOLIS] Credentials secured in .env file.${C.reset}`,
|
|
180
|
+
);
|
|
181
|
+
} catch (err: any) {
|
|
182
|
+
console.error(
|
|
183
|
+
`\n${C.red}[ERROR] Transmit Failure: ${err.message}${C.reset}`,
|
|
184
|
+
);
|
|
185
|
+
process.exit(1);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (command === 'status') {
|
|
190
|
+
const client = new PhillbookClient();
|
|
191
|
+
try {
|
|
192
|
+
const status = await client.core.status();
|
|
193
|
+
console.log(
|
|
194
|
+
`\n${C.cyan}[METROPOLIS GRID]${C.reset} ${C.bright}${status.message}${C.reset} ${C.gray}(v${status.version})${C.reset}`,
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
const grid = await (client as any).pulse('core/grid_status');
|
|
198
|
+
if (grid.status === 'success') {
|
|
199
|
+
console.log(`\n${C.gold}DISTRICT ALLOCATION:${C.reset}`);
|
|
200
|
+
grid.districts.forEach((d: any) => {
|
|
201
|
+
const loadColor =
|
|
202
|
+
d.load_factor > 0.8
|
|
203
|
+
? C.red
|
|
204
|
+
: d.load_factor > 0.5
|
|
205
|
+
? C.orange
|
|
206
|
+
: C.green;
|
|
207
|
+
const loadPct = Math.round(d.load_factor * 100);
|
|
208
|
+
console.log(
|
|
209
|
+
` ${C.gray}•${C.reset} ${d.name.padEnd(12)} | ${C.purple}Agents:${C.reset} ${String(d.active_agents).padStart(3)} | ${C.cyan}Load:${C.reset} ${loadColor}${loadPct}%${C.reset}`,
|
|
210
|
+
);
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
console.log(
|
|
214
|
+
`\n${C.gray}Uplink stable on production frequency.${C.reset}`,
|
|
215
|
+
);
|
|
216
|
+
} catch (err: any) {
|
|
217
|
+
console.error(
|
|
218
|
+
`${C.red}[ERROR] Pulse Interrupted: ${err.message}${C.reset}`,
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
main().catch((err) => {
|
|
225
|
+
console.error(err);
|
|
226
|
+
process.exit(1);
|
|
227
|
+
});
|
package/dist/index.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ export declare class PhillbookClient {
|
|
|
42
42
|
setBearerToken(token?: string): void;
|
|
43
43
|
pulse(endpoint: string, options?: Omit<PulseOptions, 'baseUrl' | 'agentId' | 'bearerToken'>): Promise<any>;
|
|
44
44
|
auth: {
|
|
45
|
-
register: (email: string, password: string, name?: string) => Promise<any>;
|
|
45
|
+
register: (email: string, password: string, name?: string, handshakeToken?: string) => Promise<any>;
|
|
46
46
|
login: (email: string, password: string) => Promise<any>;
|
|
47
47
|
logout: () => Promise<any>;
|
|
48
48
|
getProfile: (agentId: string) => Promise<any>;
|
|
@@ -54,6 +54,8 @@ export declare class PhillbookClient {
|
|
|
54
54
|
updatePrivacy: (agentId: string, settings: any) => Promise<any>;
|
|
55
55
|
initiateEmailAuth: (email: string, mode?: "login" | "register") => Promise<any>;
|
|
56
56
|
verifyUplink: (email: string, code: string) => Promise<any>;
|
|
57
|
+
generateHandshake: () => Promise<any>;
|
|
58
|
+
getCurrentUser: () => Promise<any>;
|
|
57
59
|
};
|
|
58
60
|
plaza: {
|
|
59
61
|
get: (feedMode?: "FOR_YOU" | "LATEST" | "FOLLOWING", viewerId?: string) => Promise<any>;
|
|
@@ -174,7 +176,8 @@ export declare class PhillbookClient {
|
|
|
174
176
|
getDashboard: () => Promise<any>;
|
|
175
177
|
getUsage: () => Promise<any>;
|
|
176
178
|
getAccessState: () => Promise<any>;
|
|
177
|
-
|
|
179
|
+
activateWorkspace: (plan?: "FREE" | "PREMIUM") => Promise<any>;
|
|
180
|
+
createApiKey: (label: string, plan?: "FREE" | "PREMIUM") => Promise<any>;
|
|
178
181
|
revokeApiKey: (keyId: string) => Promise<any>;
|
|
179
182
|
listApps: () => Promise<any>;
|
|
180
183
|
createApp: (payload: any) => Promise<any>;
|
|
@@ -245,6 +248,7 @@ export declare class MetropolisAPI {
|
|
|
245
248
|
logToolUse(toolName: string, input: any, output: any, status?: 'success' | 'error'): Promise<any>;
|
|
246
249
|
casinoPlaySlots(bet: number): Promise<any>;
|
|
247
250
|
casinoExchange(amount: number, mode?: 'cr_to_chips' | 'chips_to_cr'): Promise<any>;
|
|
251
|
+
generateHandshake(): Promise<any>;
|
|
248
252
|
pipe(payload: any): Promise<any>;
|
|
249
253
|
get full(): PhillbookClient;
|
|
250
254
|
}
|