@preply/ds-ai-cli 11.1.0

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.
@@ -0,0 +1,3 @@
1
+ import { Tool } from '@preply/ds-ai-core';
2
+ export declare function createCommand(name: string, tool: Tool<any, any>): import('commander').Command;
3
+ //# sourceMappingURL=create-command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-command.d.ts","sourceRoot":"","sources":["../src/create-command.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,EAAiB,MAAM,oBAAoB,CAAC;AAG9D,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,+BAoB/D"}
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@preply/ds-ai-cli",
3
+ "description": "CLI for querying the Preply Design System",
4
+ "version": "11.1.0",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "type": "module",
9
+ "bin": {
10
+ "ds-ai": "./dist/bin.js"
11
+ },
12
+ "scripts": {
13
+ "clean": "rm -rf dist",
14
+ "check:types": "run --top-level tsc --noEmit",
15
+ "lint": "run --top-level eslint .",
16
+ "build": "vite build",
17
+ "dev": "vite build --watch"
18
+ },
19
+ "devDependencies": {
20
+ "@types/node": "^24.12.0",
21
+ "vite": "^8.0.0",
22
+ "vite-plugin-dts": "^4.5.4"
23
+ },
24
+ "dependencies": {
25
+ "@preply/ds-ai-core": "11.1.0",
26
+ "commander": "^14.0.0",
27
+ "zod": "^4.3.6",
28
+ "zod-commander": "^0.1.0",
29
+ "zod-opts": "^1.0.0"
30
+ },
31
+ "gitHead": "a5330f56c6c03a557b29efefcabacb41d67f4b63"
32
+ }
@@ -0,0 +1,66 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+ import { Command } from 'commander';
3
+ import * as z from 'zod';
4
+ import { createCommand } from '../create-command';
5
+
6
+ vi.mock(import('@preply/ds-ai-core'), async importOriginal => {
7
+ const actual = await importOriginal();
8
+ return {
9
+ ...actual,
10
+ identify: vi.fn(),
11
+ trackToolCall: vi.fn(),
12
+ };
13
+ });
14
+
15
+ function makeTool(overrides = {}) {
16
+ return {
17
+ name: 'test_tool',
18
+ description: 'A test tool',
19
+ arguments: z.object({ name: z.string() }),
20
+ callback: vi.fn(() => ['result line 1', 'result line 2']),
21
+ ...overrides,
22
+ };
23
+ }
24
+
25
+ describe('createCommand', () => {
26
+ it('creates a Commander command with correct name and description', () => {
27
+ const tool = makeTool();
28
+ const cmd = createCommand('my-cmd', tool);
29
+
30
+ expect(cmd).toBeInstanceOf(Command);
31
+ expect(cmd.name()).toBe('my-cmd');
32
+ expect(cmd.description()).toBe('A test tool');
33
+ });
34
+
35
+ it('invokes tool callback when action runs', async () => {
36
+ const tool = makeTool();
37
+ const cmd = createCommand('run', tool);
38
+
39
+ const parent = new Command();
40
+ parent.addCommand(cmd);
41
+ parent.exitOverride();
42
+
43
+ await parent.parseAsync(['node', 'test', 'run', 'search-query']);
44
+
45
+ expect(tool.callback).toHaveBeenCalled();
46
+ });
47
+
48
+ it('sets exitCode to 1 when tool callback throws', async () => {
49
+ const tool = makeTool({
50
+ callback: vi.fn(() => {
51
+ throw new Error('boom');
52
+ }),
53
+ });
54
+ const cmd = createCommand('fail', tool);
55
+
56
+ const parent = new Command();
57
+ parent.addCommand(cmd);
58
+ parent.exitOverride();
59
+
60
+ const originalExitCode = process.exitCode;
61
+ await parent.parseAsync(['node', 'test', 'fail', 'arg']);
62
+
63
+ expect(process.exitCode).toBe(1);
64
+ process.exitCode = originalExitCode;
65
+ });
66
+ });
package/src/bin.ts ADDED
@@ -0,0 +1,34 @@
1
+ import { program } from 'commander';
2
+ import pkg from '../package.json' with { type: 'json' };
3
+ import { tools, shutdownEventTracking, identify } from '@preply/ds-ai-core';
4
+ import { createCommand } from './create-command';
5
+
6
+ identify();
7
+
8
+ // prettier-ignore
9
+ program
10
+ .name(Object.keys(pkg.bin)[0])
11
+ .description(pkg.description)
12
+ .version(pkg.version, '-v, --version', 'Output the version number')
13
+ .usage('<command> [options]');
14
+
15
+ program
16
+ .command('components')
17
+ .description('Query documentation for components')
18
+ .addCommand(createCommand('list', tools.listComponents))
19
+ .addCommand(createCommand('docs', tools.getComponentDocs));
20
+
21
+ program
22
+ .command('icons')
23
+ .description('Search for icons')
24
+ .addCommand(createCommand('search', tools.searchIcon));
25
+
26
+ program
27
+ .command('tokens')
28
+ .description('Search for tokens')
29
+ .addCommand(createCommand('search-by-name', tools.searchTokenByName))
30
+ .addCommand(createCommand('search-by-value', tools.searchTokenByValue));
31
+
32
+ program.parse();
33
+
34
+ await shutdownEventTracking();
@@ -0,0 +1,25 @@
1
+ import { zodCommand } from 'zod-commander';
2
+ import { type Tool, trackToolCall } from '@preply/ds-ai-core';
3
+
4
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
+ export function createCommand(name: string, tool: Tool<any, any>) {
6
+ return zodCommand({
7
+ name,
8
+ description: tool.description,
9
+ args: tool.arguments?.shape,
10
+ opts: tool.options?.shape,
11
+ action: (args, opts) => {
12
+ try {
13
+ const toolArgs = {
14
+ ...tool.arguments?.parse(args),
15
+ ...tool.options?.parse(opts),
16
+ };
17
+ tool.callback(toolArgs).forEach(text => console.log('\n', text));
18
+ trackToolCall(tool.name, toolArgs, { invocationMethod: 'cli' });
19
+ } catch (error) {
20
+ console.error('An error occurred while executing the command', error);
21
+ process.exitCode = 1;
22
+ }
23
+ },
24
+ });
25
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "include": ["src", "package.json", "vite.config.ts"],
4
+ "exclude": ["node_modules", "dist"],
5
+ "compilerOptions": {
6
+ "resolveJsonModule": true,
7
+ "module": "esnext",
8
+ "target": "esnext",
9
+ "types": ["vitest/globals", "node"]
10
+ }
11
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,20 @@
1
+ import { defineConfig } from 'vite';
2
+ import dts from 'vite-plugin-dts';
3
+
4
+ export default defineConfig({
5
+ plugins: [dts({ exclude: ['vite.config.ts'], entryRoot: 'src' })],
6
+ build: {
7
+ target: 'esnext',
8
+ ssr: true,
9
+ lib: {
10
+ entry: 'src/bin.ts',
11
+ formats: ['es'],
12
+ },
13
+ rolldownOptions: {
14
+ output: {
15
+ entryFileNames: '[name].js',
16
+ banner: '#!/usr/bin/env node',
17
+ },
18
+ },
19
+ },
20
+ });