@diegoaltoworks/chatter 0.12.0 → 0.14.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/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/bin/create-apikey.js +194 -0
- package/dist/client/index.d.ts +2 -2
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/src/browser.d.ts +1 -1
- package/dist/client/src/browser.d.ts.map +1 -1
- package/dist/client/src/index.d.ts +2 -2
- package/dist/client/src/index.d.ts.map +1 -1
- package/dist/core/widgets.d.ts.map +1 -1
- package/dist/index.d.ts +14 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2694 -2679
- package/dist/index.mjs +4949 -4938
- package/dist/mcp-server/index.d.ts +4 -4
- package/dist/mcp-server/index.d.ts.map +1 -1
- package/dist/mcp-server.d.ts.map +1 -1
- package/dist/mcp-server.js +9 -12
- package/dist/mcp-server.mjs +10 -13
- package/dist/middleware/jwt.d.ts.map +1 -1
- package/dist/static/chatter.css +8 -4
- package/package.json +33 -21
- package/bin/create-apikey.ts +0 -101
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Modular implementation of the Model Context Protocol server
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
7
|
-
export * from "./cost-tracker";
|
|
8
|
-
export * from "./rate-limiter";
|
|
6
|
+
export { createMCPServer } from "../mcp-server";
|
|
9
7
|
export * from "./conversation-id";
|
|
8
|
+
export * from "./cost-tracker";
|
|
10
9
|
export * from "./logger";
|
|
11
|
-
export
|
|
10
|
+
export * from "./rate-limiter";
|
|
11
|
+
export * from "./types";
|
|
12
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp-server/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp-server/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,cAAc,mBAAmB,CAAC;AAElC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAE/B,cAAc,SAAS,CAAC"}
|
package/dist/mcp-server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../src/mcp-server.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAapE,YAAY,EACV,WAAW,EACX,QAAQ,EACR,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../src/mcp-server.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAapE,YAAY,EACV,WAAW,EACX,QAAQ,EACR,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,eAAe,CAAC,MAAM,EAAE,gBAAgB,sBAuS7D"}
|
package/dist/mcp-server.js
CHANGED
|
@@ -81,6 +81,8 @@ var PromptLoader = class {
|
|
|
81
81
|
this.promptsDir = promptsDir;
|
|
82
82
|
this.bot = bot;
|
|
83
83
|
}
|
|
84
|
+
promptsDir;
|
|
85
|
+
bot;
|
|
84
86
|
/**
|
|
85
87
|
* Load a prompt template and interpolate variables
|
|
86
88
|
*/
|
|
@@ -164,6 +166,7 @@ var VectorStore = class _VectorStore {
|
|
|
164
166
|
});
|
|
165
167
|
this.knowledgeDir = options.knowledgeDir || "./config/knowledge";
|
|
166
168
|
}
|
|
169
|
+
client;
|
|
167
170
|
db;
|
|
168
171
|
knowledgeDir;
|
|
169
172
|
// On boot: ingest new chunks and embed only missing ones.
|
|
@@ -480,7 +483,7 @@ async function createMCPServer(config) {
|
|
|
480
483
|
});
|
|
481
484
|
console.log("\u2705 MCP server initialized");
|
|
482
485
|
if (publicToolConfig.enabled) {
|
|
483
|
-
const
|
|
486
|
+
const publicShape = {
|
|
484
487
|
message: import_zod.z.string().optional().describe("A single message to send (for simple queries)"),
|
|
485
488
|
messages: import_zod.z.array(
|
|
486
489
|
import_zod.z.object({
|
|
@@ -491,15 +494,12 @@ async function createMCPServer(config) {
|
|
|
491
494
|
conversationId: import_zod.z.string().optional().describe(
|
|
492
495
|
"Optional conversation ID to track sessions. If not provided, a new ID will be generated."
|
|
493
496
|
)
|
|
494
|
-
}
|
|
495
|
-
(data) => data.message !== void 0 || data.messages !== void 0,
|
|
496
|
-
"Either 'message' or 'messages' must be provided"
|
|
497
|
-
);
|
|
497
|
+
};
|
|
498
498
|
server.registerTool(
|
|
499
499
|
publicToolConfig.name,
|
|
500
500
|
{
|
|
501
501
|
description: publicToolConfig.description,
|
|
502
|
-
inputSchema:
|
|
502
|
+
inputSchema: publicShape
|
|
503
503
|
},
|
|
504
504
|
async (args) => {
|
|
505
505
|
const { message, messages, conversationId } = args;
|
|
@@ -567,7 +567,7 @@ ${ctx.join("\n\n")}`
|
|
|
567
567
|
console.log(`\u2705 Registered tool: ${publicToolConfig.name}`);
|
|
568
568
|
}
|
|
569
569
|
if (privateToolConfig.enabled) {
|
|
570
|
-
const
|
|
570
|
+
const privateShape = {
|
|
571
571
|
message: import_zod.z.string().optional().describe("A single message to send (for simple queries)"),
|
|
572
572
|
messages: import_zod.z.array(
|
|
573
573
|
import_zod.z.object({
|
|
@@ -578,15 +578,12 @@ ${ctx.join("\n\n")}`
|
|
|
578
578
|
conversationId: import_zod.z.string().optional().describe(
|
|
579
579
|
"Optional conversation ID to track sessions. If not provided, a new ID will be generated."
|
|
580
580
|
)
|
|
581
|
-
}
|
|
582
|
-
(data) => data.message !== void 0 || data.messages !== void 0,
|
|
583
|
-
"Either 'message' or 'messages' must be provided"
|
|
584
|
-
);
|
|
581
|
+
};
|
|
585
582
|
server.registerTool(
|
|
586
583
|
privateToolConfig.name,
|
|
587
584
|
{
|
|
588
585
|
description: privateToolConfig.description,
|
|
589
|
-
inputSchema:
|
|
586
|
+
inputSchema: privateShape
|
|
590
587
|
},
|
|
591
588
|
async (args) => {
|
|
592
589
|
const { message, messages, conversationId } = args;
|
package/dist/mcp-server.mjs
CHANGED
|
@@ -47,6 +47,8 @@ var PromptLoader = class {
|
|
|
47
47
|
this.promptsDir = promptsDir;
|
|
48
48
|
this.bot = bot;
|
|
49
49
|
}
|
|
50
|
+
promptsDir;
|
|
51
|
+
bot;
|
|
50
52
|
/**
|
|
51
53
|
* Load a prompt template and interpolate variables
|
|
52
54
|
*/
|
|
@@ -74,7 +76,7 @@ var PromptLoader = class {
|
|
|
74
76
|
import { createClient } from "@libsql/client";
|
|
75
77
|
|
|
76
78
|
// src/core/loaders.ts
|
|
77
|
-
import { readFileSync as readFileSync2,
|
|
79
|
+
import { readdirSync, readFileSync as readFileSync2, statSync } from "node:fs";
|
|
78
80
|
import { join as join2 } from "node:path";
|
|
79
81
|
function walk(dir) {
|
|
80
82
|
const items = [];
|
|
@@ -130,6 +132,7 @@ var VectorStore = class _VectorStore {
|
|
|
130
132
|
});
|
|
131
133
|
this.knowledgeDir = options.knowledgeDir || "./config/knowledge";
|
|
132
134
|
}
|
|
135
|
+
client;
|
|
133
136
|
db;
|
|
134
137
|
knowledgeDir;
|
|
135
138
|
// On boot: ingest new chunks and embed only missing ones.
|
|
@@ -446,7 +449,7 @@ async function createMCPServer(config) {
|
|
|
446
449
|
});
|
|
447
450
|
console.log("\u2705 MCP server initialized");
|
|
448
451
|
if (publicToolConfig.enabled) {
|
|
449
|
-
const
|
|
452
|
+
const publicShape = {
|
|
450
453
|
message: z.string().optional().describe("A single message to send (for simple queries)"),
|
|
451
454
|
messages: z.array(
|
|
452
455
|
z.object({
|
|
@@ -457,15 +460,12 @@ async function createMCPServer(config) {
|
|
|
457
460
|
conversationId: z.string().optional().describe(
|
|
458
461
|
"Optional conversation ID to track sessions. If not provided, a new ID will be generated."
|
|
459
462
|
)
|
|
460
|
-
}
|
|
461
|
-
(data) => data.message !== void 0 || data.messages !== void 0,
|
|
462
|
-
"Either 'message' or 'messages' must be provided"
|
|
463
|
-
);
|
|
463
|
+
};
|
|
464
464
|
server.registerTool(
|
|
465
465
|
publicToolConfig.name,
|
|
466
466
|
{
|
|
467
467
|
description: publicToolConfig.description,
|
|
468
|
-
inputSchema:
|
|
468
|
+
inputSchema: publicShape
|
|
469
469
|
},
|
|
470
470
|
async (args) => {
|
|
471
471
|
const { message, messages, conversationId } = args;
|
|
@@ -533,7 +533,7 @@ ${ctx.join("\n\n")}`
|
|
|
533
533
|
console.log(`\u2705 Registered tool: ${publicToolConfig.name}`);
|
|
534
534
|
}
|
|
535
535
|
if (privateToolConfig.enabled) {
|
|
536
|
-
const
|
|
536
|
+
const privateShape = {
|
|
537
537
|
message: z.string().optional().describe("A single message to send (for simple queries)"),
|
|
538
538
|
messages: z.array(
|
|
539
539
|
z.object({
|
|
@@ -544,15 +544,12 @@ ${ctx.join("\n\n")}`
|
|
|
544
544
|
conversationId: z.string().optional().describe(
|
|
545
545
|
"Optional conversation ID to track sessions. If not provided, a new ID will be generated."
|
|
546
546
|
)
|
|
547
|
-
}
|
|
548
|
-
(data) => data.message !== void 0 || data.messages !== void 0,
|
|
549
|
-
"Either 'message' or 'messages' must be provided"
|
|
550
|
-
);
|
|
547
|
+
};
|
|
551
548
|
server.registerTool(
|
|
552
549
|
privateToolConfig.name,
|
|
553
550
|
{
|
|
554
551
|
description: privateToolConfig.description,
|
|
555
|
-
inputSchema:
|
|
552
|
+
inputSchema: privateShape
|
|
556
553
|
},
|
|
557
554
|
async (args) => {
|
|
558
555
|
const { message, messages, conversationId } = args;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../src/middleware/jwt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../src/middleware/jwt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAO9C;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,aAAa,IAwBf,GAAG,OAAO,EAAE,MAAM,IAAI;;8BAa/D;AAGD,eAAO,MAAM,iBAAiB,MAhBe,OAAO,QAAQ,IAAI;;6BAgBS,CAAC"}
|
package/dist/static/chatter.css
CHANGED
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
border-radius: 12px;
|
|
13
13
|
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
|
14
14
|
overflow: hidden;
|
|
15
|
-
font-family:
|
|
16
|
-
sans-serif;
|
|
15
|
+
font-family:
|
|
16
|
+
-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/* Header */
|
|
@@ -152,7 +152,9 @@
|
|
|
152
152
|
display: flex;
|
|
153
153
|
align-items: center;
|
|
154
154
|
justify-content: center;
|
|
155
|
-
transition:
|
|
155
|
+
transition:
|
|
156
|
+
transform 0.2s,
|
|
157
|
+
opacity 0.2s;
|
|
156
158
|
flex-shrink: 0;
|
|
157
159
|
}
|
|
158
160
|
|
|
@@ -181,7 +183,9 @@
|
|
|
181
183
|
font-size: 24px;
|
|
182
184
|
cursor: pointer;
|
|
183
185
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
|
|
184
|
-
transition:
|
|
186
|
+
transition:
|
|
187
|
+
transform 0.2s,
|
|
188
|
+
box-shadow 0.2s;
|
|
185
189
|
z-index: 9998;
|
|
186
190
|
display: flex;
|
|
187
191
|
align-items: center;
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diegoaltoworks/chatter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Embeddable AI chatbot framework with RAG, authentication, and customizable widgets",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
8
|
"bin": {
|
|
9
|
-
"chatter": "./bin/create-apikey.
|
|
9
|
+
"chatter": "./dist/bin/create-apikey.js"
|
|
10
10
|
},
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
@@ -30,15 +30,20 @@
|
|
|
30
30
|
"require": "./dist/mcp-server.js"
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
|
-
"files": [
|
|
33
|
+
"files": [
|
|
34
|
+
"dist",
|
|
35
|
+
"README.md",
|
|
36
|
+
"LICENSE"
|
|
37
|
+
],
|
|
34
38
|
"scripts": {
|
|
35
39
|
"dev": "bun --watch src/index.ts",
|
|
36
|
-
"build": "bun run build:clean && bun run build:types && bun run build:esm && bun run build:cjs && bun run build:mcp && bun run build:client && bun run build:copy-client",
|
|
40
|
+
"build": "bun run build:clean && bun run build:types && bun run build:esm && bun run build:cjs && bun run build:mcp && bun run build:bin && bun run build:client && bun run build:copy-client",
|
|
37
41
|
"build:clean": "rm -rf dist",
|
|
38
42
|
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
39
43
|
"build:esm": "esbuild src/index.ts --bundle --format=esm --outfile=dist/index.mjs --external:hono --external:openai --external:@libsql/client --external:jose --platform=node --target=node24",
|
|
40
44
|
"build:cjs": "esbuild src/index.ts --bundle --format=cjs --outfile=dist/index.js --external:hono --external:openai --external:@libsql/client --external:jose --platform=node --target=node24",
|
|
41
45
|
"build:mcp": "esbuild src/mcp-server.ts --bundle --format=esm --outfile=dist/mcp-server.mjs --external:@modelcontextprotocol/sdk --external:openai --external:@libsql/client --external:zod --platform=node --target=node24 && esbuild src/mcp-server.ts --bundle --format=cjs --outfile=dist/mcp-server.js --external:@modelcontextprotocol/sdk --external:openai --external:@libsql/client --external:zod --platform=node --target=node24",
|
|
46
|
+
"build:bin": "esbuild bin/create-apikey.ts --bundle --format=cjs --outfile=dist/bin/create-apikey.js --external:jose --platform=node --target=node18 --banner:js='#!/usr/bin/env node'",
|
|
42
47
|
"build:client": "cd src/client && bun run build",
|
|
43
48
|
"build:copy-client": "mkdir -p dist/static && cp src/client/dist/chatter.js src/client/dist/chatter.css dist/static/",
|
|
44
49
|
"test": "bun test",
|
|
@@ -82,28 +87,35 @@
|
|
|
82
87
|
"node": ">=24.0.0"
|
|
83
88
|
},
|
|
84
89
|
"peerDependencies": {
|
|
85
|
-
"@libsql/client": "^0.
|
|
86
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
87
|
-
"hono": "^4.
|
|
88
|
-
"openai": "^
|
|
89
|
-
"zod": "^3.25.
|
|
90
|
+
"@libsql/client": "^0.17.2",
|
|
91
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
92
|
+
"hono": "^4.12.14",
|
|
93
|
+
"openai": "^6.34.0",
|
|
94
|
+
"zod": "^3.25.76"
|
|
90
95
|
},
|
|
91
96
|
"dependencies": {
|
|
92
|
-
"jose": "
|
|
97
|
+
"jose": "6.2.2"
|
|
93
98
|
},
|
|
94
99
|
"devDependencies": {
|
|
95
|
-
"@biomejs/biome": "
|
|
96
|
-
"@
|
|
97
|
-
"@
|
|
98
|
-
"@types/
|
|
99
|
-
"
|
|
100
|
-
"
|
|
101
|
-
"
|
|
102
|
-
"
|
|
103
|
-
"
|
|
100
|
+
"@biomejs/biome": "2.4.12",
|
|
101
|
+
"@libsql/client": "0.17.2",
|
|
102
|
+
"@modelcontextprotocol/sdk": "1.29.0",
|
|
103
|
+
"@types/bun": "1.3.12",
|
|
104
|
+
"@types/node": "25.6.0",
|
|
105
|
+
"esbuild": "0.28.0",
|
|
106
|
+
"hono": "4.12.14",
|
|
107
|
+
"husky": "9.1.7",
|
|
108
|
+
"lint-staged": "16.4.0",
|
|
109
|
+
"openai": "6.34.0",
|
|
110
|
+
"typescript": "6.0.3",
|
|
111
|
+
"zod": "3.25.76"
|
|
104
112
|
},
|
|
105
113
|
"lint-staged": {
|
|
106
|
-
"*.{ts,js,json,md}": [
|
|
107
|
-
|
|
114
|
+
"*.{ts,js,json,md}": [
|
|
115
|
+
"biome check --write --no-errors-on-unmatched"
|
|
116
|
+
],
|
|
117
|
+
"*.ts": [
|
|
118
|
+
"bash -c 'tsc --noEmit --skipLibCheck'"
|
|
119
|
+
]
|
|
108
120
|
}
|
|
109
121
|
}
|
package/bin/create-apikey.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* CLI tool for creating Chatter API keys
|
|
4
|
-
*
|
|
5
|
-
* Usage:
|
|
6
|
-
* npx chatter create-apikey --name "my-key" --expires-in 365d
|
|
7
|
-
* bun run bin/create-apikey.ts --name "test" --expires-in 1y
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { ApiKeyManager } from "../src/auth/apikeys";
|
|
11
|
-
|
|
12
|
-
async function main() {
|
|
13
|
-
// Parse command line arguments
|
|
14
|
-
const args = process.argv.slice(2);
|
|
15
|
-
const options: { name?: string; expiresIn?: string } = {};
|
|
16
|
-
|
|
17
|
-
for (let i = 0; i < args.length; i++) {
|
|
18
|
-
if (args[i] === "--name" && args[i + 1]) {
|
|
19
|
-
options.name = args[i + 1];
|
|
20
|
-
i++;
|
|
21
|
-
} else if (args[i] === "--expires-in" && args[i + 1]) {
|
|
22
|
-
options.expiresIn = args[i + 1];
|
|
23
|
-
i++;
|
|
24
|
-
} else if (args[i] === "--help" || args[i] === "-h") {
|
|
25
|
-
console.log(`
|
|
26
|
-
Chatter API Key Generator
|
|
27
|
-
|
|
28
|
-
Usage:
|
|
29
|
-
npx chatter create-apikey [options]
|
|
30
|
-
|
|
31
|
-
Options:
|
|
32
|
-
--name <name> Name/label for the API key (default: "api-key")
|
|
33
|
-
--expires-in <time> Expiration time (default: "365d")
|
|
34
|
-
Formats: s=seconds, m=minutes, h=hours, d=days, M=months, y=years
|
|
35
|
-
Examples: 30d, 12h, 1y, 6M
|
|
36
|
-
|
|
37
|
-
Environment:
|
|
38
|
-
CHATTER_SECRET Required. Secret key for signing JWT tokens
|
|
39
|
-
|
|
40
|
-
Examples:
|
|
41
|
-
npx chatter create-apikey --name "mobile-app" --expires-in 365d
|
|
42
|
-
npx chatter create-apikey --name "test-key" --expires-in 1h
|
|
43
|
-
`);
|
|
44
|
-
process.exit(0);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Check for CHATTER_SECRET
|
|
49
|
-
const secret = process.env.CHATTER_SECRET;
|
|
50
|
-
if (!secret) {
|
|
51
|
-
console.error("❌ Error: CHATTER_SECRET environment variable is not set");
|
|
52
|
-
console.error("\n Please set it before running this command:");
|
|
53
|
-
console.error(" export CHATTER_SECRET=your-secret-key-here");
|
|
54
|
-
console.error("\n Or prefix the command:");
|
|
55
|
-
console.error(" CHATTER_SECRET=your-secret npx chatter create-apikey\n");
|
|
56
|
-
process.exit(1);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Create API key manager
|
|
60
|
-
const manager = new ApiKeyManager(secret);
|
|
61
|
-
|
|
62
|
-
// Default values
|
|
63
|
-
const keyName = options.name || "api-key";
|
|
64
|
-
const expiresIn = options.expiresIn || "365d";
|
|
65
|
-
|
|
66
|
-
try {
|
|
67
|
-
// Create the API key
|
|
68
|
-
const apiKey = await manager.create({
|
|
69
|
-
name: keyName,
|
|
70
|
-
expiresIn,
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
// Decode to show details (without verification for display)
|
|
74
|
-
const payload = manager.decode(apiKey);
|
|
75
|
-
if (!payload) {
|
|
76
|
-
throw new Error("Failed to decode generated API key");
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const expiresAt = new Date((payload.exp || 0) * 1000);
|
|
80
|
-
const issuedAt = new Date((payload.iat || 0) * 1000);
|
|
81
|
-
|
|
82
|
-
// Output the result
|
|
83
|
-
console.log("\n✅ API Key generated successfully!\n");
|
|
84
|
-
console.log(` Name: ${keyName}`);
|
|
85
|
-
console.log(` ID: ${payload.sub}`);
|
|
86
|
-
console.log(` Issued: ${issuedAt.toISOString()}`);
|
|
87
|
-
console.log(` Expires: ${expiresAt.toISOString()} (${expiresIn})`);
|
|
88
|
-
console.log(`\n API Key:\n ${apiKey}\n`);
|
|
89
|
-
console.log(" Usage:");
|
|
90
|
-
console.log(" curl -X POST https://your-bot.example.com/api/public/chat \\");
|
|
91
|
-
console.log(` -H "x-api-key: ${apiKey.slice(0, 50)}..." \\`);
|
|
92
|
-
console.log(' -H "Content-Type: application/json" \\');
|
|
93
|
-
console.log(' -d \'{"message": "Hello"}\'');
|
|
94
|
-
console.log("");
|
|
95
|
-
} catch (error) {
|
|
96
|
-
console.error("❌ Error creating API key:", error);
|
|
97
|
-
process.exit(1);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
main();
|