@xl0/pi-lovely-web 0.1.2 → 0.1.4

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 CHANGED
@@ -42,21 +42,21 @@ The plain-text tool output looks likes this:
42
42
  - `web_fetch` - The single web page in markdown format
43
43
  - `web_image` - The single image, returned as media content. Respects the Pi image resizing settings:
44
44
 
45
- ![web_image](assets/web_image.png)
45
+ ![web_image](https://raw.githubusercontent.com/xl0/pi-lovely-web/master/assets/web_image.png)
46
46
 
47
47
 
48
48
  ## Configuration
49
49
 
50
50
  Run `/lovely-web` in Pi to configure providers interactively:
51
51
 
52
- ![alt text](assets/settings.png)
52
+ ![settings](https://raw.githubusercontent.com/xl0/pi-lovely-web/master/assets/settings.png)
53
53
 
54
54
  The settings are stored in `~/.pi/agent/xl0-pi-lovely-web.json` (global) or `.pi/xl0-pi-lovely-web.json` (project):
55
55
 
56
56
  ```json
57
57
  {
58
- "webSearch": { "provider": "firecrawl", "enabled": true },
59
- "webFetch": { "provider": "firecrawl", "enabled": true },
58
+ "webSearch": { "provider": "firecrawl" },
59
+ "webFetch": { "provider": "firecrawl" },
60
60
  "webImage": { "enabled": true },
61
61
  "webApiKeys": {
62
62
  "firecrawl": "fc-...",
@@ -69,9 +69,9 @@ The settings are stored in `~/.pi/agent/xl0-pi-lovely-web.json` (global) or `.pi
69
69
 
70
70
  API keys can also be set via environment variables: `FIRECRAWL_API_KEY`, `EXA_API_KEY`, `TAVILY_API_KEY`, `BRAVE_API_KEY`.
71
71
 
72
- Search and fetch can use different providers. If only `webSearch.provider` is set,
73
- `web_fetch` falls back to it when that provider supports fetch. Set `enabled:false`
74
- on `webSearch`, `webFetch`, or `webImage` to remove that tool from Pi's active tool list.
72
+ Search and fetch default to Firecrawl and can use different providers. Set `provider:null`
73
+ on `webSearch` or `webFetch` to remove that tool from Pi's active tool list. Set
74
+ `webImage.enabled:false` to disable `web_image`.
75
75
 
76
76
  `waitFor` is provider-specific: Firecrawl supports it as an extra pre-capture delay; Exa and Tavily ignore it and `web_fetch` returns a warning if supplied.
77
77
 
@@ -4,6 +4,7 @@ import { type ExtensionAPI, ExtensionInputComponent, getSelectListTheme, getSett
4
4
  import { Container, SelectList, type SettingItem, SettingsList, Text } from "@earendil-works/pi-tui"
5
5
  import {
6
6
  applyToolConfig,
7
+ DEFAULT_PROVIDER_ID,
7
8
  DISABLED_LABEL,
8
9
  getImageMaxSize,
9
10
  isFetchEnabled,
@@ -68,14 +69,14 @@ export function registerLovelyWebCommand(pi: ExtensionAPI) {
68
69
  {
69
70
  id: "search",
70
71
  label: "web_search",
71
- currentValue: isSearchEnabled(config) ? providerLabel(config.webSearch?.provider) : DISABLED_LABEL,
72
+ currentValue: isSearchEnabled(config) ? providerLabel(config.webSearch?.provider ?? DEFAULT_PROVIDER_ID) : DISABLED_LABEL,
72
73
  description: "Search provider, or disabled to remove web_search from active tools.",
73
74
  submenu: (currentValue, done) => providerSubmenu("Select search provider", searchLabels, currentValue, done)
74
75
  },
75
76
  {
76
77
  id: "fetch",
77
78
  label: "web_fetch",
78
- currentValue: isFetchEnabled(config) ? providerLabel(config.webFetch?.provider) : DISABLED_LABEL,
79
+ currentValue: isFetchEnabled(config) ? providerLabel(config.webFetch?.provider ?? DEFAULT_PROVIDER_ID) : DISABLED_LABEL,
79
80
  description: "Fetch provider, or disabled to remove web_fetch from active tools.",
80
81
  submenu: (currentValue, done) => providerSubmenu("Select fetch provider", fetchLabels, currentValue, done)
81
82
  },
@@ -89,9 +90,9 @@ export function registerLovelyWebCommand(pi: ExtensionAPI) {
89
90
  {
90
91
  id: "image-resize",
91
92
  label: "Resize images",
92
- currentValue: isImageResizeEnabled(config) ? "enabled" : "disabled",
93
+ currentValue: isImageResizeEnabled(config) ? "on" : "off",
93
94
  description: "Resize fetched images to fit within the max size limit.",
94
- values: ["enabled", "disabled"]
95
+ values: ["on", "off"]
95
96
  },
96
97
  {
97
98
  id: "image-max-size",
@@ -145,21 +146,21 @@ export function registerLovelyWebCommand(pi: ExtensionAPI) {
145
146
  getSettingsListTheme(),
146
147
  (id, newValue) => {
147
148
  if (id === "search") {
148
- if (newValue === DISABLED_LABEL) config.webSearch = { ...config.webSearch, enabled: false }
149
+ if (newValue === DISABLED_LABEL) config.webSearch = { provider: null }
149
150
  else {
150
151
  const providerId = providerIdFromLabel(newValue)
151
- if (providerId) config.webSearch = { provider: providerId, enabled: true }
152
+ if (providerId) config.webSearch = { provider: providerId }
152
153
  }
153
154
  } else if (id === "fetch") {
154
- if (newValue === DISABLED_LABEL) config.webFetch = { ...config.webFetch, enabled: false }
155
+ if (newValue === DISABLED_LABEL) config.webFetch = { provider: null }
155
156
  else {
156
157
  const providerId = providerIdFromLabel(newValue)
157
- if (providerId) config.webFetch = { provider: providerId, enabled: true }
158
+ if (providerId) config.webFetch = { provider: providerId }
158
159
  }
159
160
  } else if (id === "image") {
160
161
  config.webImage = { ...config.webImage, enabled: newValue === "enabled" }
161
162
  } else if (id === "image-resize") {
162
- config.webImage = { ...config.webImage, resize: newValue === "enabled" }
163
+ config.webImage = { ...config.webImage, resize: newValue === "on" }
163
164
  }
164
165
  save()
165
166
  },
@@ -9,6 +9,7 @@ import { tavilyProvider } from "./providers/tavily.js"
9
9
  import type { Provider, WebToolsConfig } from "./providers/types.js"
10
10
 
11
11
  export const DEFAULT_TIMEOUT_MS = 30_000
12
+ export const DEFAULT_PROVIDER_ID = "firecrawl"
12
13
  export const DISABLED_LABEL = "Disabled"
13
14
 
14
15
  export const providers: Record<string, Provider> = {
@@ -21,11 +22,11 @@ export const providers: Record<string, Provider> = {
21
22
  export const providerNames = Object.keys(providers)
22
23
 
23
24
  export function isSearchEnabled(config: WebToolsConfig): boolean {
24
- return config.webSearch?.enabled !== false
25
+ return config.webSearch?.provider !== null
25
26
  }
26
27
 
27
28
  export function isFetchEnabled(config: WebToolsConfig): boolean {
28
- return config.webFetch?.enabled !== false
29
+ return config.webFetch?.provider !== null
29
30
  }
30
31
 
31
32
  export function isImageEnabled(config: WebToolsConfig): boolean {
@@ -46,11 +47,7 @@ function resolveProviderId(type: "search" | "fetch", config: WebToolsConfig): st
46
47
 
47
48
  const direct = type === "search" ? config.webSearch?.provider : config.webFetch?.provider
48
49
  const fallback = type === "fetch" && isSearchEnabled(config) ? config.webSearch?.provider : undefined
49
- const id = direct || fallback
50
- if (!id) {
51
- const hint = type === "search" ? "webSearch.provider" : "webFetch.provider"
52
- throw new Error(`No ${type} provider configured. Set ${hint} via /lovely-web.`)
53
- }
50
+ const id = direct ?? fallback ?? DEFAULT_PROVIDER_ID
54
51
  if (!providers[id]) throw new Error(`Unknown provider "${id}". Available: ${Object.keys(providers).join(", ")}.`)
55
52
  return id
56
53
  }
@@ -83,8 +80,8 @@ export function loadConfig(cwd: string): WebToolsConfig {
83
80
  return {
84
81
  ...global,
85
82
  ...project,
86
- webSearch: { ...global.webSearch, ...project.webSearch },
87
- webFetch: { ...global.webFetch, ...project.webFetch },
83
+ webSearch: { provider: DEFAULT_PROVIDER_ID, ...global.webSearch, ...project.webSearch },
84
+ webFetch: { provider: DEFAULT_PROVIDER_ID, ...global.webFetch, ...project.webFetch },
88
85
  webImage: { ...global.webImage, ...project.webImage },
89
86
  webApiKeys: { ...global.webApiKeys, ...project.webApiKeys }
90
87
  }
@@ -24,8 +24,8 @@ export interface Provider {
24
24
  }
25
25
 
26
26
  export interface WebToolsConfig {
27
- webSearch?: { provider?: string; enabled?: boolean }
28
- webFetch?: { provider?: string; enabled?: boolean }
27
+ webSearch?: { provider?: string | null }
28
+ webFetch?: { provider?: string | null }
29
29
  webImage?: { enabled?: boolean; resize?: boolean; maxSize?: number }
30
30
  webApiKeys?: Record<string, string>
31
31
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xl0/pi-lovely-web",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "keywords": [
5
5
  "pi-package",
6
6
  "firecrawl",
@@ -49,6 +49,7 @@
49
49
  "pi": {
50
50
  "extensions": [
51
51
  "./extensions"
52
- ]
52
+ ],
53
+ "image": "https://raw.githubusercontent.com/xl0/pi-lovely-web/master/assets/web_image.png"
53
54
  }
54
55
  }