@horribleprogram/sdk 0.1.1

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 ADDED
@@ -0,0 +1,97 @@
1
+ # @botcierge/sdk
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@botcierge/sdk.svg)](https://www.npmjs.com/package/@botcierge/sdk)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ Official JavaScript/TypeScript SDK for the **Botcierge Intent Classification API**.
7
+
8
+ ## Features
9
+
10
+ - **TypeScript Native**: Full type definitions for all API responses.
11
+ - **Lightweight**: Zero dependencies (uses native `fetch`).
12
+ - **Flexible**: Easy to use for both simple scripts and complex applications.
13
+ - **Cross-platform**: Works in Node.js, Browsers, and Edge environments.
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @botcierge/sdk
19
+ ```
20
+
21
+ ## Quick Start
22
+
23
+ ```typescript
24
+ import { query_intent } from '@botcierge/sdk';
25
+
26
+ try {
27
+ const result = await query_intent("I'd like to share some food");
28
+
29
+ console.log(`Domain: ${result.domain}`); // foodshare
30
+ console.log(`Intent: ${result.intent}`); // share_food
31
+ console.log(`Confidence: ${result.confidence}`); // high
32
+ } catch (error) {
33
+ console.error("Classification failed:", error.message);
34
+ }
35
+ ```
36
+
37
+ ## API Reference
38
+
39
+ ### `query_intent(utterance: string): Promise<IntentResult>`
40
+
41
+ A helper function for quick classification using the default configuration (connecting to `http://localhost:8000`).
42
+
43
+ ### `class Botcierge`
44
+
45
+ The main class for interacting with the Botcierge API.
46
+
47
+ #### `constructor(config?: BotciergeConfig)`
48
+
49
+ - `config.baseUrl`: The base URL of your Botcierge API (default: `http://localhost:8000`).
50
+
51
+ #### `query_intent(utterance: string): Promise<IntentResult>`
52
+
53
+ Classifies a string into a specific domain and intent.
54
+
55
+ ### Types
56
+
57
+ #### `IntentResult`
58
+ ```typescript
59
+ interface IntentResult {
60
+ domain: string; // The high-level category (e.g., 'moneyshare')
61
+ intent: string; // The specific action (e.g., 'request_loan')
62
+ confidence: "high" | "medium" | "low";
63
+ scores: Record<string, number>; // Raw similarity scores for all intents
64
+ }
65
+ ```
66
+
67
+ ## Error Handling
68
+
69
+ The SDK throws standard `Error` objects if the network request fails or if the API returns a non-2xx status code.
70
+
71
+ ```typescript
72
+ import { Botcierge } from '@botcierge/sdk';
73
+
74
+ const client = new Botcierge({ baseUrl: 'https://invalid-api.com' });
75
+
76
+ try {
77
+ await client.query_intent("hello");
78
+ } catch (e) {
79
+ console.log(e.message); // "Botcierge API error: ..."
80
+ }
81
+ ```
82
+
83
+ ## Development
84
+
85
+ ### Running Tests
86
+ ```bash
87
+ npm test
88
+ ```
89
+
90
+ ### Building
91
+ ```bash
92
+ npm run build
93
+ ```
94
+
95
+ ## License
96
+
97
+ MIT © [horribleprogram](https://npmjs.com/~horribleprogram)
@@ -0,0 +1,30 @@
1
+ // src/index.ts
2
+ var Botcierge = class {
3
+ baseUrl;
4
+ constructor(config = {}) {
5
+ this.baseUrl = config.baseUrl || "http://localhost:8000";
6
+ }
7
+ async query_intent(utterance) {
8
+ const response = await fetch(`${this.baseUrl}/classify`, {
9
+ method: "POST",
10
+ headers: {
11
+ "Content-Type": "application/json"
12
+ },
13
+ body: JSON.stringify({ utterance })
14
+ });
15
+ if (!response.ok) {
16
+ const error = await response.json().catch(() => ({ detail: "Unknown error" }));
17
+ throw new Error(`Botcierge API error: ${error.detail || response.statusText}`);
18
+ }
19
+ return await response.json();
20
+ }
21
+ };
22
+ var defaultClient = new Botcierge();
23
+ async function query_intent(utterance) {
24
+ return defaultClient.query_intent(utterance);
25
+ }
26
+
27
+ export {
28
+ Botcierge,
29
+ query_intent
30
+ };
package/dist/index.cjs ADDED
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ Botcierge: () => Botcierge,
24
+ query_intent: () => query_intent
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+ var Botcierge = class {
28
+ baseUrl;
29
+ constructor(config = {}) {
30
+ this.baseUrl = config.baseUrl || "http://localhost:8000";
31
+ }
32
+ async query_intent(utterance) {
33
+ const response = await fetch(`${this.baseUrl}/classify`, {
34
+ method: "POST",
35
+ headers: {
36
+ "Content-Type": "application/json"
37
+ },
38
+ body: JSON.stringify({ utterance })
39
+ });
40
+ if (!response.ok) {
41
+ const error = await response.json().catch(() => ({ detail: "Unknown error" }));
42
+ throw new Error(`Botcierge API error: ${error.detail || response.statusText}`);
43
+ }
44
+ return await response.json();
45
+ }
46
+ };
47
+ var defaultClient = new Botcierge();
48
+ async function query_intent(utterance) {
49
+ return defaultClient.query_intent(utterance);
50
+ }
51
+ // Annotate the CommonJS export names for ESM import in node:
52
+ 0 && (module.exports = {
53
+ Botcierge,
54
+ query_intent
55
+ });
@@ -0,0 +1,21 @@
1
+ interface IntentResult {
2
+ domain: string;
3
+ intent: string;
4
+ confidence: "high" | "medium" | "low";
5
+ scores?: Record<string, number>;
6
+ }
7
+ interface BotciergeConfig {
8
+ baseUrl?: string;
9
+ }
10
+ declare class Botcierge {
11
+ private baseUrl;
12
+ constructor(config?: BotciergeConfig);
13
+ query_intent(utterance: string): Promise<IntentResult>;
14
+ }
15
+ /**
16
+ * Classifies an utterance into an intent.
17
+ * By default, connects to http://localhost:8000
18
+ */
19
+ declare function query_intent(utterance: string): Promise<IntentResult>;
20
+
21
+ export { Botcierge, type BotciergeConfig, type IntentResult, query_intent };
@@ -0,0 +1,21 @@
1
+ interface IntentResult {
2
+ domain: string;
3
+ intent: string;
4
+ confidence: "high" | "medium" | "low";
5
+ scores?: Record<string, number>;
6
+ }
7
+ interface BotciergeConfig {
8
+ baseUrl?: string;
9
+ }
10
+ declare class Botcierge {
11
+ private baseUrl;
12
+ constructor(config?: BotciergeConfig);
13
+ query_intent(utterance: string): Promise<IntentResult>;
14
+ }
15
+ /**
16
+ * Classifies an utterance into an intent.
17
+ * By default, connects to http://localhost:8000
18
+ */
19
+ declare function query_intent(utterance: string): Promise<IntentResult>;
20
+
21
+ export { Botcierge, type BotciergeConfig, type IntentResult, query_intent };
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ import {
2
+ Botcierge,
3
+ query_intent
4
+ } from "./chunk-AOE6JLKC.js";
5
+ export {
6
+ Botcierge,
7
+ query_intent
8
+ };
package/dist/main.cjs ADDED
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from))
11
+ if (!__hasOwnProp.call(to, key) && key !== except)
12
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ }
14
+ return to;
15
+ };
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ // If the importer is in node compatibility mode or this is not an ESM
18
+ // file that has been converted to a CommonJS file using a Babel-
19
+ // compatible transform (i.e. "__esModule" has not been set), then set
20
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+
25
+ // src/main.ts
26
+ var readline = __toESM(require("readline"), 1);
27
+
28
+ // src/index.ts
29
+ var Botcierge = class {
30
+ baseUrl;
31
+ constructor(config = {}) {
32
+ this.baseUrl = config.baseUrl || "http://localhost:8000";
33
+ }
34
+ async query_intent(utterance) {
35
+ const response = await fetch(`${this.baseUrl}/classify`, {
36
+ method: "POST",
37
+ headers: {
38
+ "Content-Type": "application/json"
39
+ },
40
+ body: JSON.stringify({ utterance })
41
+ });
42
+ if (!response.ok) {
43
+ const error = await response.json().catch(() => ({ detail: "Unknown error" }));
44
+ throw new Error(`Botcierge API error: ${error.detail || response.statusText}`);
45
+ }
46
+ return await response.json();
47
+ }
48
+ };
49
+ var defaultClient = new Botcierge();
50
+ async function query_intent(utterance) {
51
+ return defaultClient.query_intent(utterance);
52
+ }
53
+
54
+ // src/main.ts
55
+ var queries = [
56
+ "I'm hungry",
57
+ "I need some blood",
58
+ "I want to add milk to my shopping list"
59
+ ];
60
+ async function runBatch() {
61
+ for (const query of queries) {
62
+ const result = await query_intent(query);
63
+ console.log(result.intent);
64
+ }
65
+ }
66
+ async function runInteractive() {
67
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
68
+ const prompt = () => rl.question("> ", async (user_query) => {
69
+ if (!user_query) {
70
+ rl.close();
71
+ return;
72
+ }
73
+ const result = await query_intent(user_query);
74
+ console.log(result.intent);
75
+ prompt();
76
+ });
77
+ prompt();
78
+ }
79
+ var mode = process.argv[2];
80
+ if (mode === "interactive") {
81
+ runInteractive();
82
+ } else {
83
+ runBatch();
84
+ }
@@ -0,0 +1,2 @@
1
+
2
+ export { }
package/dist/main.d.ts ADDED
@@ -0,0 +1,2 @@
1
+
2
+ export { }
package/dist/main.js ADDED
@@ -0,0 +1,36 @@
1
+ import {
2
+ query_intent
3
+ } from "./chunk-AOE6JLKC.js";
4
+
5
+ // src/main.ts
6
+ import * as readline from "readline";
7
+ var queries = [
8
+ "I'm hungry",
9
+ "I need some blood",
10
+ "I want to add milk to my shopping list"
11
+ ];
12
+ async function runBatch() {
13
+ for (const query of queries) {
14
+ const result = await query_intent(query);
15
+ console.log(result.intent);
16
+ }
17
+ }
18
+ async function runInteractive() {
19
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
20
+ const prompt = () => rl.question("> ", async (user_query) => {
21
+ if (!user_query) {
22
+ rl.close();
23
+ return;
24
+ }
25
+ const result = await query_intent(user_query);
26
+ console.log(result.intent);
27
+ prompt();
28
+ });
29
+ prompt();
30
+ }
31
+ var mode = process.argv[2];
32
+ if (mode === "interactive") {
33
+ runInteractive();
34
+ } else {
35
+ runBatch();
36
+ }
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@horribleprogram/sdk",
3
+ "version": "0.1.1",
4
+ "description": "SDK for Botcierge Intent Classification",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.mjs",
8
+ "types": "./dist/index.d.ts",
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "scripts": {
13
+ "build": "tsup src/index.ts src/main.ts --format cjs,esm --dts --clean",
14
+ "dev": "tsup src/index.ts --format cjs,esm --watch --dts",
15
+ "test": "vitest run",
16
+ "lint": "tsc"
17
+ },
18
+ "keywords": [
19
+ "botcierge",
20
+ "intent",
21
+ "classifier",
22
+ "sdk"
23
+ ],
24
+ "author": "horribleprogram",
25
+ "license": "MIT",
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "devDependencies": {
30
+ "@types/node": "^25.8.0",
31
+ "tsup": "^8.0.0",
32
+ "typescript": "^5.0.0",
33
+ "vitest": "^4.1.6"
34
+ },
35
+ "dependencies": {}
36
+ }