Skip to content
Draft
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
16 changes: 14 additions & 2 deletions src/__tests__/linkup-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,16 @@ describe('LinkupClient', () => {

it('should handle structured output type using JSON schema', async () => {
maxios.post.mockResolvedValueOnce({
data: 'foo',
data: {
data: 'foo',
sources: [
{
name: 'foo',
snippet: 'foo bar baz',
url: 'http://foo.bar/baz',
},
],
},
} as AxiosResponse);

const result = await underTest.search({
Expand All @@ -152,7 +161,10 @@ describe('LinkupClient', () => {
structuredOutputSchema: { type: 'string' },
});

expect(result).toEqual('foo');
expect(result).toEqual({
data: 'foo',
sources: [{ name: 'foo', snippet: 'foo bar baz', url: 'http://foo.bar/baz' }],
});
});

it('should handle structured output type using Zod schema', async () => {
Expand Down
9 changes: 6 additions & 3 deletions src/linkup-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
SearchParams,
SearchResults,
SourcedAnswer,
StructuredOutputSchema,
StructuredResult,
} from './types';
import { concatErrorAndDetails, isZodObject } from './utils';

Expand All @@ -42,7 +42,7 @@ export class LinkupClient {
: T extends 'searchResults'
? SearchResults
: T extends 'structured'
? StructuredOutputSchema
? StructuredResult
: never
> {
const headers: Record<string, string> = {
Expand Down Expand Up @@ -108,8 +108,11 @@ export class LinkupClient {
return {
results: (searchResponse as SearchResults).results,
} as LinkupSearchResponse<T>;
// biome-ignore lint/complexity/noUselessSwitchCase: left for exhaustiveness
case 'structured':
return {
data: (searchResponse as StructuredResult).data,
sources: (searchResponse as StructuredResult).sources,
} as LinkupSearchResponse<T>;
default:
return searchResponse as LinkupSearchResponse<T>;
}
Expand Down
7 changes: 6 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type LinkupSearchResponse<T> = T extends 'sourcedAnswer'
: T extends 'searchResults'
? SearchResults
: T extends 'structured'
? StructuredOutputSchema
? StructuredResult
: never;

export interface SearchResults {
Expand All @@ -49,6 +49,11 @@ export interface ImageSearchResult {
url: string;
}

export interface StructuredResult {
data: string;
sources: (Source | TextSearchResult | ImageSearchResult)[];
}

export interface SourcedAnswer {
answer: string;
sources: (Source | TextSearchResult | ImageSearchResult)[];
Expand Down