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
7 changes: 6 additions & 1 deletion app/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import type { FeatureCollection } from 'geojson'
import { Spinner } from '@/components/ui/spinner'
import { Section } from '@/components/section'
import { FollowupPanel } from '@/components/followup-panel'
import { inquire, researcher, taskManager, querySuggestor, resolutionSearch, type DrawnFeature } from '@/lib/agents'
import { inquire } from '@/lib/agents/inquire'
import { researcher } from '@/lib/agents/researcher'
import { taskManager } from '@/lib/agents/task-manager'
import { querySuggestor } from '@/lib/agents/query-suggestor'
import { resolutionSearch } from '@/lib/agents/resolution-search'
import { type DrawnFeature } from '@/lib/types/geospatial'
import { writer } from '@/lib/agents/writer'
import { saveChat, getSystemPrompt } from '@/lib/actions/chat'
import { Chat, AIMessage } from '@/lib/types'
Expand Down
2 changes: 1 addition & 1 deletion lib/actions/suggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { createStreamableUI, createStreamableValue } from 'ai/rsc'
import { CoreMessage, LanguageModel, streamObject } from 'ai'
import { PartialRelated, relatedSchema } from '@/lib/schema/related'
import { getModel } from '../utils'
import { getModel } from '../utils/ai-model'
import { MapData } from '@/components/map/map-data-context'

export async function getSuggestions(
Expand Down
5 changes: 0 additions & 5 deletions lib/agents/index.tsx

This file was deleted.

4 changes: 3 additions & 1 deletion lib/agents/inquire.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
'use server'

import { Copilot } from '@/components/copilot';
import { createStreamableUI, createStreamableValue } from 'ai/rsc';
import { CoreMessage, LanguageModel, streamObject } from 'ai';
import { PartialInquiry, inquirySchema } from '@/lib/schema/inquiry';
import { getModel } from '../utils';
import { getModel } from '../utils/ai-model';

// Define a plain object type for the inquiry prop
interface InquiryProp {
Expand Down
4 changes: 3 additions & 1 deletion lib/agents/query-suggestor.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
'use server'

import { createStreamableUI, createStreamableValue } from 'ai/rsc'
import { CoreMessage, LanguageModel, streamObject } from 'ai'
import { PartialRelated, relatedSchema } from '@/lib/schema/related'
import { Section } from '@/components/section'
import SearchRelated from '@/components/search-related'
import { getModel } from '../utils'
import { getModel } from '../utils/ai-model'

export async function querySuggestor(
uiStream: ReturnType<typeof createStreamableUI>,
Expand Down
6 changes: 4 additions & 2 deletions lib/agents/researcher.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use server'

// lib/agents/researcher.tsx
import { createStreamableUI, createStreamableValue } from 'ai/rsc'
import {
Expand All @@ -10,9 +12,9 @@ import {
import { Section } from '@/components/section'
import { BotMessage } from '@/components/message'
import { getTools } from './tools'
import { getModel } from '../utils'
import { getModel } from '../utils/ai-model'
import { MapProvider } from '@/lib/store/settings'
import { DrawnFeature } from './resolution-search'
import { type DrawnFeature } from '@/lib/types/geospatial'

// This magic tag lets us write raw multi-line strings with backticks, arrows, etc.
const raw = String.raw
Expand Down
21 changes: 8 additions & 13 deletions lib/agents/resolution-search.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use server'

import { CoreMessage, streamObject } from 'ai'
import { getModel } from '@/lib/utils'
import { getModel } from '@/lib/utils/ai-model'
import { z } from 'zod'

// This agent is now a pure data-processing module, with no UI dependencies.
import { type DrawnFeature } from '@/lib/types/geospatial'

// Define the schema for the structured response from the AI.
const resolutionSearchSchema = z.object({
Expand All @@ -23,13 +24,6 @@ const resolutionSearchSchema = z.object({
}).describe('A GeoJSON object containing points of interest and classified land features to be overlaid on the map.'),
})

export interface DrawnFeature {
id: string;
type: 'Polygon' | 'LineString';
measurement: string;
geometry: any;
}

export async function resolutionSearch(messages: CoreMessage[], timezone: string = 'UTC', drawnFeatures?: DrawnFeature[]) {
const localTime = new Date().toLocaleString('en-US', {
timeZone: timezone,
Expand Down Expand Up @@ -63,15 +57,16 @@ Analyze the user's prompt and the image to provide a holistic understanding of t

const filteredMessages = messages.filter(msg => msg.role !== 'system');

// Check if any message contains an image (resolution search is specifically for image analysis)
// Check if any message contains an image
const hasImage = messages.some(message =>
Array.isArray(message.content) &&
message.content.some(part => part.type === 'image')
)

// Use streamObject to get partial results.
const model = await getModel(hasImage);

return streamObject({
model: await getModel(hasImage),
model,
system: systemPrompt,
messages: filteredMessages,
schema: resolutionSearchSchema,
Expand Down
4 changes: 3 additions & 1 deletion lib/agents/task-manager.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use server'

import { CoreMessage, generateObject, LanguageModel } from 'ai'
import { nextActionSchema } from '../schema/next-action'
import { getModel } from '../utils'
import { getModel } from '../utils/ai-model'

// Decide whether inquiry is required for the user input
export async function taskManager(messages: CoreMessage[]) {
Expand Down
Loading