@circleback/cli 0.3.1 → 0.3.3

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.
@@ -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
- if (body.error) {
59
- throw new Error(body.error.message);
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 textContent.text;
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
- if (parsed.error) {
79
- throw new Error(parsed.error.message);
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)
@@ -242,7 +242,9 @@ const formatActionItems = (actionItems) => {
242
242
  item.id,
243
243
  item.status,
244
244
  item.assignee?.name ?? constants_1.UNASSIGNED_ACTION_ITEM_ASSIGNEE_LABEL,
245
- (0, string_1.truncate)(item.meeting.name || constants_1.DEFAULT_MEETING_NAME, meetingWidth - 2),
245
+ item.meetings
246
+ .map((meeting) => (0, string_1.truncate)(meeting.name || constants_1.DEFAULT_MEETING_NAME, meetingWidth - 2))
247
+ .join('\n') || '-',
246
248
  (0, date_1.formatDate)(item.createdAt),
247
249
  ]));
248
250
  return `${chalk_1.default.bold(`${(0, string_1.pluralize)(actionItems.length, 'action item', 'action items')} found`)}\n${table.toString()}`;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@circleback/cli",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Circleback CLI. Search and access meetings, emails, calendar events, and more.",
5
5
  "license": "MIT",
6
6
  "author": "Circleback <support@circleback.ai> (https://circleback.ai)",
@@ -25,6 +25,7 @@
25
25
  "prebuild": "rm -rf dist",
26
26
  "build": "tsc && chmod +x dist/index.js",
27
27
  "typecheck": "tsc --noEmit",
28
+ "test:unit": "jest --runInBand",
28
29
  "postinstall": "echo '\n Welcome to the Circleback CLI. Run `circleback` or `cb` to get started.\n'",
29
30
  "prepublishOnly": "npm run build"
30
31
  },