@circleback/cli 0.3.1 → 0.3.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/jsonRpc.js +21 -11
- package/dist/types.js +5 -1
- package/package.json +1 -1
package/dist/client/jsonRpc.js
CHANGED
|
@@ -46,6 +46,22 @@ const sendRequest = async (method, params, accessToken) => fetch(`${constants_1.
|
|
|
46
46
|
params,
|
|
47
47
|
}),
|
|
48
48
|
});
|
|
49
|
+
const getJsonRpcResultText = (body) => {
|
|
50
|
+
if (body.error) {
|
|
51
|
+
throw new Error(body.error.message);
|
|
52
|
+
}
|
|
53
|
+
if (body.result === undefined)
|
|
54
|
+
return;
|
|
55
|
+
const result = types_1.jsonRpcResultSchema.safeParse(body.result);
|
|
56
|
+
if (!result.success) {
|
|
57
|
+
throw new Error('Invalid JSON-RPC response.');
|
|
58
|
+
}
|
|
59
|
+
const textContent = result.data.content.find((item) => item.type === 'text')?.text;
|
|
60
|
+
if (result.data.isError === true) {
|
|
61
|
+
throw new Error(textContent || 'Tool returned an error.');
|
|
62
|
+
}
|
|
63
|
+
return textContent;
|
|
64
|
+
};
|
|
49
65
|
const parseResponse = async (response) => {
|
|
50
66
|
const contentType = response.headers.get('content-type') ?? '';
|
|
51
67
|
if (contentType.includes('text/event-stream')) {
|
|
@@ -55,14 +71,11 @@ const parseResponse = async (response) => {
|
|
|
55
71
|
if (!(0, types_1.isJsonRpcResponse)(body)) {
|
|
56
72
|
throw new Error('Invalid JSON-RPC response.');
|
|
57
73
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
const textContent = body.result?.content?.find((item) => item.type === 'text');
|
|
62
|
-
if (!textContent) {
|
|
74
|
+
const text = getJsonRpcResultText(body);
|
|
75
|
+
if (text === undefined) {
|
|
63
76
|
throw new Error('No text content in response.');
|
|
64
77
|
}
|
|
65
|
-
return
|
|
78
|
+
return text;
|
|
66
79
|
};
|
|
67
80
|
const parseSSEResponse = async (response) => {
|
|
68
81
|
const text = await response.text();
|
|
@@ -75,11 +88,8 @@ const parseSSEResponse = async (response) => {
|
|
|
75
88
|
const parsed = JSON.parse(data);
|
|
76
89
|
if (!(0, types_1.isJsonRpcResponse)(parsed))
|
|
77
90
|
return [];
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
const textContent = parsed.result?.content?.find((item) => item.type === 'text');
|
|
82
|
-
return textContent ? [textContent.text] : [];
|
|
91
|
+
const resultText = getJsonRpcResultText(parsed);
|
|
92
|
+
return resultText === undefined ? [] : [resultText];
|
|
83
93
|
}
|
|
84
94
|
catch (error) {
|
|
85
95
|
if (error instanceof SyntaxError)
|
package/dist/types.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isJsonRpcResponse = exports.isOAuthTokenResponse = exports.isStoredApiKey = exports.parseStoredCredentials = exports.CredentialSource = exports.CredentialType = void 0;
|
|
3
|
+
exports.isJsonRpcResponse = exports.jsonRpcResultSchema = exports.isOAuthTokenResponse = exports.isStoredApiKey = exports.parseStoredCredentials = exports.CredentialSource = exports.CredentialType = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
var CredentialType;
|
|
6
6
|
(function (CredentialType) {
|
|
@@ -45,6 +45,10 @@ const isOAuthTokenResponse = (value) => typeof value === 'object' &&
|
|
|
45
45
|
'scope' in value &&
|
|
46
46
|
typeof value.scope === 'string';
|
|
47
47
|
exports.isOAuthTokenResponse = isOAuthTokenResponse;
|
|
48
|
+
exports.jsonRpcResultSchema = zod_1.z.object({
|
|
49
|
+
content: zod_1.z.array(zod_1.z.object({ type: zod_1.z.string(), text: zod_1.z.string() })),
|
|
50
|
+
isError: zod_1.z.boolean().optional(),
|
|
51
|
+
});
|
|
48
52
|
const isJsonRpcResponse = (value) => typeof value === 'object' &&
|
|
49
53
|
value !== null &&
|
|
50
54
|
'jsonrpc' in value &&
|
package/package.json
CHANGED