@build-a-bot/sdk 0.0.0-stage → 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/dist/bots/Bot.d.ts +17 -0
- package/dist/bots/Bot.d.ts.map +1 -0
- package/dist/bots/Bot.js +58 -0
- package/dist/bots/Bot.js.map +1 -0
- package/dist/bots/serialize.d.ts +3 -0
- package/dist/bots/serialize.d.ts.map +1 -0
- package/dist/bots/serialize.js +27 -0
- package/dist/bots/serialize.js.map +1 -0
- package/dist/client/APIError.d.ts +8 -0
- package/dist/client/APIError.d.ts.map +1 -0
- package/dist/client/APIError.js +8 -0
- package/dist/client/APIError.js.map +1 -0
- package/dist/client/BuildABot.d.ts +26 -0
- package/dist/client/BuildABot.d.ts.map +1 -0
- package/dist/client/BuildABot.js +61 -0
- package/dist/client/BuildABot.js.map +1 -0
- package/dist/client/UsesClient.d.ts +5 -0
- package/dist/client/UsesClient.d.ts.map +1 -0
- package/dist/client/UsesClient.js +2 -0
- package/dist/client/UsesClient.js.map +1 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +2 -0
- package/dist/constants.js.map +1 -0
- package/dist/data/bots/DataBot.d.ts +10 -0
- package/dist/data/bots/DataBot.d.ts.map +1 -0
- package/dist/data/bots/DataBot.js +16 -0
- package/dist/data/bots/DataBot.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/user/User.d.ts +10 -0
- package/dist/user/User.d.ts.map +1 -0
- package/dist/user/User.js +9 -0
- package/dist/user/User.js.map +1 -0
- package/package.json +30 -4
- package/README.md +0 -3
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type * as core from '@build-a-bot/core';
|
|
2
|
+
import type { UsesClient } from '../client/UsesClient.js';
|
|
3
|
+
export type BotOptions = Omit<core.BotOptions, 'context'> & UsesClient;
|
|
4
|
+
export declare class Bot {
|
|
5
|
+
#private;
|
|
6
|
+
readonly client: UsesClient['client'];
|
|
7
|
+
name: core.Bot['name'];
|
|
8
|
+
status: core.Bot['status'];
|
|
9
|
+
template: core.Bot['template'];
|
|
10
|
+
code: core.Bot['code'];
|
|
11
|
+
script: core.Bot['script'];
|
|
12
|
+
functions: core.Bot['functions'];
|
|
13
|
+
constructor(options: BotOptions);
|
|
14
|
+
build(options?: core.BotBuildOptions): Promise<void>;
|
|
15
|
+
protected callFunction<T>(name: string, input: unknown): Promise<T>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=Bot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Bot.d.ts","sourceRoot":"","sources":["../../src/bots/Bot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,IAAI,MAAM,mBAAmB,CAAC;AAE/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAG1D,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,SAAS,CAAC,GAAG,UAAU,CAAC;AASvE,qBAAa,GAAG;;IACd,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;IACtC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACvB,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC3B,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC/B,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACvB,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC3B,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;gBAErB,OAAO,EAAE,UAAU;IAUzB,KAAK,CAAC,OAAO,GAAE,IAAI,CAAC,eAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;cAe9C,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;CAwB1E"}
|
package/dist/bots/Bot.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { APIError } from '../client/APIError.js';
|
|
2
|
+
import { serializeBotTemplate } from './serialize.js';
|
|
3
|
+
export class Bot {
|
|
4
|
+
client;
|
|
5
|
+
name;
|
|
6
|
+
status;
|
|
7
|
+
template;
|
|
8
|
+
code;
|
|
9
|
+
script;
|
|
10
|
+
functions;
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.client = options.client;
|
|
13
|
+
this.name = options.name;
|
|
14
|
+
this.status = 'idle';
|
|
15
|
+
this.template = options.template;
|
|
16
|
+
this.code = options.code;
|
|
17
|
+
this.script = undefined;
|
|
18
|
+
this.functions = {};
|
|
19
|
+
}
|
|
20
|
+
async build(options = {}) {
|
|
21
|
+
await this.#upsert();
|
|
22
|
+
const route = await this.#route();
|
|
23
|
+
let current = await this.client.call('POST', await this.#route('/build'), options);
|
|
24
|
+
do {
|
|
25
|
+
this.status = current.status;
|
|
26
|
+
this.code = current.code;
|
|
27
|
+
if (current.status !== 'building') {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
await new Promise((resolve) => setTimeout(resolve, 1_000));
|
|
31
|
+
current = await this.client.call('GET', route);
|
|
32
|
+
} while (true);
|
|
33
|
+
}
|
|
34
|
+
async callFunction(name, input) {
|
|
35
|
+
return this.client.call('POST', await this.#route(`/${encodeURIComponent(name)}`), input);
|
|
36
|
+
}
|
|
37
|
+
async #upsert() {
|
|
38
|
+
const route = await this.#route();
|
|
39
|
+
try {
|
|
40
|
+
return await this.client.call('GET', route);
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
if (!(e instanceof APIError) || e.status !== 404) {
|
|
44
|
+
throw e;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return this.client.call('POST', '/bots', {
|
|
48
|
+
name: this.name,
|
|
49
|
+
template: serializeBotTemplate(this.template),
|
|
50
|
+
code: this.code,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
async #route(path = '') {
|
|
54
|
+
const user = await this.client.user();
|
|
55
|
+
return `/bots/${encodeURIComponent(user.username)}/${encodeURIComponent(this.name)}${path}`;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=Bot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Bot.js","sourceRoot":"","sources":["../../src/bots/Bot.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAWtD,MAAM,OAAO,GAAG;IACL,MAAM,CAAuB;IACtC,IAAI,CAAmB;IACvB,MAAM,CAAqB;IAC3B,QAAQ,CAAuB;IAC/B,IAAI,CAAmB;IACvB,MAAM,CAAqB;IAC3B,SAAS,CAAwB;IAEjC,YAAY,OAAmB;QAC7B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;QACxB,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,UAAgC,EAAE;QAC5C,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;QACrB,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;QAClC,IAAI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AO,EAAE;YACpD,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,QAAQ,EAAE,oBAAoB,CAAC,IAAI,CAAC,QAAQ,CAAC;YAC7C,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,IAAI,GAAG,EAAE;QACpB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QACtC,OAAO,SAAS,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC;IAC9F,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../src/bots/serialize.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,eAAO,MAAM,oBAAoB,GAAI,UAAU,WAAW,KAAG,MAwB3D,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const serializeBotTemplate = (template) => ({
|
|
3
|
+
classSpecs: template.classSpecs.map((classSpec) => {
|
|
4
|
+
const val = {
|
|
5
|
+
description: classSpec.description,
|
|
6
|
+
prompt: classSpec.prompt,
|
|
7
|
+
functionSpecs: classSpec.functionSpecs.map((spec) => ({
|
|
8
|
+
name: spec.name,
|
|
9
|
+
description: spec.description,
|
|
10
|
+
prompt: spec.prompt,
|
|
11
|
+
inputSchema: z.toJSONSchema(spec.inputSchema, { io: 'input' }),
|
|
12
|
+
outputSchema: z.toJSONSchema(spec.outputSchema),
|
|
13
|
+
sampleInputs: spec.sampleInputs,
|
|
14
|
+
})),
|
|
15
|
+
};
|
|
16
|
+
if (classSpec.numImplementations === 'many') {
|
|
17
|
+
return { ...val, numImplementations: 'many', nameTemplate: classSpec.nameTemplate };
|
|
18
|
+
}
|
|
19
|
+
return { ...val, numImplementations: 'single', name: classSpec.name };
|
|
20
|
+
}),
|
|
21
|
+
vmContext: {
|
|
22
|
+
requiredGlobals: template.requiredGlobals,
|
|
23
|
+
requiredModules: template.requiredModules,
|
|
24
|
+
requiredTools: template.requiredTools,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
//# sourceMappingURL=serialize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialize.js","sourceRoot":"","sources":["../../src/bots/serialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,QAAqB,EAAU,EAAE,CAAC,CAAC;IACtE,UAAU,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE;QAChD,MAAM,GAAG,GAAG;YACV,WAAW,EAAE,SAAS,CAAC,WAAW;YAClC,MAAM,EAAE,SAAS,CAAC,MAAM;YACxB,aAAa,EAAE,SAAS,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;gBACpD,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,WAAW,EAAE,IAAI,CAAC,WAAW;gBAC7B,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,WAAW,EAAE,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC;gBAC9D,YAAY,EAAE,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC;gBAC/C,YAAY,EAAE,IAAI,CAAC,YAAY;aAChC,CAAC,CAAC;SACJ,CAAC;QACF,IAAI,SAAS,CAAC,kBAAkB,KAAK,MAAM,EAAE,CAAC;YAC5C,OAAO,EAAE,GAAG,GAAG,EAAE,kBAAkB,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,CAAC,YAAY,EAAE,CAAC;QACtF,CAAC;QACD,OAAO,EAAE,GAAG,GAAG,EAAE,kBAAkB,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,CAAC;IACxE,CAAC,CAAC;IACF,SAAS,EAAE;QACT,eAAe,EAAE,QAAQ,CAAC,eAAe;QACzC,eAAe,EAAE,QAAQ,CAAC,eAAe;QACzC,aAAa,EAAE,QAAQ,CAAC,aAAa;KACtC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"APIError.d.ts","sourceRoot":"","sources":["../../src/client/APIError.ts"],"names":[],"mappings":"AAAA,qBAAa,QAAS,SAAQ,KAAK;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE;CAIzD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"APIError.js","sourceRoot":"","sources":["../../src/client/APIError.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,QAAS,SAAQ,KAAK;IACxB,MAAM,CAAS;IAExB,YAAY,OAA4C;QACtD,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC/B,CAAC;CACF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { DataBot, type DataBotOptions } from '../data/bots/DataBot.js';
|
|
2
|
+
import { User } from '../user/User.js';
|
|
3
|
+
import type { UsesClient } from './UsesClient.js';
|
|
4
|
+
export type BuildABotOptions = {
|
|
5
|
+
apiKey: string;
|
|
6
|
+
host?: string;
|
|
7
|
+
};
|
|
8
|
+
type DataBotsOptions = UsesClient;
|
|
9
|
+
declare class DataBots {
|
|
10
|
+
readonly client: UsesClient['client'];
|
|
11
|
+
constructor(options: DataBotsOptions);
|
|
12
|
+
build(options: Omit<DataBotOptions, 'client'>): Promise<DataBot>;
|
|
13
|
+
}
|
|
14
|
+
export declare class BuildABot {
|
|
15
|
+
#private;
|
|
16
|
+
readonly apiKey: string;
|
|
17
|
+
readonly host: string;
|
|
18
|
+
readonly data: {
|
|
19
|
+
bots: DataBots;
|
|
20
|
+
};
|
|
21
|
+
constructor(options: BuildABotOptions);
|
|
22
|
+
call<T>(method: string, route: string, params?: unknown): Promise<T>;
|
|
23
|
+
user(): Promise<User>;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=BuildABot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BuildABot.d.ts","sourceRoot":"","sources":["../../src/client/BuildABot.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEvC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,KAAK,eAAe,GAAG,UAAU,CAAC;AAElC,cAAM,QAAQ;IACZ,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;gBAE1B,OAAO,EAAE,eAAe;IAI9B,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;CAKvE;AAED,qBAAa,SAAS;;IACpB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,QAAQ,CAAA;KAAE,CAAC;gBAGtB,OAAO,EAAE,gBAAgB;IAM/B,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;IA4BpE,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAS5B"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { defaultHost } from '../constants.js';
|
|
2
|
+
import { DataBot } from '../data/bots/DataBot.js';
|
|
3
|
+
import { User } from '../user/User.js';
|
|
4
|
+
import { APIError } from './APIError.js';
|
|
5
|
+
class DataBots {
|
|
6
|
+
client;
|
|
7
|
+
constructor(options) {
|
|
8
|
+
this.client = options.client;
|
|
9
|
+
}
|
|
10
|
+
async build(options) {
|
|
11
|
+
const bot = new DataBot({ ...options, client: this.client });
|
|
12
|
+
await bot.build();
|
|
13
|
+
return bot;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export class BuildABot {
|
|
17
|
+
apiKey;
|
|
18
|
+
host;
|
|
19
|
+
data;
|
|
20
|
+
#user;
|
|
21
|
+
constructor(options) {
|
|
22
|
+
this.apiKey = options.apiKey;
|
|
23
|
+
this.host = options.host ?? defaultHost;
|
|
24
|
+
this.data = { bots: new DataBots({ client: this }) };
|
|
25
|
+
}
|
|
26
|
+
async call(method, route, params) {
|
|
27
|
+
if (!route.startsWith('/') || route.startsWith('//') || route.includes('..')) {
|
|
28
|
+
throw new Error('Expected a path relative to the API.');
|
|
29
|
+
}
|
|
30
|
+
const url = new URL(route, this.host);
|
|
31
|
+
const headers = {
|
|
32
|
+
Accept: 'application/json',
|
|
33
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
34
|
+
};
|
|
35
|
+
if (params !== undefined) {
|
|
36
|
+
headers['Content-Type'] = 'application/json';
|
|
37
|
+
}
|
|
38
|
+
const resp = await fetch(url, {
|
|
39
|
+
method,
|
|
40
|
+
headers,
|
|
41
|
+
body: params === undefined ? undefined : JSON.stringify(params),
|
|
42
|
+
});
|
|
43
|
+
if (!resp.ok) {
|
|
44
|
+
const body = (await resp.json().catch(() => null));
|
|
45
|
+
throw new APIError({
|
|
46
|
+
message: typeof body?.error === 'string' ? body.error : `API request failed (${resp.status}).`,
|
|
47
|
+
status: resp.status,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return resp.json();
|
|
51
|
+
}
|
|
52
|
+
async user() {
|
|
53
|
+
this.#user ??= this.#loadUser();
|
|
54
|
+
return this.#user;
|
|
55
|
+
}
|
|
56
|
+
async #loadUser() {
|
|
57
|
+
const val = await this.call('GET', '/users/me');
|
|
58
|
+
return new User({ client: this, username: val.username });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=BuildABot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BuildABot.js","sourceRoot":"","sources":["../../src/client/BuildABot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAuB,MAAM,yBAAyB,CAAC;AACvE,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAUzC,MAAM,QAAQ;IACH,MAAM,CAAuB;IAEtC,YAAY,OAAwB;QAClC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,OAAuC;QACjD,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;QAC7D,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC;QAClB,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AAED,MAAM,OAAO,SAAS;IACX,MAAM,CAAS;IACf,IAAI,CAAS;IACb,IAAI,CAAqB;IAClC,KAAK,CAAiB;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AM,IAAI,QAAQ,CAAC;gBACjB,OAAO,EACL,OAAO,IAAI,EAAE,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,uBAAuB,IAAI,CAAC,MAAM,IAAI;gBACvF,MAAM,EAAE,IAAI,CAAC,MAAM;aACpB,CAAC,CAAC;QACL,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,EAAgB,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,IAAI;QACR,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,SAAS,EAAE,CAAC;QAChC,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,KAAK,CAAC,SAAS;QACb,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,IAAI,CAAuB,KAAK,EAAE,WAAW,CAAC,CAAC;QACtE,OAAO,IAAI,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC5D,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UsesClient.d.ts","sourceRoot":"","sources":["../../src/client/UsesClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,MAAM,MAAM,UAAU,GAAG;IACvB,MAAM,EAAE,SAAS,CAAC;CACnB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UsesClient.js","sourceRoot":"","sources":["../../src/client/UsesClient.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,gCAAgC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as core from '@build-a-bot/core';
|
|
2
|
+
import type { UsesClient } from '../../client/UsesClient.js';
|
|
3
|
+
import { Bot } from '../../bots/Bot.js';
|
|
4
|
+
export type DataBotOptions = Omit<core.DataBotOptions, 'context'> & UsesClient;
|
|
5
|
+
export declare class DataBot extends Bot {
|
|
6
|
+
constructor(options: DataBotOptions);
|
|
7
|
+
extract(input: Parameters<core.DataBot['extract']>[0]): ReturnType<core.DataBot['extract']>;
|
|
8
|
+
identity(input: Parameters<core.DataBot['identity']>[0]): ReturnType<core.DataBot['identity']>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=DataBot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DataBot.d.ts","sourceRoot":"","sources":["../../../src/data/bots/DataBot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,mBAAmB,CAAC;AAC1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAExC,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC,GAAG,UAAU,CAAC;AAE/E,qBAAa,OAAQ,SAAQ,GAAG;gBAClB,OAAO,EAAE,cAAc;IAMnC,OAAO,CAAC,KAAK,EAAE,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAI3F,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;CAG/F"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as core from '@build-a-bot/core';
|
|
2
|
+
import { Bot } from '../../bots/Bot.js';
|
|
3
|
+
export class DataBot extends Bot {
|
|
4
|
+
constructor(options) {
|
|
5
|
+
const { client, ...dataOptions } = options;
|
|
6
|
+
const bot = new core.DataBot(dataOptions);
|
|
7
|
+
super({ client, name: bot.name, template: bot.template });
|
|
8
|
+
}
|
|
9
|
+
extract(input) {
|
|
10
|
+
return this.callFunction('extract', input);
|
|
11
|
+
}
|
|
12
|
+
identity(input) {
|
|
13
|
+
return this.callFunction('identity', input);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=DataBot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DataBot.js","sourceRoot":"","sources":["../../../src/data/bots/DataBot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,mBAAmB,CAAC;AAE1C,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAIxC,MAAM,OAAO,OAAQ,SAAQ,GAAG;IAC9B,YAAY,OAAuB;QACjC,MAAM,EAAE,MAAM,EAAE,GAAG,WAAW,EAAE,GAAG,OAAO,CAAC;QAC3C,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAC1C,KAAK,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC5D,CAAC;IAED,OAAO,CAAC,KAA6C;QACnD,OAAO,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAC7C,CAAC;IAED,QAAQ,CAAC,KAA8C;QACrD,OAAO,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IAC9C,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { BuildABot, type BuildABotOptions } from './client/BuildABot.js';
|
|
2
|
+
export { APIError } from './client/APIError.js';
|
|
3
|
+
export type { UsesClient } from './client/UsesClient.js';
|
|
4
|
+
export { DataBot, type DataBotOptions } from './data/bots/DataBot.js';
|
|
5
|
+
export { User, type UserOptions } from './user/User.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,YAAY,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,IAAI,EAAE,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAyB,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,OAAO,EAAE,OAAO,EAAuB,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,IAAI,EAAoB,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { UsesClient } from '../client/UsesClient.js';
|
|
2
|
+
export type UserOptions = UsesClient & {
|
|
3
|
+
username: string;
|
|
4
|
+
};
|
|
5
|
+
export declare class User {
|
|
6
|
+
readonly client: UsesClient['client'];
|
|
7
|
+
readonly username: string;
|
|
8
|
+
constructor(options: UserOptions);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=User.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"User.d.ts","sourceRoot":"","sources":["../../src/user/User.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE1D,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG;IACrC,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,qBAAa,IAAI;IACf,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;IACtC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;gBAEd,OAAO,EAAE,WAAW;CAIjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"User.js","sourceRoot":"","sources":["../../src/user/User.ts"],"names":[],"mappings":"AAMA,MAAM,OAAO,IAAI;IACN,MAAM,CAAuB;IAC7B,QAAQ,CAAS;IAE1B,YAAY,OAAoB;QAC9B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IACnC,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@build-a-bot/sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Build-A-Bot SDK.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist/"
|
|
17
|
+
],
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=20.12"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc",
|
|
26
|
+
"dev": "tsc --watch"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@build-a-bot/core": "^0.1.0",
|
|
30
|
+
"zod": "^4.4.3"
|
|
31
|
+
}
|
|
32
|
+
}
|
package/README.md
DELETED