@chat-js/registry 0.1.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 +9 -0
- package/index.d.ts +4 -0
- package/index.js +1 -0
- package/index.json +18 -0
- package/items/get-weather.json +26 -0
- package/items/retrieve-url.json +35 -0
- package/items/toolkit-renderer.json +28 -0
- package/items/word-count.json +22 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# @chat-js/registry
|
|
2
|
+
|
|
3
|
+
Published ChatJS registry artifacts and authoring types.
|
|
4
|
+
|
|
5
|
+
This package contains:
|
|
6
|
+
|
|
7
|
+
- `index.json` with the registry index
|
|
8
|
+
- `items/*.json` with generated registry tool manifests
|
|
9
|
+
- `ToolEnvVars` for typing static `toolEnvVars` exports in `tool.ts`
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/index.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"name": "word-count",
|
|
4
|
+
"description": "Count words, characters, and sentences in text"
|
|
5
|
+
},
|
|
6
|
+
{
|
|
7
|
+
"name": "retrieve-url",
|
|
8
|
+
"description": "Fetch structured information from a single URL"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"name": "get-weather",
|
|
12
|
+
"description": "Get the current weather at a location"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"name": "toolkit-renderer",
|
|
16
|
+
"description": "Shared renderer helpers for installable ChatJS tools"
|
|
17
|
+
}
|
|
18
|
+
]
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "get-weather",
|
|
3
|
+
"description": "Get the current weather at a location",
|
|
4
|
+
"dependencies": [
|
|
5
|
+
"ai",
|
|
6
|
+
"date-fns",
|
|
7
|
+
"zod"
|
|
8
|
+
],
|
|
9
|
+
"registryDependencies": [
|
|
10
|
+
"toolkit-renderer"
|
|
11
|
+
],
|
|
12
|
+
"files": [
|
|
13
|
+
{
|
|
14
|
+
"path": "tool.ts",
|
|
15
|
+
"type": "tool",
|
|
16
|
+
"target": "get-weather/tool.ts",
|
|
17
|
+
"content": "import { tool } from \"ai\";\nimport { z } from \"zod\";\n\nexport const getWeather = tool({\n description: \"Get the current weather at a location\",\n inputSchema: z.object({\n latitude: z.number(),\n longitude: z.number(),\n }),\n execute: async ({\n latitude,\n longitude,\n }: {\n latitude: number;\n longitude: number;\n }) => {\n const response = await fetch(\n `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}¤t=temperature_2m&hourly=temperature_2m&daily=sunrise,sunset&timezone=auto`\n );\n\n const weatherData = await response.json();\n return weatherData as WeatherAtLocation;\n },\n});\n\nexport interface WeatherAtLocation {\n current: {\n time: string;\n interval: number;\n temperature_2m: number;\n };\n current_units: {\n time: string;\n interval: string;\n temperature_2m: string;\n };\n daily: {\n time: string[];\n sunrise: string[];\n sunset: string[];\n };\n daily_units: {\n time: string;\n sunrise: string;\n sunset: string;\n };\n elevation: number;\n generationtime_ms: number;\n hourly: {\n time: string[];\n temperature_2m: number[];\n };\n hourly_units: {\n time: string;\n temperature_2m: string;\n };\n latitude: number;\n longitude: number;\n timezone: string;\n timezone_abbreviation: string;\n utc_offset_seconds: number;\n}\n"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"path": "renderer.tsx",
|
|
21
|
+
"type": "renderer",
|
|
22
|
+
"target": "get-weather/renderer.tsx",
|
|
23
|
+
"content": "\"use client\";\n\nimport { format, isWithinInterval } from \"date-fns\";\nimport { cx } from \"@toolkit/lib/cx\";\nimport type { TypelessToolPartFromTool } from \"@toolkit/lib/tool-part\";\nimport { useToolIsCompact } from \"@toolkit/hooks/use-tool-is-compact\";\nimport { getWeather, type WeatherAtLocation } from \"./tool\";\n\ntype GetWeatherRendererTool = TypelessToolPartFromTool<\n typeof getWeather\n>;\n\nconst SAMPLE = {\n latitude: 37.763_283,\n longitude: -122.412_86,\n generationtime_ms: 0.027_894_973_754_882_812,\n utc_offset_seconds: 0,\n timezone: \"GMT\",\n timezone_abbreviation: \"GMT\",\n elevation: 18,\n current_units: { time: \"iso8601\", interval: \"seconds\", temperature_2m: \"°C\" },\n current: { time: \"2024-10-07T19:30\", interval: 900, temperature_2m: 29.3 },\n hourly_units: { time: \"iso8601\", temperature_2m: \"°C\" },\n hourly: {\n time: [\n \"2024-10-07T19:00\",\n \"2024-10-07T20:00\",\n \"2024-10-07T21:00\",\n \"2024-10-07T22:00\",\n \"2024-10-07T23:00\",\n \"2024-10-08T00:00\",\n \"2024-10-08T01:00\",\n ],\n temperature_2m: [\n 33.9, 32.1, 28.9, 26.9, 25.2, 23, 21.1,\n ],\n },\n daily_units: {\n time: \"iso8601\",\n sunrise: \"iso8601\",\n sunset: \"iso8601\",\n },\n daily: {\n time: [\"2024-10-07\"],\n sunrise: [\"2024-10-07T07:15\"],\n sunset: [\"2024-10-07T19:00\"],\n },\n};\n\nfunction n(num: number): number {\n return Math.ceil(num);\n}\n\nfunction WeatherCard({\n weatherAtLocation,\n}: {\n weatherAtLocation: WeatherAtLocation;\n}) {\n const currentHigh = Math.max(\n ...weatherAtLocation.hourly.temperature_2m.slice(0, 24)\n );\n const currentLow = Math.min(\n ...weatherAtLocation.hourly.temperature_2m.slice(0, 24)\n );\n\n const isDay = isWithinInterval(new Date(weatherAtLocation.current.time), {\n start: new Date(weatherAtLocation.daily.sunrise[0]),\n end: new Date(weatherAtLocation.daily.sunset[0]),\n });\n\n const isCompact = useToolIsCompact();\n const hoursToShow = isCompact ? 5 : 6;\n const currentTimeIndex = weatherAtLocation.hourly.time.findIndex(\n (time) => new Date(time) >= new Date(weatherAtLocation.current.time)\n );\n const startIndex =\n currentTimeIndex >= 0\n ? currentTimeIndex\n : Math.max(0, weatherAtLocation.hourly.time.length - hoursToShow);\n const displayTimes = weatherAtLocation.hourly.time.slice(\n startIndex,\n startIndex + hoursToShow\n );\n const displayTemperatures = weatherAtLocation.hourly.temperature_2m.slice(\n startIndex,\n startIndex + hoursToShow\n );\n\n return (\n <div\n className={cx(\n \"skeleton-bg flex max-w-[500px] flex-col gap-4 rounded-2xl p-4\",\n isDay && \"bg-blue-400\",\n !isDay && \"bg-indigo-900\"\n )}\n >\n <div className=\"flex flex-row items-center justify-between\">\n <div className=\"flex flex-row items-center gap-2\">\n <div\n className={cx(\n \"skeleton-div size-10 rounded-full\",\n isDay && \"bg-yellow-300\",\n !isDay && \"bg-indigo-100\"\n )}\n />\n <div className=\"font-medium text-4xl text-blue-50\">\n {n(weatherAtLocation.current.temperature_2m)}\n {weatherAtLocation.current_units.temperature_2m}\n </div>\n </div>\n\n <div className=\"text-blue-50\">{`H:${n(currentHigh)}° L:${n(currentLow)}°`}</div>\n </div>\n\n <div className=\"flex flex-row justify-between\">\n {displayTimes.map((time, index) => (\n <div className=\"flex flex-col items-center gap-1\" key={time}>\n <div className=\"text-blue-100 text-xs\">\n {format(new Date(time), \"ha\")}\n </div>\n <div\n className={cx(\n \"skeleton-div size-6 rounded-full\",\n isDay && \"bg-yellow-300\",\n !isDay && \"bg-indigo-200\"\n )}\n />\n <div className=\"text-blue-50 text-sm\">\n {n(displayTemperatures[index])}\n {weatherAtLocation.hourly_units.temperature_2m}\n </div>\n </div>\n ))}\n </div>\n </div>\n );\n}\n\nexport function GetWeatherRenderer({\n tool,\n}: {\n tool: GetWeatherRendererTool;\n messageId: string;\n isReadonly: boolean;\n}) {\n if (tool.state !== \"output-available\") {\n return (\n <div className=\"skeleton\" key={tool.toolCallId}>\n <WeatherCard weatherAtLocation={SAMPLE} />\n </div>\n );\n }\n\n if (!tool.output) {\n return <WeatherCard weatherAtLocation={SAMPLE} />;\n }\n\n return <WeatherCard weatherAtLocation={tool.output} />;\n}\n"
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "retrieve-url",
|
|
3
|
+
"description": "Fetch structured information from a single URL",
|
|
4
|
+
"dependencies": [
|
|
5
|
+
"@mendable/firecrawl-js",
|
|
6
|
+
"ai",
|
|
7
|
+
"lucide-react",
|
|
8
|
+
"react-markdown",
|
|
9
|
+
"zod"
|
|
10
|
+
],
|
|
11
|
+
"envRequirements": [
|
|
12
|
+
{
|
|
13
|
+
"description": "FIRECRAWL_API_KEY",
|
|
14
|
+
"options": [
|
|
15
|
+
[
|
|
16
|
+
"FIRECRAWL_API_KEY"
|
|
17
|
+
]
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"files": [
|
|
22
|
+
{
|
|
23
|
+
"path": "tool.ts",
|
|
24
|
+
"type": "tool",
|
|
25
|
+
"target": "retrieve-url/tool.ts",
|
|
26
|
+
"content": "import FirecrawlApp from \"@mendable/firecrawl-js\";\nimport { tool } from \"ai\";\nimport { z } from \"zod\";\nimport { env } from \"@/lib/env\";\nimport { createModuleLogger } from \"@/lib/logger\";\n\ntype ToolEnvVars = {\n description?: string;\n options: string[][];\n}[];\n\nexport const toolEnvVars: ToolEnvVars = [\n {\n description: \"FIRECRAWL_API_KEY\",\n options: [[\"FIRECRAWL_API_KEY\"]],\n },\n];\n\nconst log = createModuleLogger(\"tools/retrieve-url\");\n\nconst app = env.FIRECRAWL_API_KEY\n ? new FirecrawlApp({ apiKey: env.FIRECRAWL_API_KEY })\n : null;\n\nfunction parseUrl(url: string): URL | null {\n try {\n const parsed = new URL(url);\n if (parsed.protocol !== \"http:\" && parsed.protocol !== \"https:\") {\n return null;\n }\n return parsed;\n } catch {\n return null;\n }\n}\n\nfunction redactUrl(url: URL): string {\n return `${url.origin}${url.pathname}`;\n}\n\nexport const retrieveUrl = tool({\n description: `Fetch structured information from a single URL via Firecrawl.\n\nUse for:\n- Extract content from a specific URL supplied by the user\n\nAvoid:\n- General-purpose web searches`,\n inputSchema: z.object({\n url: z.string().describe(\"The URL to retrieve the information from.\"),\n }),\n execute: async ({ url }: { url: string }) => {\n try {\n if (!app) {\n return {\n error:\n \"Firecrawl is not configured. Set FIRECRAWL_API_KEY to enable retrieval.\",\n };\n }\n const parsedUrl = parseUrl(url);\n if (!parsedUrl) {\n return {\n error: \"Please provide a valid http:// or https:// URL.\",\n };\n }\n\n const redactedUrl = redactUrl(parsedUrl);\n const normalizedUrl = parsedUrl.toString();\n const content = await app.scrapeUrl(normalizedUrl);\n if (!(content.success && content.metadata)) {\n return {\n results: [\n {\n error: content.error,\n },\n ],\n };\n }\n\n const schema = z.object({\n title: z.string(),\n content: z.string(),\n description: z.string(),\n });\n\n let title = content.metadata.title;\n let description = content.metadata.description;\n let extractedContent = content.markdown;\n\n if (!(title && description && extractedContent)) {\n const extractResult = await app.extract([normalizedUrl], {\n prompt:\n \"Extract the page title, main content, and a brief description.\",\n schema,\n });\n\n if (extractResult.success && extractResult.data) {\n title = title || extractResult.data.title;\n description = description || extractResult.data.description;\n extractedContent = extractedContent || extractResult.data.content;\n }\n }\n\n return {\n results: [\n {\n title: title || \"Untitled\",\n content: extractedContent || \"\",\n url: redactedUrl,\n description: description || \"\",\n language: content.metadata.language,\n },\n ],\n };\n } catch (error) {\n const parsedUrl = parseUrl(url);\n log.error(\n { err: error, url: parsedUrl ? redactUrl(parsedUrl) : \"<invalid-url>\" },\n \"Firecrawl API error in retrieveUrl tool\"\n );\n return { error: \"Failed to retrieve content\" };\n }\n },\n});\n"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"path": "renderer.tsx",
|
|
30
|
+
"type": "renderer",
|
|
31
|
+
"target": "retrieve-url/renderer.tsx",
|
|
32
|
+
"content": "\"use client\";\n\nimport { ChevronDown, ExternalLink, Globe, TextIcon } from \"lucide-react\";\nimport ReactMarkdown from \"react-markdown\";\nimport type { TypelessToolPartFromTool } from \"@/tools/chatjs/_shared/lib/tool-part\";\nimport type { retrieveUrl } from \"./tool\";\n\ntype RetrieveUrlRendererTool = TypelessToolPartFromTool<typeof retrieveUrl>;\n\nfunction LoadingState() {\n return (\n <div className=\"my-4 rounded-xl border border-border bg-card p-4\">\n <div className=\"flex items-center gap-4\">\n <div className=\"relative h-10 w-10\">\n <div className=\"absolute inset-0 animate-pulse rounded-full bg-primary/10\" />\n <Globe className=\"absolute inset-0 m-auto h-5 w-5 text-primary/70\" />\n </div>\n <div className=\"flex-1 space-y-2\">\n <div className=\"h-4 w-36 animate-pulse rounded-md bg-muted-foreground/20\" />\n <div className=\"space-y-1.5\">\n <div className=\"h-3 w-full animate-pulse rounded-md bg-muted-foreground/15\" />\n <div className=\"h-3 w-2/3 animate-pulse rounded-md bg-muted-foreground/15\" />\n </div>\n </div>\n </div>\n </div>\n );\n}\n\nfunction ErrorState({ errorMessage }: { errorMessage: string | undefined }) {\n return (\n <div className=\"my-4 rounded-xl border border-red-200 bg-red-50 p-4 dark:border-red-500 dark:bg-red-950/50\">\n <div className=\"flex items-center gap-3\">\n <div className=\"flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-red-100 dark:bg-red-900/50\">\n <Globe className=\"h-4 w-4 text-red-600 dark:text-red-300\" />\n </div>\n <div>\n <div className=\"font-medium text-red-700 text-sm dark:text-red-300\">\n Error retrieving content\n </div>\n <div className=\"mt-1 text-red-600/80 text-xs dark:text-red-400/80\">\n {errorMessage}\n </div>\n </div>\n </div>\n </div>\n );\n}\n\nfunction getItemProperty<T>(\n item: unknown,\n property: string,\n defaultValue: T\n): T {\n if (item && typeof item === \"object\" && property in item) {\n const value = (item as Record<string, unknown>)[property];\n return (value as T) ?? defaultValue;\n }\n return defaultValue;\n}\n\nfunction RetrievedContentHeader({ firstItem }: { firstItem: unknown }) {\n const url = getItemProperty(firstItem, \"url\", \"\");\n const title = getItemProperty(firstItem, \"title\", \"Retrieved Content\");\n const description = getItemProperty(\n firstItem,\n \"description\",\n \"No description available\"\n );\n const language = getItemProperty(firstItem, \"language\", \"Unknown\");\n\n return (\n <div className=\"p-4\">\n <div className=\"flex items-start gap-4\">\n <div className=\"relative h-10 w-10 shrink-0\">\n <div className=\"absolute inset-0 rounded-lg bg-linear-to-br from-primary/10 to-transparent\" />\n <Globe className=\"absolute inset-0 m-auto h-5 w-5 text-primary/70\" />\n </div>\n <div className=\"min-w-0 flex-1 space-y-2\">\n <h2 className=\"truncate font-semibold text-foreground text-lg tracking-tight\">\n {title}\n </h2>\n <p className=\"line-clamp-2 text-muted-foreground text-sm\">\n {description}\n </p>\n <div className=\"flex items-center gap-3\">\n <span className=\"rounded-full bg-primary/10 px-2.5 py-0.5 font-medium text-primary text-xs\">\n {language}\n </span>\n <a\n className=\"inline-flex items-center gap-1.5 text-muted-foreground text-xs transition-colors hover:text-primary\"\n href={url || \"#\"}\n rel=\"noopener noreferrer\"\n target=\"_blank\"\n >\n <ExternalLink className=\"h-3 w-3\" />\n View source\n </a>\n </div>\n </div>\n </div>\n </div>\n );\n}\n\nfunction RetrievedContentDetails({ firstItem }: { firstItem: unknown }) {\n const content = getItemProperty(firstItem, \"content\", \"No content available\");\n\n return (\n <div className=\"border-border border-t\">\n <details className=\"group\">\n <summary className=\"flex w-full cursor-pointer items-center justify-between px-4 py-2 text-muted-foreground text-sm transition-colors hover:bg-muted\">\n <div className=\"flex items-center gap-2\">\n <TextIcon className=\"h-4 w-4 text-muted-foreground\" />\n <span>View content</span>\n </div>\n <ChevronDown className=\"h-4 w-4 transition-transform duration-200 group-open:rotate-180\" />\n </summary>\n <div className=\"max-h-[50vh] overflow-y-auto bg-muted/50 p-4\">\n <div className=\"prose prose-neutral dark:prose-invert prose-sm max-w-none\">\n <ReactMarkdown>{content}</ReactMarkdown>\n </div>\n </div>\n </details>\n </div>\n );\n}\n\nfunction getFirstItem(result: unknown): unknown {\n if (\n result &&\n typeof result === \"object\" &&\n \"results\" in result &&\n Array.isArray(result.results)\n ) {\n return result.results[0];\n }\n}\n\nfunction getErrorMessage(result: unknown, firstItem: unknown): string | null {\n const topLevelError =\n result && typeof result === \"object\" && \"error\" in result\n ? (result.error as string)\n : undefined;\n const firstItemError =\n firstItem && typeof firstItem === \"object\" && \"error\" in firstItem\n ? (firstItem.error as string)\n : undefined;\n\n return topLevelError ?? firstItemError ?? null;\n}\n\nexport function RetrieveUrlRenderer({\n tool,\n}: {\n tool: RetrieveUrlRendererTool;\n messageId: string;\n isReadonly: boolean;\n}) {\n if (tool.state === \"input-available\" || tool.state === \"input-streaming\") {\n return <LoadingState />;\n }\n\n if (tool.state !== \"output-available\") {\n return null;\n }\n\n if (!tool.output) {\n return null;\n }\n\n const { output: result } = tool;\n const firstItem = getFirstItem(result);\n const errorMessage = getErrorMessage(result, firstItem);\n\n if (errorMessage) {\n return <ErrorState errorMessage={errorMessage} />;\n }\n\n return (\n <div className=\"my-4 overflow-hidden rounded-xl border border-border bg-card\">\n <RetrievedContentHeader firstItem={firstItem} />\n <RetrievedContentDetails firstItem={firstItem} />\n </div>\n );\n}\n"
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "toolkit-renderer",
|
|
3
|
+
"description": "Shared renderer helpers for installable ChatJS tools",
|
|
4
|
+
"dependencies": [
|
|
5
|
+
"ai",
|
|
6
|
+
"react"
|
|
7
|
+
],
|
|
8
|
+
"files": [
|
|
9
|
+
{
|
|
10
|
+
"path": "cx.ts",
|
|
11
|
+
"type": "lib",
|
|
12
|
+
"target": "_shared/lib/cx.ts",
|
|
13
|
+
"content": "export function cx(...parts: Array<string | false | null | undefined>): string {\n return parts.filter(Boolean).join(\" \");\n}\n"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"path": "tool-part.ts",
|
|
17
|
+
"type": "lib",
|
|
18
|
+
"target": "_shared/lib/tool-part.ts",
|
|
19
|
+
"content": "import type { Tool, UIToolInvocation } from \"ai\";\n\nexport type ToolPartFromTool<T extends Tool> = UIToolInvocation<T>;\n\nexport type TypelessToolPartFromTool<T extends Tool> = ToolPartFromTool<T>;\n"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"path": "use-tool-is-compact.ts",
|
|
23
|
+
"type": "hook",
|
|
24
|
+
"target": "_shared/hooks/use-tool-is-compact.ts",
|
|
25
|
+
"content": "\"use client\";\n\nimport { useEffect, useState } from \"react\";\n\nconst COMPACT_BREAKPOINT = 640;\n\nexport function useToolIsCompact(): boolean {\n const [isCompact, setIsCompact] = useState(false);\n\n useEffect(() => {\n const mediaQuery = window.matchMedia(\n `(max-width: ${COMPACT_BREAKPOINT - 1}px)`\n );\n\n const update = () => setIsCompact(mediaQuery.matches);\n update();\n mediaQuery.addEventListener(\"change\", update);\n\n return () => mediaQuery.removeEventListener(\"change\", update);\n }, []);\n\n return isCompact;\n}\n"
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "word-count",
|
|
3
|
+
"description": "Count words, characters, and sentences in text",
|
|
4
|
+
"dependencies": [
|
|
5
|
+
"ai",
|
|
6
|
+
"zod"
|
|
7
|
+
],
|
|
8
|
+
"files": [
|
|
9
|
+
{
|
|
10
|
+
"path": "tool.ts",
|
|
11
|
+
"type": "tool",
|
|
12
|
+
"target": "word-count/tool.ts",
|
|
13
|
+
"content": "import { tool } from \"ai\";\nimport { z } from \"zod\";\n\nconst WORD_SPLIT_REGEX = /\\s+/;\nconst SENTENCE_SPLIT_REGEX = /[.!?]+/;\n\nexport const wordCount = tool({\n description: \"Count the words, characters, and sentences in a given text\",\n inputSchema: z.object({\n text: z.string().describe(\"The text to analyze\"),\n }),\n execute: ({ text }: { text: string }) => {\n const words =\n text.trim() === \"\" ? 0 : text.trim().split(WORD_SPLIT_REGEX).length;\n const characters = text.length;\n const charactersNoSpaces = text.replace(/\\s/g, \"\").length;\n const sentences = text\n .split(SENTENCE_SPLIT_REGEX)\n .filter((s) => s.trim().length > 0).length;\n\n return { words, characters, charactersNoSpaces, sentences };\n },\n});\n\nexport type WordCountOutput = {\n words: number;\n characters: number;\n charactersNoSpaces: number;\n sentences: number;\n};\n"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"path": "renderer.tsx",
|
|
17
|
+
"type": "renderer",
|
|
18
|
+
"target": "word-count/renderer.tsx",
|
|
19
|
+
"content": "\"use client\";\n\nimport type { TypelessToolPartFromTool } from \"@/tools/chatjs/_shared/lib/tool-part\";\nimport type { wordCount } from \"./tool\";\n\ntype WordCountRendererTool = TypelessToolPartFromTool<typeof wordCount>;\n\nexport function WordCountRenderer({\n tool,\n}: {\n tool: WordCountRendererTool;\n messageId: string;\n isReadonly: boolean;\n}) {\n if (tool.state === \"input-available\") {\n return (\n <div className=\"rounded-lg border p-3 text-muted-foreground text-sm\">\n Counting words...\n </div>\n );\n }\n\n if (tool.state !== \"output-available\") {\n return null;\n }\n\n if (!tool.output) {\n return null;\n }\n\n const { words, characters, charactersNoSpaces, sentences } = tool.output;\n\n return (\n <div className=\"grid grid-cols-2 gap-2 rounded-lg border p-3 text-sm sm:grid-cols-4\">\n <Stat label=\"Words\" value={words} />\n <Stat label=\"Characters\" value={characters} />\n <Stat label=\"No spaces\" value={charactersNoSpaces} />\n <Stat label=\"Sentences\" value={sentences} />\n </div>\n );\n}\n\nfunction Stat({ label, value }: { label: string; value: number }) {\n return (\n <div className=\"flex flex-col items-center gap-1\">\n <span className=\"font-semibold text-lg\">{value}</span>\n <span className=\"text-muted-foreground text-xs\">{label}</span>\n </div>\n );\n}\n"
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@chat-js/registry",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "ChatJS tool registry items",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/franciscomoretti/chat-js.git",
|
|
9
|
+
"directory": "packages/registry"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/franciscomoretti/chat-js/tree/main/packages/registry",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/franciscomoretti/chat-js/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"chatjs",
|
|
17
|
+
"ai",
|
|
18
|
+
"registry",
|
|
19
|
+
"tools"
|
|
20
|
+
],
|
|
21
|
+
"private": false,
|
|
22
|
+
"type": "module",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./index.d.ts",
|
|
26
|
+
"default": "./index.js"
|
|
27
|
+
},
|
|
28
|
+
"./index.json": "./index.json",
|
|
29
|
+
"./items/*": "./items/*.json"
|
|
30
|
+
},
|
|
31
|
+
"types": "./index.d.ts",
|
|
32
|
+
"files": [
|
|
33
|
+
"index.d.ts",
|
|
34
|
+
"index.js",
|
|
35
|
+
"index.json",
|
|
36
|
+
"items"
|
|
37
|
+
],
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "bun build.ts",
|
|
43
|
+
"prepublishOnly": "bun run build"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"ts-morph": "^27.0.2"
|
|
47
|
+
}
|
|
48
|
+
}
|