@openstaticfish/chattybox-config 0.1.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 +16 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +49 -0
- package/package.json +33 -0
package/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# @openstaticfish/chattybox-config
|
|
2
|
+
|
|
3
|
+
Typed configuration and runtime validation for ChattyBox config-as-code projects.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { defineConfig } from "@openstaticfish/chattybox-config";
|
|
7
|
+
|
|
8
|
+
export default defineConfig({
|
|
9
|
+
schemaVersion: "1",
|
|
10
|
+
assistant: { name: "Support" },
|
|
11
|
+
knowledge: {
|
|
12
|
+
sources: [{ type: "website", url: "https://docs.example.com" }],
|
|
13
|
+
},
|
|
14
|
+
widget: { enabled: true },
|
|
15
|
+
});
|
|
16
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export type ConfigMode = "collaborative" | "config_locked";
|
|
2
|
+
export type DeploymentEnvironment = "development" | "preview" | "production";
|
|
3
|
+
export type WebsiteSource = {
|
|
4
|
+
type: "website";
|
|
5
|
+
url: string;
|
|
6
|
+
include?: Array<string>;
|
|
7
|
+
exclude?: Array<string>;
|
|
8
|
+
maxPages?: number;
|
|
9
|
+
};
|
|
10
|
+
export type ChattyboxConfig = {
|
|
11
|
+
schemaVersion: "1";
|
|
12
|
+
assistant: {
|
|
13
|
+
name: string;
|
|
14
|
+
systemPrompt?: string;
|
|
15
|
+
promptProfile?: "default" | "support" | "sales" | "sarcastic" | "custom";
|
|
16
|
+
fallbackMessage?: string;
|
|
17
|
+
};
|
|
18
|
+
knowledge?: {
|
|
19
|
+
sources: Array<WebsiteSource>;
|
|
20
|
+
};
|
|
21
|
+
runtime?: {
|
|
22
|
+
locale?: string;
|
|
23
|
+
};
|
|
24
|
+
widget?: {
|
|
25
|
+
enabled: boolean;
|
|
26
|
+
position?: "bottom-right" | "bottom-left" | "top-right" | "top-left";
|
|
27
|
+
headerTitle?: string;
|
|
28
|
+
welcomeMessage?: string;
|
|
29
|
+
theme?: {
|
|
30
|
+
primaryColor?: string;
|
|
31
|
+
backgroundColor?: string;
|
|
32
|
+
textColor?: string;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export declare function validateConfig(config: ChattyboxConfig): ChattyboxConfig;
|
|
37
|
+
export declare function defineConfig(config: ChattyboxConfig): ChattyboxConfig;
|
|
38
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var HEX_COLOR = /^#[0-9a-f]{6}$/i;
|
|
3
|
+
function requireNonEmptyString(value, path) {
|
|
4
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
5
|
+
throw new Error(`${path} must be a non-empty string`);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
function validateOptionalColor(value, path) {
|
|
9
|
+
if (value !== undefined && (typeof value !== "string" || !HEX_COLOR.test(value))) {
|
|
10
|
+
throw new Error(`${path} must be a six-digit hex color`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function validateConfig(config) {
|
|
14
|
+
if (!config || typeof config !== "object")
|
|
15
|
+
throw new Error("Config must be an object");
|
|
16
|
+
if (config.schemaVersion !== "1")
|
|
17
|
+
throw new Error('schemaVersion must be "1"');
|
|
18
|
+
requireNonEmptyString(config.assistant?.name, "assistant.name");
|
|
19
|
+
if (config.assistant.systemPrompt !== undefined) {
|
|
20
|
+
requireNonEmptyString(config.assistant.systemPrompt, "assistant.systemPrompt");
|
|
21
|
+
}
|
|
22
|
+
for (const [index, source] of (config.knowledge?.sources ?? []).entries()) {
|
|
23
|
+
if (source.type !== "website") {
|
|
24
|
+
throw new Error(`knowledge.sources[${index}].type is not supported`);
|
|
25
|
+
}
|
|
26
|
+
requireNonEmptyString(source.url, `knowledge.sources[${index}].url`);
|
|
27
|
+
try {
|
|
28
|
+
const url = new URL(source.url);
|
|
29
|
+
if (url.protocol !== "http:" && url.protocol !== "https:")
|
|
30
|
+
throw new Error;
|
|
31
|
+
} catch {
|
|
32
|
+
throw new Error(`knowledge.sources[${index}].url must be an HTTP(S) URL`);
|
|
33
|
+
}
|
|
34
|
+
if (source.maxPages !== undefined && (!Number.isInteger(source.maxPages) || source.maxPages < 1)) {
|
|
35
|
+
throw new Error(`knowledge.sources[${index}].maxPages must be a positive integer`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
validateOptionalColor(config.widget?.theme?.primaryColor, "widget.theme.primaryColor");
|
|
39
|
+
validateOptionalColor(config.widget?.theme?.backgroundColor, "widget.theme.backgroundColor");
|
|
40
|
+
validateOptionalColor(config.widget?.theme?.textColor, "widget.theme.textColor");
|
|
41
|
+
return config;
|
|
42
|
+
}
|
|
43
|
+
function defineConfig(config) {
|
|
44
|
+
return validateConfig(config);
|
|
45
|
+
}
|
|
46
|
+
export {
|
|
47
|
+
validateConfig,
|
|
48
|
+
defineConfig
|
|
49
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openstaticfish/chattybox-config",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"files": ["dist/index.js", "dist/index.d.ts", "README.md"],
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/OpenStaticFish/chattybox.git",
|
|
18
|
+
"directory": "packages/sdk-config"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public",
|
|
22
|
+
"provenance": true
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "bun build src/index.ts --outdir dist --target node --format esm && tsc --declaration --emitDeclarationOnly --noEmit false --outDir dist",
|
|
26
|
+
"prepack": "bun run build",
|
|
27
|
+
"lint": "eslint .",
|
|
28
|
+
"type-check": "tsc --noEmit"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"typescript": "^6.0.3"
|
|
32
|
+
}
|
|
33
|
+
}
|