From bb5afa099a602396abd2fd19393b1bd5290ac3d6 Mon Sep 17 00:00:00 2001 From: geoffsee <> Date: Thu, 17 Jul 2025 14:44:04 -0400 Subject: [PATCH] Replace yacht control tooling with map control functionality, updating relevant references and logic. --- .../ai/src/providers/chat-stream-provider.ts | 8 +- packages/ai/src/tools/maps.ts | 111 ++++++++++++++++++ packages/ai/src/tools/yachtpit.ts | 68 ----------- 3 files changed, 115 insertions(+), 72 deletions(-) create mode 100644 packages/ai/src/tools/maps.ts delete mode 100644 packages/ai/src/tools/yachtpit.ts diff --git a/packages/ai/src/providers/chat-stream-provider.ts b/packages/ai/src/providers/chat-stream-provider.ts index f400c5a..95667d2 100644 --- a/packages/ai/src/providers/chat-stream-provider.ts +++ b/packages/ai/src/providers/chat-stream-provider.ts @@ -1,8 +1,8 @@ import { OpenAI } from 'openai'; import ChatSdk from '../chat-sdk/chat-sdk.ts'; +import { mapControlAi, MapsTools } from '../tools/maps.ts'; import { getWeather, WeatherTool } from '../tools/weather.ts'; -import { yachtpitAi, YachtpitTools } from '../tools/yachtpit.ts'; import type { GenericEnv } from '../types'; export interface CommonProviderParams { @@ -38,14 +38,14 @@ export abstract class BaseChatProvider implements ChatStreamProvider { const client = this.getOpenAIClient(param); - const tools = [WeatherTool, YachtpitTools]; + const tools = [WeatherTool, MapsTools]; const callFunction = async (name, args) => { if (name === 'get_weather') { return getWeather(args.latitude, args.longitude); } - if (name === 'ship_control') { - return yachtpitAi({ action: args.action, value: args.value }); + if (name === 'maps_control') { + return mapControlAi({ action: args.action, value: args.value }); } }; diff --git a/packages/ai/src/tools/maps.ts b/packages/ai/src/tools/maps.ts new file mode 100644 index 0000000..4c60d42 --- /dev/null +++ b/packages/ai/src/tools/maps.ts @@ -0,0 +1,111 @@ +export interface MapsControlResult { + message: string; + status: 'success' | 'error'; + data?: any; +} + +/** + * A mock interface for controlling a map. + */ +export const MapsTools = { + type: 'function', + description: + 'Interface for controlling a web-rendered map to explore publicly available geospatial data', + + /** + * Mock implementation of a maps control command. + */ + function: { + name: 'maps_control', + parameters: { + type: 'object', + properties: { + action: { + type: 'string', + enum: ['add_point', 'zoom_to', 'search_datasets', 'add_dataset', 'remove_dataset'], + description: 'Action to perform on the geospatial map.', + }, + value: { + type: 'string', + description: 'Numeric value for the action, indicating a code for reference', + }, + }, + required: ['action'], + additionalProperties: false, + }, + }, +}; + +export function mapControlAi(args: { action: string; value?: string }): Promise { + switch (args.action) { + case 'add_point': { + if (!args.value) { + return Promise.resolve({ + status: 'error', + message: 'Missing point coordinates or reference code.', + }); + } + return Promise.resolve({ + status: 'success', + message: `Point added to map with reference: ${args.value}`, + data: { pointId: args.value, action: 'add_point' }, + }); + } + + case 'zoom_to': { + if (!args.value) { + return Promise.resolve({ status: 'error', message: 'Missing zoom target reference.' }); + } + return Promise.resolve({ + status: 'success', + message: `Map zoomed to: ${args.value}`, + data: { target: args.value, action: 'zoom_to' }, + }); + } + + case 'search_datasets': { + const searchTerm = args.value || 'all'; + return Promise.resolve({ + status: 'success', + message: `Searching datasets for: ${searchTerm}`, + data: { + searchTerm, + action: 'search_datasets', + results: [ + { id: 'osm', name: 'OpenStreetMap', type: 'base_layer' }, + { id: 'satellite', name: 'Satellite Imagery', type: 'base_layer' }, + { id: 'maritime', name: 'Maritime Data', type: 'overlay' }, + ], + }, + }); + } + + case 'add_dataset': { + if (!args.value) { + return Promise.resolve({ status: 'error', message: 'Missing dataset reference.' }); + } + return Promise.resolve({ + status: 'success', + message: `Dataset added to map: ${args.value}`, + data: { datasetId: args.value, action: 'add_dataset' }, + }); + } + + case 'remove_dataset': { + if (!args.value) { + return Promise.resolve({ status: 'error', message: 'Missing dataset reference.' }); + } + return Promise.resolve({ + status: 'success', + message: `Dataset removed from map: ${args.value}`, + data: { datasetId: args.value, action: 'remove_dataset' }, + }); + } + + default: + return Promise.resolve({ + status: 'error', + message: `Invalid action: ${args.action}. Valid actions are: add_point, zoom_to, search_datasets, add_dataset, remove_dataset`, + }); + } +} diff --git a/packages/ai/src/tools/yachtpit.ts b/packages/ai/src/tools/yachtpit.ts deleted file mode 100644 index ac492a4..0000000 --- a/packages/ai/src/tools/yachtpit.ts +++ /dev/null @@ -1,68 +0,0 @@ -export interface ShipControlResult { - message: string; - status: 'success' | 'error'; - data?: any; -} - -/** - * A mock interface for controlling a ship. - */ -export const YachtpitTools = { - type: 'function', - description: 'Interface for controlling a ship: set speed, change heading, report status, etc.', - - /** - * Mock implementation of a ship control command. - */ - function: { - name: 'ship_control', - parameters: { - type: 'object', - properties: { - action: { - type: 'string', - enum: ['set_speed', 'change_heading', 'report_status', 'stop'], - description: 'Action to perform on the ship.', - }, - value: { - type: 'number', - description: - 'Numeric value for the action, such as speed (knots) or heading (degrees). Only required for set_speed and change_heading.', - }, - }, - required: ['action'], - additionalProperties: false, - }, - }, -}; - -export function yachtpitAi(args: { action: string; value?: number }): Promise { - switch (args.action) { - case 'set_speed': - if (typeof args.value !== 'number') { - return { status: 'error', message: 'Missing speed value.' }; - } - return { status: 'success', message: `Speed set to ${args.value} knots.` }; - case 'change_heading': - if (typeof args.value !== 'number') { - return { status: 'error', message: 'Missing heading value.' }; - } - return { status: 'success', message: `Heading changed to ${args.value} degrees.` }; - case 'report_status': - // Return a simulated ship status - return { - status: 'success', - message: 'Ship status reported.', - data: { - speed: 12, - heading: 87, - engine: 'nominal', - position: { lat: 42.35, lon: -70.88 }, - }, - }; - case 'stop': - return { status: 'success', message: 'Ship stopped.' }; - default: - return { status: 'error', message: 'Invalid action.' }; - } -}