mirror of
https://github.com/geoffsee/open-gsio.git
synced 2025-09-08 22:56:46 +00:00
Replace yacht control tooling with map control functionality, updating relevant references and logic.
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
import { OpenAI } from 'openai';
|
import { OpenAI } from 'openai';
|
||||||
|
|
||||||
import ChatSdk from '../chat-sdk/chat-sdk.ts';
|
import ChatSdk from '../chat-sdk/chat-sdk.ts';
|
||||||
|
import { mapControlAi, MapsTools } from '../tools/maps.ts';
|
||||||
import { getWeather, WeatherTool } from '../tools/weather.ts';
|
import { getWeather, WeatherTool } from '../tools/weather.ts';
|
||||||
import { yachtpitAi, YachtpitTools } from '../tools/yachtpit.ts';
|
|
||||||
import type { GenericEnv } from '../types';
|
import type { GenericEnv } from '../types';
|
||||||
|
|
||||||
export interface CommonProviderParams {
|
export interface CommonProviderParams {
|
||||||
@@ -38,14 +38,14 @@ export abstract class BaseChatProvider implements ChatStreamProvider {
|
|||||||
|
|
||||||
const client = this.getOpenAIClient(param);
|
const client = this.getOpenAIClient(param);
|
||||||
|
|
||||||
const tools = [WeatherTool, YachtpitTools];
|
const tools = [WeatherTool, MapsTools];
|
||||||
|
|
||||||
const callFunction = async (name, args) => {
|
const callFunction = async (name, args) => {
|
||||||
if (name === 'get_weather') {
|
if (name === 'get_weather') {
|
||||||
return getWeather(args.latitude, args.longitude);
|
return getWeather(args.latitude, args.longitude);
|
||||||
}
|
}
|
||||||
if (name === 'ship_control') {
|
if (name === 'maps_control') {
|
||||||
return yachtpitAi({ action: args.action, value: args.value });
|
return mapControlAi({ action: args.action, value: args.value });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
111
packages/ai/src/tools/maps.ts
Normal file
111
packages/ai/src/tools/maps.ts
Normal file
@@ -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<MapsControlResult> {
|
||||||
|
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`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@@ -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<ShipControlResult> {
|
|
||||||
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.' };
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user