@valuya/bot-channel-bootstrap-core 0.2.0-beta.1 → 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/dist/index.d.ts +18 -0
- package/dist/index.js +37 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,10 +4,12 @@ export type ChannelMode = {
|
|
|
4
4
|
kind: "agent";
|
|
5
5
|
soulId: string;
|
|
6
6
|
};
|
|
7
|
+
export type SoulProvider = "openai" | "webhook";
|
|
7
8
|
export declare function normalizeChannelMode(args: {
|
|
8
9
|
value?: string;
|
|
9
10
|
soulId: string;
|
|
10
11
|
}): ChannelMode;
|
|
12
|
+
export declare function normalizeSoulProvider(value?: string): SoulProvider;
|
|
11
13
|
export declare function createConfiguredSoul<TSoul extends {
|
|
12
14
|
locale?: string;
|
|
13
15
|
systemPrompt: string;
|
|
@@ -28,3 +30,19 @@ export declare function createOptionalOpenAISoulRuntime<TRuntime>(args: {
|
|
|
28
30
|
runCompletion: unknown;
|
|
29
31
|
}) => TRuntime;
|
|
30
32
|
}): TRuntime | undefined;
|
|
33
|
+
export declare function createOptionalWebhookSoulRuntime<TRuntime>(args: {
|
|
34
|
+
mode: ChannelMode;
|
|
35
|
+
provider?: string;
|
|
36
|
+
url?: string;
|
|
37
|
+
authToken?: string;
|
|
38
|
+
timeoutMs?: number;
|
|
39
|
+
extraHeaders?: Record<string, string>;
|
|
40
|
+
createRuntime: (args: {
|
|
41
|
+
url: string;
|
|
42
|
+
provider?: string;
|
|
43
|
+
authToken?: string;
|
|
44
|
+
timeoutMs?: number;
|
|
45
|
+
extraHeaders?: Record<string, string>;
|
|
46
|
+
}) => TRuntime;
|
|
47
|
+
}): TRuntime | undefined;
|
|
48
|
+
export declare function parseJsonHeaders(value?: string): Record<string, string> | undefined;
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,13 @@ export function normalizeChannelMode(args) {
|
|
|
3
3
|
? { kind: "agent", soulId: args.soulId }
|
|
4
4
|
: { kind: "human" };
|
|
5
5
|
}
|
|
6
|
+
export function normalizeSoulProvider(value) {
|
|
7
|
+
const normalized = String(value || "openai").trim().toLowerCase();
|
|
8
|
+
if (normalized === "webhook" || normalized === "api" || normalized === "n8n" || normalized === "langchain") {
|
|
9
|
+
return "webhook";
|
|
10
|
+
}
|
|
11
|
+
return "openai";
|
|
12
|
+
}
|
|
6
13
|
export function createConfiguredSoul(args) {
|
|
7
14
|
const raw = String(args.responseSchemaJson || "").trim();
|
|
8
15
|
if (!raw)
|
|
@@ -34,3 +41,33 @@ export function createOptionalOpenAISoulRuntime(args) {
|
|
|
34
41
|
}),
|
|
35
42
|
});
|
|
36
43
|
}
|
|
44
|
+
export function createOptionalWebhookSoulRuntime(args) {
|
|
45
|
+
if (args.mode.kind !== "agent")
|
|
46
|
+
return undefined;
|
|
47
|
+
const url = String(args.url || "").trim();
|
|
48
|
+
if (!url)
|
|
49
|
+
return undefined;
|
|
50
|
+
return args.createRuntime({
|
|
51
|
+
url,
|
|
52
|
+
provider: normalizeSoulProvider(args.provider),
|
|
53
|
+
authToken: String(args.authToken || "").trim() || undefined,
|
|
54
|
+
timeoutMs: args.timeoutMs,
|
|
55
|
+
extraHeaders: args.extraHeaders,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
export function parseJsonHeaders(value) {
|
|
59
|
+
const raw = String(value || "").trim();
|
|
60
|
+
if (!raw)
|
|
61
|
+
return undefined;
|
|
62
|
+
try {
|
|
63
|
+
const parsed = JSON.parse(raw);
|
|
64
|
+
const headers = Object.fromEntries(Object.entries(parsed)
|
|
65
|
+
.filter((entry) => (typeof entry[0] === "string"
|
|
66
|
+
&& ["string", "number", "boolean"].includes(typeof entry[1])))
|
|
67
|
+
.map(([key, headerValue]) => [key, String(headerValue)]));
|
|
68
|
+
return Object.keys(headers).length ? headers : undefined;
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
}
|