@youdotcom-oss/api 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +551 -0
- package/bin/cli.js +5483 -0
- package/package.json +68 -0
- package/src/cli.ts +98 -0
- package/src/commands/contents.ts +52 -0
- package/src/commands/express.ts +52 -0
- package/src/commands/search.ts +52 -0
- package/src/contents/contents.schemas.ts +46 -0
- package/src/contents/contents.utils.ts +98 -0
- package/src/contents/tests/contents.utils.spec.ts +78 -0
- package/src/express/express.schemas.ts +77 -0
- package/src/express/express.utils.ts +113 -0
- package/src/express/tests/express.utils.spec.ts +83 -0
- package/src/main.ts +22 -0
- package/src/search/search.schemas.ts +110 -0
- package/src/search/search.utils.ts +80 -0
- package/src/search/tests/search.utils.spec.ts +135 -0
- package/src/shared/api.constants.ts +10 -0
- package/src/shared/api.types.ts +1 -0
- package/src/shared/check-response-for-errors.ts +13 -0
- package/src/shared/generate-error-report-link.ts +35 -0
- package/src/shared/tests/check-response-for-errors.spec.ts +31 -0
- package/src/shared/tests/format-search-results-text.spec.ts +85 -0
- package/src/shared/use-get-user-agents.ts +8 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import { formatSearchResultsText } from '../../../../mcp/src/shared/format-search-results-text.ts'
|
|
3
|
+
|
|
4
|
+
describe('formatSearchResultsText', () => {
|
|
5
|
+
test('formats basic search results with title and URL', () => {
|
|
6
|
+
const results = [
|
|
7
|
+
{
|
|
8
|
+
url: 'https://example.com',
|
|
9
|
+
title: 'Example Title',
|
|
10
|
+
},
|
|
11
|
+
]
|
|
12
|
+
const formatted = formatSearchResultsText(results)
|
|
13
|
+
expect(formatted).toContain('Title: Example Title')
|
|
14
|
+
expect(formatted).toContain('URL: https://example.com')
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
test('includes page_age when present', () => {
|
|
18
|
+
const results = [
|
|
19
|
+
{
|
|
20
|
+
url: 'https://example.com',
|
|
21
|
+
title: 'Example',
|
|
22
|
+
page_age: '2024-01-15T10:00:00Z',
|
|
23
|
+
},
|
|
24
|
+
]
|
|
25
|
+
const formatted = formatSearchResultsText(results)
|
|
26
|
+
expect(formatted).toContain('Published: 2024-01-15T10:00:00Z')
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('includes description when present', () => {
|
|
30
|
+
const results = [
|
|
31
|
+
{
|
|
32
|
+
url: 'https://example.com',
|
|
33
|
+
title: 'Example',
|
|
34
|
+
description: 'A test description',
|
|
35
|
+
},
|
|
36
|
+
]
|
|
37
|
+
const formatted = formatSearchResultsText(results)
|
|
38
|
+
expect(formatted).toContain('Description: A test description')
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
test('includes snippets array when present', () => {
|
|
42
|
+
const results = [
|
|
43
|
+
{
|
|
44
|
+
url: 'https://example.com',
|
|
45
|
+
title: 'Example',
|
|
46
|
+
snippets: ['Snippet one', 'Snippet two'],
|
|
47
|
+
},
|
|
48
|
+
]
|
|
49
|
+
const formatted = formatSearchResultsText(results)
|
|
50
|
+
expect(formatted).toContain('Snippets:')
|
|
51
|
+
expect(formatted).toContain('- Snippet one')
|
|
52
|
+
expect(formatted).toContain('- Snippet two')
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
test('includes single snippet when present', () => {
|
|
56
|
+
const results = [
|
|
57
|
+
{
|
|
58
|
+
url: 'https://example.com',
|
|
59
|
+
title: 'Example',
|
|
60
|
+
snippet: 'Single snippet text',
|
|
61
|
+
},
|
|
62
|
+
]
|
|
63
|
+
const formatted = formatSearchResultsText(results)
|
|
64
|
+
expect(formatted).toContain('Snippet: Single snippet text')
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
test('formats multiple results with separator', () => {
|
|
68
|
+
const results = [
|
|
69
|
+
{ url: 'https://a.com', title: 'Title A' },
|
|
70
|
+
{ url: 'https://b.com', title: 'Title B' },
|
|
71
|
+
]
|
|
72
|
+
const formatted = formatSearchResultsText(results)
|
|
73
|
+
expect(formatted).toContain('Title A')
|
|
74
|
+
expect(formatted).toContain('Title B')
|
|
75
|
+
// Results should be separated by double newlines
|
|
76
|
+
const parts = formatted.split('\n\n')
|
|
77
|
+
expect(parts.length).toBeGreaterThan(1)
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
test('handles empty results array', () => {
|
|
81
|
+
const results: Array<{ url: string; title: string }> = []
|
|
82
|
+
const formatted = formatSearchResultsText(results)
|
|
83
|
+
expect(formatted).toBe('')
|
|
84
|
+
})
|
|
85
|
+
})
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import packageJson from '../../package.json' with { type: 'json' }
|
|
2
|
+
import type { GetUserAgent } from './api.types.ts'
|
|
3
|
+
|
|
4
|
+
// getUserAgent function for tracking
|
|
5
|
+
export const useGetUserAgent =
|
|
6
|
+
(client = ''): GetUserAgent =>
|
|
7
|
+
() =>
|
|
8
|
+
`CLI/ ${packageJson.version} (You.com;${client})`
|