@projectservan8n/cnapse 0.2.0 → 0.4.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,174 @@
1
+ import {
2
+ setApiKey,
3
+ setModel,
4
+ setProvider
5
+ } from "./chunk-COKO6V5J.js";
6
+
7
+ // src/components/Setup.tsx
8
+ import { useState } from "react";
9
+ import { Box, Text, useInput, useApp } from "ink";
10
+ import TextInput from "ink-text-input";
11
+ import { jsx, jsxs } from "react/jsx-runtime";
12
+ var PROVIDERS = [
13
+ { id: "ollama", name: "Ollama", desc: "Local AI (free, no API key needed)" },
14
+ { id: "openrouter", name: "OpenRouter", desc: "Many models, pay per use" },
15
+ { id: "anthropic", name: "Anthropic", desc: "Claude models" },
16
+ { id: "openai", name: "OpenAI", desc: "GPT models" }
17
+ ];
18
+ var DEFAULT_MODELS = {
19
+ ollama: ["qwen2.5:0.5b", "qwen2.5:7b", "llama3.2:3b", "codellama:7b"],
20
+ openrouter: [
21
+ "qwen/qwen-2.5-coder-32b-instruct",
22
+ "anthropic/claude-3.5-sonnet",
23
+ "openai/gpt-4o",
24
+ "google/gemini-pro-1.5"
25
+ ],
26
+ anthropic: [
27
+ "claude-3-5-sonnet-20241022",
28
+ "claude-3-opus-20240229",
29
+ "claude-3-haiku-20240307"
30
+ ],
31
+ openai: ["gpt-4o", "gpt-4o-mini", "gpt-4-turbo", "gpt-3.5-turbo"]
32
+ };
33
+ function Setup() {
34
+ const { exit } = useApp();
35
+ const [step, setStep] = useState("provider");
36
+ const [selectedProvider, setSelectedProvider] = useState(0);
37
+ const [selectedModel, setSelectedModel] = useState(0);
38
+ const [apiKey, setApiKeyInput] = useState("");
39
+ const [provider, setProviderState] = useState("ollama");
40
+ useInput((input, key) => {
41
+ if (key.escape) {
42
+ exit();
43
+ return;
44
+ }
45
+ if (step === "provider") {
46
+ if (key.upArrow) {
47
+ setSelectedProvider((prev) => prev > 0 ? prev - 1 : PROVIDERS.length - 1);
48
+ } else if (key.downArrow) {
49
+ setSelectedProvider((prev) => prev < PROVIDERS.length - 1 ? prev + 1 : 0);
50
+ } else if (key.return) {
51
+ const selected = PROVIDERS[selectedProvider];
52
+ setProviderState(selected.id);
53
+ setProvider(selected.id);
54
+ if (selected.id === "ollama") {
55
+ setStep("model");
56
+ } else {
57
+ setStep("apiKey");
58
+ }
59
+ }
60
+ } else if (step === "model") {
61
+ const models = DEFAULT_MODELS[provider] || [];
62
+ if (key.upArrow) {
63
+ setSelectedModel((prev) => prev > 0 ? prev - 1 : models.length - 1);
64
+ } else if (key.downArrow) {
65
+ setSelectedModel((prev) => prev < models.length - 1 ? prev + 1 : 0);
66
+ } else if (key.return) {
67
+ const model = models[selectedModel];
68
+ setModel(model);
69
+ setStep("done");
70
+ setTimeout(() => exit(), 1500);
71
+ }
72
+ }
73
+ });
74
+ const handleApiKeySubmit = (value) => {
75
+ if (value.trim()) {
76
+ setApiKey(provider, value.trim());
77
+ setApiKeyInput(value);
78
+ setStep("model");
79
+ }
80
+ };
81
+ return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", padding: 1, children: [
82
+ /* @__PURE__ */ jsx(Box, { marginBottom: 1, children: /* @__PURE__ */ jsx(Text, { bold: true, color: "cyan", children: "\u{1F680} C-napse Setup" }) }),
83
+ step === "provider" && /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [
84
+ /* @__PURE__ */ jsx(Text, { bold: true, children: "Select AI Provider:" }),
85
+ /* @__PURE__ */ jsx(Text, { color: "gray", dimColor: true, children: "(Use \u2191\u2193 arrows, Enter to select)" }),
86
+ /* @__PURE__ */ jsx(Box, { marginTop: 1, flexDirection: "column", children: PROVIDERS.map((p, i) => /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsxs(Text, { color: i === selectedProvider ? "cyan" : "white", children: [
87
+ i === selectedProvider ? "\u276F " : " ",
88
+ /* @__PURE__ */ jsx(Text, { bold: i === selectedProvider, children: p.name }),
89
+ /* @__PURE__ */ jsxs(Text, { color: "gray", children: [
90
+ " - ",
91
+ p.desc
92
+ ] })
93
+ ] }) }, p.id)) })
94
+ ] }),
95
+ step === "apiKey" && /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [
96
+ /* @__PURE__ */ jsxs(Text, { children: [
97
+ /* @__PURE__ */ jsx(Text, { color: "green", children: "\u2713" }),
98
+ " Provider: ",
99
+ /* @__PURE__ */ jsx(Text, { bold: true, children: provider })
100
+ ] }),
101
+ /* @__PURE__ */ jsxs(Box, { marginTop: 1, flexDirection: "column", children: [
102
+ /* @__PURE__ */ jsxs(Text, { bold: true, children: [
103
+ "Enter your ",
104
+ provider,
105
+ " API key:"
106
+ ] }),
107
+ /* @__PURE__ */ jsx(Text, { color: "gray", dimColor: true, children: "(Paste with Ctrl+V or right-click, then Enter)" }),
108
+ /* @__PURE__ */ jsxs(Box, { marginTop: 1, children: [
109
+ /* @__PURE__ */ jsx(Text, { color: "cyan", children: "\u276F " }),
110
+ /* @__PURE__ */ jsx(
111
+ TextInput,
112
+ {
113
+ value: apiKey,
114
+ onChange: setApiKeyInput,
115
+ onSubmit: handleApiKeySubmit,
116
+ mask: "*"
117
+ }
118
+ )
119
+ ] })
120
+ ] })
121
+ ] }),
122
+ step === "model" && /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [
123
+ /* @__PURE__ */ jsxs(Text, { children: [
124
+ /* @__PURE__ */ jsx(Text, { color: "green", children: "\u2713" }),
125
+ " Provider: ",
126
+ /* @__PURE__ */ jsx(Text, { bold: true, children: provider })
127
+ ] }),
128
+ provider !== "ollama" && /* @__PURE__ */ jsxs(Text, { children: [
129
+ /* @__PURE__ */ jsx(Text, { color: "green", children: "\u2713" }),
130
+ " API Key: ",
131
+ /* @__PURE__ */ jsx(Text, { bold: true, children: "saved" })
132
+ ] }),
133
+ /* @__PURE__ */ jsxs(Box, { marginTop: 1, flexDirection: "column", children: [
134
+ /* @__PURE__ */ jsx(Text, { bold: true, children: "Select Model:" }),
135
+ /* @__PURE__ */ jsx(Text, { color: "gray", dimColor: true, children: "(Use \u2191\u2193 arrows, Enter to select)" }),
136
+ /* @__PURE__ */ jsx(Box, { marginTop: 1, flexDirection: "column", children: (DEFAULT_MODELS[provider] || []).map((model, i) => /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsxs(Text, { color: i === selectedModel ? "cyan" : "white", children: [
137
+ i === selectedModel ? "\u276F " : " ",
138
+ /* @__PURE__ */ jsx(Text, { bold: i === selectedModel, children: model })
139
+ ] }) }, model)) })
140
+ ] })
141
+ ] }),
142
+ step === "done" && /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [
143
+ /* @__PURE__ */ jsxs(Text, { children: [
144
+ /* @__PURE__ */ jsx(Text, { color: "green", children: "\u2713" }),
145
+ " Provider: ",
146
+ /* @__PURE__ */ jsx(Text, { bold: true, children: provider })
147
+ ] }),
148
+ provider !== "ollama" && /* @__PURE__ */ jsxs(Text, { children: [
149
+ /* @__PURE__ */ jsx(Text, { color: "green", children: "\u2713" }),
150
+ " API Key: ",
151
+ /* @__PURE__ */ jsx(Text, { bold: true, children: "saved" })
152
+ ] }),
153
+ /* @__PURE__ */ jsxs(Text, { children: [
154
+ /* @__PURE__ */ jsx(Text, { color: "green", children: "\u2713" }),
155
+ " Model:",
156
+ " ",
157
+ /* @__PURE__ */ jsx(Text, { bold: true, children: DEFAULT_MODELS[provider]?.[selectedModel] })
158
+ ] }),
159
+ /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsx(Text, { color: "green", bold: true, children: "\u2705 Setup complete! Run `cnapse` to start chatting." }) }),
160
+ provider === "ollama" && /* @__PURE__ */ jsxs(Box, { marginTop: 1, flexDirection: "column", children: [
161
+ /* @__PURE__ */ jsx(Text, { color: "yellow", children: "Note: Make sure the model is downloaded. Run:" }),
162
+ /* @__PURE__ */ jsxs(Text, { color: "cyan", children: [
163
+ " ",
164
+ "ollama pull ",
165
+ DEFAULT_MODELS[provider]?.[selectedModel]
166
+ ] })
167
+ ] })
168
+ ] }),
169
+ /* @__PURE__ */ jsx(Box, { marginTop: 2, children: /* @__PURE__ */ jsx(Text, { color: "gray", dimColor: true, children: "Press Esc to cancel" }) })
170
+ ] });
171
+ }
172
+ export {
173
+ Setup
174
+ };
@@ -0,0 +1,50 @@
1
+ // src/lib/config.ts
2
+ import Conf from "conf";
3
+ var config = new Conf({
4
+ projectName: "cnapse",
5
+ defaults: {
6
+ provider: "ollama",
7
+ model: "qwen2.5:0.5b",
8
+ apiKeys: {},
9
+ ollamaHost: "http://localhost:11434",
10
+ openrouter: {
11
+ siteUrl: "https://github.com/projectservan8n/C-napse",
12
+ appName: "C-napse"
13
+ },
14
+ telegram: {
15
+ enabled: false
16
+ }
17
+ }
18
+ });
19
+ function getConfig() {
20
+ return {
21
+ provider: config.get("provider"),
22
+ model: config.get("model"),
23
+ apiKeys: config.get("apiKeys"),
24
+ ollamaHost: config.get("ollamaHost"),
25
+ openrouter: config.get("openrouter"),
26
+ telegram: config.get("telegram")
27
+ };
28
+ }
29
+ function setProvider(provider) {
30
+ config.set("provider", provider);
31
+ }
32
+ function setModel(model) {
33
+ config.set("model", model);
34
+ }
35
+ function setApiKey(provider, key) {
36
+ const keys = config.get("apiKeys");
37
+ keys[provider] = key;
38
+ config.set("apiKeys", keys);
39
+ }
40
+ function getApiKey(provider) {
41
+ return config.get("apiKeys")[provider];
42
+ }
43
+
44
+ export {
45
+ getConfig,
46
+ setProvider,
47
+ setModel,
48
+ setApiKey,
49
+ getApiKey
50
+ };