@credal/actions 0.2.216 → 0.2.217

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.
@@ -125,8 +125,16 @@ async function addActionTypes({ file, prefix, action }) {
125
125
  });
126
126
  }
127
127
  async function addTypesToFile({ file, obj, fallback, name, }) {
128
- // Tool calling framework currently having trouble filling in records as opposed to objects
129
- const zodSchema = obj ? convert(obj).replace(/z\.record\(z\.any\(\)\)/g, "z.object({}).catchall(z.any())") : fallback;
128
+ // Tool calling framework currently having trouble filling in records as opposed to objects.
129
+ // Also coerce numeric types from strings: LLMs often emit numbers as JSON strings (e.g. "2"
130
+ // instead of 2) even when the schema specifies integer/number, causing Zod validation failures.
131
+ // z.coerce.number() is a no-op for actual numbers, so this is fully backward-compatible.
132
+ const zodSchema = obj
133
+ ? convert(obj)
134
+ .replace(/z\.record\(z\.any\(\)\)/g, "z.object({}).catchall(z.any())")
135
+ .replace(/z\.number\(\)\.int\(\)/g, "z.coerce.number().int()")
136
+ .replace(/z\.number\(\)/g, "z.coerce.number()")
137
+ : fallback;
130
138
  const zodName = `${name}Schema`;
131
139
  file.addVariableStatement({
132
140
  declarationKind: VariableDeclarationKind.Const,
@@ -9,16 +9,17 @@ const appendRowsToSpreadsheet = async ({ params, authParams, }) => {
9
9
  throw new Error(MISSING_AUTH_TOKEN);
10
10
  }
11
11
  const { spreadsheetId, sheetName, rows } = params;
12
- // Transform rows from schema format to Google Sheets API format
13
- // Schema: [[{ stringValue: "cell1" }, { stringValue: "cell2" }], ...]
14
- // API expects: [["cell1", "cell2"], ...]
15
- const values = rows.map(row => row.map(cell => cell.stringValue));
16
- const appendUrl = `https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}/values/'${sheetName ?? "Sheet1"}':append`;
17
12
  try {
13
+ if (rows.length === 0) {
14
+ throw new Error("rows array cannot be empty");
15
+ }
16
+ const sheet = sheetName ?? "Sheet1";
17
+ const quotedSheet = /[\s'!]/.test(sheet) ? `'${sheet.replace(/'/g, "''")}'` : sheet;
18
+ const appendUrl = `https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}/values/${encodeURIComponent(quotedSheet)}:append`;
18
19
  const response = await axiosClient.post(appendUrl, {
19
- values,
20
+ values: rows,
20
21
  majorDimension: "ROWS",
21
- range: `'${sheetName}'`,
22
+ range: quotedSheet,
22
23
  }, {
23
24
  headers: {
24
25
  Authorization: `Bearer ${authParams.authToken}`,
@@ -8,20 +8,26 @@ const updateRowsInSpreadsheet = async ({ params, authParams, }) => {
8
8
  if (!authParams.authToken) {
9
9
  throw new Error(MISSING_AUTH_TOKEN);
10
10
  }
11
- const { spreadsheetId, sheetName, startRow, rows } = params;
12
- if (rows.length === 0) {
13
- throw new Error("rows array cannot be empty");
14
- }
15
- const values = rows.map(row => row.map(cell => cell.stringValue));
16
- if (startRow < 1) {
17
- throw new Error("startRow must be >= 1");
18
- }
19
- const endRow = startRow + rows.length - 1;
20
- const range = `'${sheetName ?? "Sheet1"}'!A${startRow}:ZZ${endRow}`;
21
- const updateUrl = `https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}/values/${encodeURIComponent(range)}`;
11
+ const { spreadsheetId, sheetName, startRow, startColumn, rows } = params;
22
12
  try {
13
+ if (rows.length === 0) {
14
+ throw new Error("rows array cannot be empty");
15
+ }
16
+ if (startRow < 1) {
17
+ throw new Error("startRow must be >= 1");
18
+ }
19
+ const col = startColumn ?? "A";
20
+ if (!/^[A-Za-z]+$/.test(col)) {
21
+ throw new Error(`startColumn must be a column letter (e.g. "A", "BE"), got: "${col}"`);
22
+ }
23
+ const endRow = startRow + rows.length - 1;
24
+ const sheet = sheetName ?? "Sheet1";
25
+ // Only quote sheet names that contain spaces or special characters
26
+ const quotedSheet = /[\s'!]/.test(sheet) ? `'${sheet.replace(/'/g, "''")}'` : sheet;
27
+ const range = `${quotedSheet}!${col}${startRow}:ZZ${endRow}`;
28
+ const updateUrl = `https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}/values/${encodeURIComponent(range)}`;
23
29
  const response = await axiosClient.put(updateUrl, {
24
- values,
30
+ values: rows,
25
31
  majorDimension: "ROWS",
26
32
  range,
27
33
  }, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@credal/actions",
3
- "version": "0.2.216",
3
+ "version": "0.2.217",
4
4
  "type": "module",
5
5
  "description": "AI Actions by Credal AI",
6
6
  "sideEffects": false,