@dotbots-boutique/server-sdk 0.4.0 → 0.4.2
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/client.js +5 -22
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -38,29 +38,9 @@ class DotBotsBackend {
|
|
|
38
38
|
}));
|
|
39
39
|
}
|
|
40
40
|
async ai(feature, request, onDelta) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
this.aiStream(feature, request, onDelta, resolve).catch(reject);
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
const response = await fetch(`${this.getProxyUrl()}/ai/call`, {
|
|
47
|
-
method: 'POST',
|
|
48
|
-
headers: this.baseHeaders(),
|
|
49
|
-
body: JSON.stringify({
|
|
50
|
-
feature,
|
|
51
|
-
messages: request.messages,
|
|
52
|
-
tools: request.tools,
|
|
53
|
-
stream: false,
|
|
54
|
-
maxTokens: request.maxTokens,
|
|
55
|
-
paidBy: request.paidBy,
|
|
56
|
-
orgId: request.orgId,
|
|
57
|
-
}),
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
this.aiStream(feature, request, onDelta ?? (() => { }), resolve).catch(reject);
|
|
58
43
|
});
|
|
59
|
-
if (!response.ok) {
|
|
60
|
-
const body = (await response.json().catch(() => ({})));
|
|
61
|
-
throw new errors_1.DotBotsBackendError(body.error ?? 'AI_CALL_FAILED', response.status);
|
|
62
|
-
}
|
|
63
|
-
return (await response.json());
|
|
64
44
|
}
|
|
65
45
|
async aiStream(feature, request, onDelta, onDone) {
|
|
66
46
|
const response = await fetch(`${this.getProxyUrl()}/ai/call`, {
|
|
@@ -98,6 +78,9 @@ class DotBotsBackend {
|
|
|
98
78
|
onDelta(data.delta);
|
|
99
79
|
else if (data.type === 'done')
|
|
100
80
|
onDone?.(data);
|
|
81
|
+
else if (data.type === 'error') {
|
|
82
|
+
throw new errors_1.DotBotsBackendError(data.error ?? 'AI_CALL_FAILED', 500);
|
|
83
|
+
}
|
|
101
84
|
}
|
|
102
85
|
}
|
|
103
86
|
}
|
package/package.json
CHANGED