Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion airtable/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"check": "tsc --noEmit"
},
"dependencies": {
"@decocms/runtime": "1.2.8",
"@decocms/runtime": "1.4.0",
"zod": "^4.0.0"
},
"devDependencies": {
Expand Down
7 changes: 4 additions & 3 deletions airtable/server/tools/auth.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { createPrivateTool } from "@decocms/runtime/tools";
import { createTool, ensureAuthenticated } from "@decocms/runtime/tools";
import { z } from "zod";
import type { Env } from "../main.ts";
import { getAccessToken } from "../lib/env.ts";
import { AirtableClient } from "../lib/airtable-client.ts";

export const createWhoamiTool = (env: Env) =>
createPrivateTool({
createTool({
id: "airtable_whoami",
description:
"Get the current authenticated user's ID, email, and OAuth scopes.",
inputSchema: z.object({}),
execute: async () => {
execute: async (_input, ctx) => {
ensureAuthenticated(ctx!);
const client = new AirtableClient(getAccessToken(env));
return await client.whoami();
},
Expand Down
12 changes: 7 additions & 5 deletions airtable/server/tools/bases.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { createPrivateTool } from "@decocms/runtime/tools";
import { createTool, ensureAuthenticated } from "@decocms/runtime/tools";
import { z } from "zod";
import type { Env } from "../main.ts";
import { getAccessToken } from "../lib/env.ts";
import { AirtableClient } from "../lib/airtable-client.ts";

export const createListBasesTool = (env: Env) =>
createPrivateTool({
createTool({
id: "airtable_list_bases",
description:
"List all Airtable bases accessible to the authenticated user. Supports pagination via offset.",
Expand All @@ -15,14 +15,15 @@ export const createListBasesTool = (env: Env) =>
.optional()
.describe("Pagination offset from a previous response."),
}),
execute: async ({ context }) => {
execute: async ({ context }, ctx) => {
ensureAuthenticated(ctx!);
const client = new AirtableClient(getAccessToken(env));
return await client.listBases(context.offset);
},
});

export const createGetBaseSchemaTool = (env: Env) =>
createPrivateTool({
createTool({
id: "airtable_get_base_schema",
description: "Get the schema (tables, fields, views) of an Airtable base.",
inputSchema: z.object({
Expand All @@ -34,7 +35,8 @@ export const createGetBaseSchemaTool = (env: Env) =>
.optional()
.describe("Pagination offset from a previous response."),
}),
execute: async ({ context }) => {
execute: async ({ context }, ctx) => {
ensureAuthenticated(ctx!);
const client = new AirtableClient(getAccessToken(env));
return await client.getBaseSchema(context.baseId, context.offset);
},
Expand Down
12 changes: 7 additions & 5 deletions airtable/server/tools/fields.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { createPrivateTool } from "@decocms/runtime/tools";
import { createTool, ensureAuthenticated } from "@decocms/runtime/tools";
import { z } from "zod";
import type { Env } from "../main.ts";
import { getAccessToken } from "../lib/env.ts";
import { AirtableClient } from "../lib/airtable-client.ts";

export const createCreateFieldTool = (env: Env) =>
createPrivateTool({
createTool({
id: "airtable_create_field",
description: "Create a new field in an Airtable table.",
inputSchema: z.object({
Expand All @@ -21,7 +21,8 @@ export const createCreateFieldTool = (env: Env) =>
.optional()
.describe("Field-type-specific options."),
}),
execute: async ({ context }) => {
execute: async ({ context }, ctx) => {
ensureAuthenticated(ctx!);
const client = new AirtableClient(getAccessToken(env));
return await client.createField(context.baseId, context.tableId, {
name: context.name,
Expand All @@ -33,7 +34,7 @@ export const createCreateFieldTool = (env: Env) =>
});

export const createUpdateFieldTool = (env: Env) =>
createPrivateTool({
createTool({
id: "airtable_update_field",
description:
"Update the name or description of an existing field in an Airtable table.",
Expand All @@ -56,7 +57,8 @@ export const createUpdateFieldTool = (env: Env) =>
"Provide at least one field to update (name or description).",
},
),
execute: async ({ context }) => {
execute: async ({ context }, ctx) => {
ensureAuthenticated(ctx!);
const client = new AirtableClient(getAccessToken(env));
return await client.updateField(
context.baseId,
Expand Down
32 changes: 19 additions & 13 deletions airtable/server/tools/records.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createPrivateTool } from "@decocms/runtime/tools";
import { createTool, ensureAuthenticated } from "@decocms/runtime/tools";
import { z } from "zod";
import type { Env } from "../main.ts";
import { getAccessToken } from "../lib/env.ts";
Expand All @@ -14,7 +14,7 @@ const SortSchema = z.object({
});

export const createListRecordsTool = (env: Env) =>
createPrivateTool({
createTool({
id: "airtable_list_records",
description:
"List records from an Airtable table with optional filtering, sorting, and field selection.",
Expand Down Expand Up @@ -50,23 +50,25 @@ export const createListRecordsTool = (env: Env) =>
.optional()
.describe("Pagination offset from a previous response."),
}),
execute: async ({ context }) => {
execute: async ({ context }, ctx) => {
ensureAuthenticated(ctx!);
const { baseId, tableIdOrName, ...options } = context;
const client = new AirtableClient(getAccessToken(env));
return await client.listRecords(baseId, tableIdOrName, options);
},
});

export const createGetRecordTool = (env: Env) =>
createPrivateTool({
createTool({
id: "airtable_get_record",
description: "Retrieve a single record by its ID from an Airtable table.",
inputSchema: z.object({
baseId: z.string().describe("The ID of the base."),
tableIdOrName: z.string().describe("The ID or name of the table."),
recordId: z.string().describe("The ID of the record to retrieve."),
}),
execute: async ({ context }) => {
execute: async ({ context }, ctx) => {
ensureAuthenticated(ctx!);
const client = new AirtableClient(getAccessToken(env));
return await client.getRecord(
context.baseId,
Expand All @@ -77,7 +79,7 @@ export const createGetRecordTool = (env: Env) =>
});

export const createSearchRecordsTool = (env: Env) =>
createPrivateTool({
createTool({
id: "airtable_search_records",
description:
"Search for records in an Airtable table by matching a term against specified fields.",
Expand Down Expand Up @@ -107,7 +109,8 @@ export const createSearchRecordsTool = (env: Env) =>
.optional()
.describe("Pagination offset from a previous response."),
}),
execute: async ({ context }) => {
execute: async ({ context }, ctx) => {
ensureAuthenticated(ctx!);
const { baseId, tableIdOrName, searchTerm, searchFields, ...options } =
context;

Expand All @@ -126,7 +129,7 @@ export const createSearchRecordsTool = (env: Env) =>
});

export const createCreateRecordsTool = (env: Env) =>
createPrivateTool({
createTool({
id: "airtable_create_records",
description: `Create one or more records in an Airtable table. Maximum ${MAX_BATCH_RECORDS} records per request.`,
inputSchema: z.object({
Expand All @@ -150,7 +153,8 @@ export const createCreateRecordsTool = (env: Env) =>
"If true, Airtable will auto-convert field values to the correct type.",
),
}),
execute: async ({ context }) => {
execute: async ({ context }, ctx) => {
ensureAuthenticated(ctx!);
const client = new AirtableClient(getAccessToken(env));
return await client.createRecords(
context.baseId,
Expand All @@ -162,7 +166,7 @@ export const createCreateRecordsTool = (env: Env) =>
});

export const createUpdateRecordsTool = (env: Env) =>
createPrivateTool({
createTool({
id: "airtable_update_records",
description: `Update one or more records in an Airtable table. Maximum ${MAX_BATCH_RECORDS} records per request. Supports upsert via performUpsert.`,
inputSchema: z.object({
Expand Down Expand Up @@ -198,7 +202,8 @@ export const createUpdateRecordsTool = (env: Env) =>
.optional()
.describe("If provided, performs an upsert instead of a plain update."),
}),
execute: async ({ context }) => {
execute: async ({ context }, ctx) => {
ensureAuthenticated(ctx!);
const client = new AirtableClient(getAccessToken(env));
return await client.updateRecords(
context.baseId,
Expand All @@ -211,7 +216,7 @@ export const createUpdateRecordsTool = (env: Env) =>
});

export const createDeleteRecordsTool = (env: Env) =>
createPrivateTool({
createTool({
id: "airtable_delete_records",
description: `Delete one or more records from an Airtable table. Maximum ${MAX_BATCH_RECORDS} records per request.`,
inputSchema: z.object({
Expand All @@ -223,7 +228,8 @@ export const createDeleteRecordsTool = (env: Env) =>
.max(MAX_BATCH_RECORDS)
.describe(`Array of record IDs to delete (1-${MAX_BATCH_RECORDS}).`),
}),
execute: async ({ context }) => {
execute: async ({ context }, ctx) => {
ensureAuthenticated(ctx!);
const client = new AirtableClient(getAccessToken(env));
return await client.deleteRecords(
context.baseId,
Expand Down
12 changes: 7 additions & 5 deletions airtable/server/tools/tables.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createPrivateTool } from "@decocms/runtime/tools";
import { createTool, ensureAuthenticated } from "@decocms/runtime/tools";
import { z } from "zod";
import type { Env } from "../main.ts";
import { getAccessToken } from "../lib/env.ts";
Expand All @@ -9,7 +9,7 @@ const FieldOptionSchema = z
.describe("Field-type-specific options (e.g., choices for select fields).");

export const createCreateTableTool = (env: Env) =>
createPrivateTool({
createTool({
id: "airtable_create_table",
description:
"Create a new table in an Airtable base with specified fields.",
Expand Down Expand Up @@ -37,7 +37,8 @@ export const createCreateTableTool = (env: Env) =>
"Array of fields for the table. At least one field is required.",
),
}),
execute: async ({ context }) => {
execute: async ({ context }, ctx) => {
ensureAuthenticated(ctx!);
const client = new AirtableClient(getAccessToken(env));
return await client.createTable(context.baseId, {
name: context.name,
Expand All @@ -48,7 +49,7 @@ export const createCreateTableTool = (env: Env) =>
});

export const createUpdateTableTool = (env: Env) =>
createPrivateTool({
createTool({
id: "airtable_update_table",
description:
"Update the name or description of an existing Airtable table.",
Expand All @@ -70,7 +71,8 @@ export const createUpdateTableTool = (env: Env) =>
"Provide at least one field to update (name or description).",
},
),
execute: async ({ context }) => {
execute: async ({ context }, ctx) => {
ensureAuthenticated(ctx!);
const client = new AirtableClient(getAccessToken(env));
return await client.updateTable(context.baseId, context.tableId, {
name: context.name,
Expand Down
2 changes: 1 addition & 1 deletion blog-post-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"build": "bun run build:server"
},
"dependencies": {
"@decocms/runtime": "1.1.3",
"@decocms/runtime": "1.4.0",
"zod": "^4.0.0"
},
"devDependencies": {
Expand Down
7 changes: 4 additions & 3 deletions blog-post-generator/server/tools/generate-blog-post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { z } from "zod";
import { createPrivateTool } from "@decocms/runtime/tools";
import { createTool, ensureAuthenticated } from "@decocms/runtime/tools";
import type { Env } from "../types/env.ts";

/**
Expand Down Expand Up @@ -63,7 +63,7 @@ const BlogPostRecommendationSchema = z.object({
* Generate blog post tool - generates blog posts from context and tone of voice
*/
export const generateBlogPostTool = (env: Env) =>
createPrivateTool({
createTool({
id: "generate_blog_post",
description:
"Generate blog post suggestions from context and tone of voice. " +
Expand Down Expand Up @@ -127,7 +127,8 @@ export const generateBlogPostTool = (env: Env) =>
.describe("Raw response from webhook for additional details"),
error: z.string().optional(),
}),
execute: async ({ context }) => {
execute: async ({ context }, ctx) => {
ensureAuthenticated(ctx!);
const {
contextText,
contextJson,
Expand Down
Loading
Loading