notsleep 1.0.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.
- package/.env.example +117 -0
- package/LICENSE +21 -0
- package/README.md +341 -0
- package/dashboard/index.html +893 -0
- package/dist/agent.d.ts +162 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +1064 -0
- package/dist/agent.js.map +1 -0
- package/dist/api.d.ts +10 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +39 -0
- package/dist/api.js.map +1 -0
- package/dist/checkpoint.d.ts +52 -0
- package/dist/checkpoint.d.ts.map +1 -0
- package/dist/checkpoint.js +234 -0
- package/dist/checkpoint.js.map +1 -0
- package/dist/config.d.ts +24 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +265 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +15 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +237 -0
- package/dist/context.js.map +1 -0
- package/dist/cost.d.ts +26 -0
- package/dist/cost.d.ts.map +1 -0
- package/dist/cost.js +161 -0
- package/dist/cost.js.map +1 -0
- package/dist/dashboard.d.ts +96 -0
- package/dist/dashboard.d.ts.map +1 -0
- package/dist/dashboard.js +292 -0
- package/dist/dashboard.js.map +1 -0
- package/dist/fileconfig.d.ts +129 -0
- package/dist/fileconfig.d.ts.map +1 -0
- package/dist/fileconfig.js +391 -0
- package/dist/fileconfig.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +882 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +9 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +221 -0
- package/dist/init.js.map +1 -0
- package/dist/logger.d.ts +33 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +150 -0
- package/dist/logger.js.map +1 -0
- package/dist/modelsdev.d.ts +63 -0
- package/dist/modelsdev.d.ts.map +1 -0
- package/dist/modelsdev.js +265 -0
- package/dist/modelsdev.js.map +1 -0
- package/dist/parallel.d.ts +54 -0
- package/dist/parallel.d.ts.map +1 -0
- package/dist/parallel.js +139 -0
- package/dist/parallel.js.map +1 -0
- package/dist/pool.d.ts +17 -0
- package/dist/pool.d.ts.map +1 -0
- package/dist/pool.js +53 -0
- package/dist/pool.js.map +1 -0
- package/dist/provider.d.ts +60 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +396 -0
- package/dist/provider.js.map +1 -0
- package/dist/registry.d.ts +60 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +153 -0
- package/dist/registry.js.map +1 -0
- package/dist/safety.d.ts +21 -0
- package/dist/safety.d.ts.map +1 -0
- package/dist/safety.js +118 -0
- package/dist/safety.js.map +1 -0
- package/dist/schema.d.ts +9 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +166 -0
- package/dist/schema.js.map +1 -0
- package/dist/test-dashboard.d.ts +5 -0
- package/dist/test-dashboard.d.ts.map +1 -0
- package/dist/test-dashboard.js +202 -0
- package/dist/test-dashboard.js.map +1 -0
- package/dist/tools.d.ts +27 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +1212 -0
- package/dist/tools.js.map +1 -0
- package/dist/types.d.ts +180 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +14 -0
- package/dist/types.js.map +1 -0
- package/dist/worktree.d.ts +50 -0
- package/dist/worktree.d.ts.map +1 -0
- package/dist/worktree.js +186 -0
- package/dist/worktree.js.map +1 -0
- package/package.json +67 -0
package/dist/config.js
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================
|
|
3
|
+
// NotSleep - Configuration Loader
|
|
4
|
+
// ============================================================
|
|
5
|
+
//
|
|
6
|
+
// Priority (highest wins):
|
|
7
|
+
// 1. CLI flags / programmatic overrides
|
|
8
|
+
// 2. Project config file (./notsleep.json)
|
|
9
|
+
// 3. Global config file (~/.notsleep/config.json)
|
|
10
|
+
// 4. Environment / .env
|
|
11
|
+
// 5. Built-in defaults
|
|
12
|
+
// ============================================================
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
+
}) : function(o, v) {
|
|
27
|
+
o["default"] = v;
|
|
28
|
+
});
|
|
29
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
30
|
+
var ownKeys = function(o) {
|
|
31
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
32
|
+
var ar = [];
|
|
33
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
34
|
+
return ar;
|
|
35
|
+
};
|
|
36
|
+
return ownKeys(o);
|
|
37
|
+
};
|
|
38
|
+
return function (mod) {
|
|
39
|
+
if (mod && mod.__esModule) return mod;
|
|
40
|
+
var result = {};
|
|
41
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
42
|
+
__setModuleDefault(result, mod);
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
})();
|
|
46
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
|
+
exports.DEFAULT_SYSTEM_PROMPT = void 0;
|
|
48
|
+
exports.markContextLimitSource = markContextLimitSource;
|
|
49
|
+
exports.getConfigSources = getConfigSources;
|
|
50
|
+
exports.loadConfig = loadConfig;
|
|
51
|
+
const dotenv = __importStar(require("dotenv"));
|
|
52
|
+
const path = __importStar(require("path"));
|
|
53
|
+
const fs = __importStar(require("fs"));
|
|
54
|
+
const fileconfig_1 = require("./fileconfig");
|
|
55
|
+
const cost_1 = require("./cost");
|
|
56
|
+
const registry_1 = require("./registry");
|
|
57
|
+
const modelsdev_1 = require("./modelsdev");
|
|
58
|
+
exports.DEFAULT_SYSTEM_PROMPT = `You are NotSleep, a long-horizon autonomous AI agent. You have been given a task and you must complete it fully before stopping. You have access to tools that let you execute shell commands, read/write files, and search the web.
|
|
59
|
+
|
|
60
|
+
CRITICAL RULES:
|
|
61
|
+
1. NEVER stop until the task is fully complete. If you encounter errors, debug and fix them.
|
|
62
|
+
2. Break large tasks into smaller subtasks and track your progress.
|
|
63
|
+
3. After completing each subtask, report progress and move to the next one.
|
|
64
|
+
4. If you are unsure about something, investigate before acting.
|
|
65
|
+
5. Always verify your work - run tests, check outputs, validate results.
|
|
66
|
+
6. If the context gets too long, you will be asked to summarize your progress. Be thorough in your summary.
|
|
67
|
+
7. Think step by step. Plan before you act.
|
|
68
|
+
8. Use "add_task" to queue follow-up work you discover (improvements, tests, documentation, refactoring).
|
|
69
|
+
9. Use "list_tasks" to see the current task queue and progress.
|
|
70
|
+
|
|
71
|
+
When you have fully completed the CURRENT task, call the "task_complete" tool with a summary of everything you accomplished. In continuous mode, you will automatically receive the next task from the queue.`;
|
|
72
|
+
/** Override the recorded context-limit source (e.g. after a /models endpoint hit). */
|
|
73
|
+
function markContextLimitSource(src) {
|
|
74
|
+
lastConfigSources.contextLimitSource = src;
|
|
75
|
+
}
|
|
76
|
+
let lastConfigSources = {
|
|
77
|
+
fileConfigSources: [],
|
|
78
|
+
envLoaded: false,
|
|
79
|
+
warnings: [],
|
|
80
|
+
contextLimitSource: 'static',
|
|
81
|
+
instructionFiles: [],
|
|
82
|
+
};
|
|
83
|
+
function getConfigSources() {
|
|
84
|
+
return lastConfigSources;
|
|
85
|
+
}
|
|
86
|
+
/** Pick the first defined value from a list of candidates. */
|
|
87
|
+
function firstDefined(...vals) {
|
|
88
|
+
for (const v of vals) {
|
|
89
|
+
if (v !== undefined && v !== null && !(typeof v === 'string' && v === ''))
|
|
90
|
+
return v;
|
|
91
|
+
}
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
function loadConfig(overrides) {
|
|
95
|
+
// ── 1. Load .env from current working directory ──
|
|
96
|
+
const envPath = path.resolve(process.cwd(), '.env');
|
|
97
|
+
let envLoaded = false;
|
|
98
|
+
if (fs.existsSync(envPath)) {
|
|
99
|
+
dotenv.config({ path: envPath });
|
|
100
|
+
envLoaded = true;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
const r = dotenv.config();
|
|
104
|
+
envLoaded = !r.error;
|
|
105
|
+
}
|
|
106
|
+
// ── 2. Load file config (global + project), env refs resolved ──
|
|
107
|
+
const { config: file, sources, warnings } = (0, fileconfig_1.loadFileConfig)();
|
|
108
|
+
// ── 3. Resolve provider (override > file > env > default) ──
|
|
109
|
+
const provider = (overrides?.provider ||
|
|
110
|
+
file.provider ||
|
|
111
|
+
process.env.NOTSLEEP_PROVIDER ||
|
|
112
|
+
'openai');
|
|
113
|
+
// ── 4. Merge each field with correct priority ──
|
|
114
|
+
const config = {
|
|
115
|
+
provider,
|
|
116
|
+
openai: {
|
|
117
|
+
apiKey: firstDefined(overrides?.openai?.apiKey, file.openai?.apiKey, process.env.OPENAI_API_KEY) || '',
|
|
118
|
+
model: firstDefined(overrides?.openai?.model, file.openai?.model, process.env.OPENAI_MODEL) || 'gpt-4o',
|
|
119
|
+
baseURL: firstDefined(overrides?.openai?.baseURL, file.openai?.baseURL, process.env.OPENAI_BASE_URL),
|
|
120
|
+
},
|
|
121
|
+
anthropic: {
|
|
122
|
+
apiKey: firstDefined(overrides?.anthropic?.apiKey, file.anthropic?.apiKey, process.env.ANTHROPIC_API_KEY) || '',
|
|
123
|
+
model: firstDefined(overrides?.anthropic?.model, file.anthropic?.model, process.env.ANTHROPIC_MODEL) || 'claude-sonnet-4-20250514',
|
|
124
|
+
baseURL: firstDefined(overrides?.anthropic?.baseURL, file.anthropic?.baseURL, process.env.ANTHROPIC_BASE_URL),
|
|
125
|
+
},
|
|
126
|
+
maxIterations: firstDefined(overrides?.maxIterations, file.maxIterations, process.env.NOTSLEEP_MAX_ITERATIONS ? parseInt(process.env.NOTSLEEP_MAX_ITERATIONS, 10) : undefined) ?? 1000,
|
|
127
|
+
maxIterationsPerTask: firstDefined(overrides?.maxIterationsPerTask, file.maxIterationsPerTask, process.env.NOTSLEEP_MAX_ITERATIONS_PER_TASK ? parseInt(process.env.NOTSLEEP_MAX_ITERATIONS_PER_TASK, 10) : undefined) ?? 0, // 0 = no per-task cap
|
|
128
|
+
checkpointDir: firstDefined(overrides?.checkpointDir, file.checkpointDir, process.env.NOTSLEEP_CHECKPOINT_DIR) ?? '.notsleep/checkpoints',
|
|
129
|
+
logDir: firstDefined(overrides?.logDir, file.logDir, process.env.NOTSLEEP_LOG_DIR) ?? '.notsleep/logs',
|
|
130
|
+
// Context window limit: if not explicitly set, auto-detect from the
|
|
131
|
+
// model name so we never exceed what the model actually supports.
|
|
132
|
+
// The old hard-coded default of 120 000 was wrong for models like
|
|
133
|
+
// GPT-4 (8K) or Claude (200K).
|
|
134
|
+
contextWindowLimit: firstDefined(overrides?.contextWindowLimit, file.contextWindowLimit, process.env.NOTSLEEP_CONTEXT_WINDOW_LIMIT ? parseInt(process.env.NOTSLEEP_CONTEXT_WINDOW_LIMIT, 10) : undefined) ?? 0, // 0 = auto-detect (resolved below after model is known)
|
|
135
|
+
summarizeThreshold: firstDefined(overrides?.summarizeThreshold, file.summarizeThreshold, process.env.NOTSLEEP_SUMMARIZE_THRESHOLD ? parseFloat(process.env.NOTSLEEP_SUMMARIZE_THRESHOLD) : undefined) ?? 0.75,
|
|
136
|
+
maxRetries: firstDefined(overrides?.maxRetries, file.maxRetries, process.env.NOTSLEEP_MAX_RETRIES ? parseInt(process.env.NOTSLEEP_MAX_RETRIES, 10) : undefined) ?? 10,
|
|
137
|
+
retryBaseDelayMs: firstDefined(overrides?.retryBaseDelayMs, file.retryBaseDelayMs, process.env.NOTSLEEP_RETRY_BASE_DELAY_MS ? parseInt(process.env.NOTSLEEP_RETRY_BASE_DELAY_MS, 10) : undefined) ?? 1000,
|
|
138
|
+
toolTimeoutMs: firstDefined(overrides?.toolTimeoutMs, file.toolTimeoutMs, process.env.NOTSLEEP_TOOL_TIMEOUT_MS ? parseInt(process.env.NOTSLEEP_TOOL_TIMEOUT_MS, 10) : undefined) ?? 120000,
|
|
139
|
+
systemPrompt: firstDefined(overrides?.systemPrompt, file.systemPrompt) ?? exports.DEFAULT_SYSTEM_PROMPT,
|
|
140
|
+
continuous: firstDefined(overrides?.continuous, file.continuous, process.env.NOTSLEEP_CONTINUOUS === 'true' ? true : undefined) ?? false,
|
|
141
|
+
stopFile: firstDefined(overrides?.stopFile, file.stopFile, process.env.NOTSLEEP_STOP_FILE) ?? '.notsleep/STOP',
|
|
142
|
+
maxCostUsd: firstDefined(overrides?.maxCostUsd, file.maxCostUsd, process.env.NOTSLEEP_MAX_COST_USD ? parseFloat(process.env.NOTSLEEP_MAX_COST_USD) : undefined),
|
|
143
|
+
customTools: overrides?.customTools ?? file.customTools,
|
|
144
|
+
autoCommit: firstDefined(overrides?.autoCommit, file.autoCommit, process.env.NOTSLEEP_AUTO_COMMIT === 'true' ? true : undefined) ?? false,
|
|
145
|
+
dashboard: {
|
|
146
|
+
enabled: firstDefined(overrides?.dashboard?.enabled, file.dashboard?.enabled, process.env.NOTSLEEP_DASHBOARD === 'true' ? true : undefined) ?? false,
|
|
147
|
+
port: firstDefined(overrides?.dashboard?.port, file.dashboard?.port, process.env.NOTSLEEP_DASHBOARD_PORT ? parseInt(process.env.NOTSLEEP_DASHBOARD_PORT, 10) : undefined) ?? 3120,
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
// ── 4b. Unified "provider/model" registry selector (OpenCode-style) ──
|
|
151
|
+
// If a `model` selector like "groq/llama-3.3-70b-versatile" is given, resolve
|
|
152
|
+
// it against the built-in provider registry (overlaid with the user's
|
|
153
|
+
// `providers` map) and populate the legacy provider + openai/anthropic block
|
|
154
|
+
// from the result. All downstream code (provider.ts, agent.ts) then works
|
|
155
|
+
// unchanged — it only ever reads config.provider and the two blocks.
|
|
156
|
+
const providers = overrides?.providers ?? file.providers;
|
|
157
|
+
const modelRef = firstDefined(overrides?.model, file.model, process.env.NOTSLEEP_MODEL);
|
|
158
|
+
if ((0, registry_1.isModelRef)(modelRef)) {
|
|
159
|
+
const resolved = (0, registry_1.resolveModelRef)(modelRef, providers);
|
|
160
|
+
config.provider = resolved.type;
|
|
161
|
+
config.model = modelRef;
|
|
162
|
+
config.providers = providers;
|
|
163
|
+
const block = { apiKey: resolved.apiKey, model: resolved.model, baseURL: resolved.baseURL };
|
|
164
|
+
if (resolved.type === 'anthropic') {
|
|
165
|
+
config.anthropic = block;
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
config.openai = block;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
// ── 4c. Optional small model for the agent's internal calls ──
|
|
172
|
+
// A "provider/model" ref resolves via the registry (its own creds); a bare
|
|
173
|
+
// model id reuses the PRIMARY provider's key + baseURL (e.g. primary gpt-4o,
|
|
174
|
+
// small_model "gpt-4o-mini"). Left unset → internal calls use the primary.
|
|
175
|
+
const smallRef = firstDefined(overrides?.smallModelRef, file.small_model, file.smallModel, process.env.NOTSLEEP_SMALL_MODEL);
|
|
176
|
+
if (smallRef) {
|
|
177
|
+
if ((0, registry_1.isModelRef)(smallRef)) {
|
|
178
|
+
const r = (0, registry_1.resolveModelRef)(smallRef, providers);
|
|
179
|
+
config.smallModel = { provider: r.type, apiKey: r.apiKey, model: r.model, baseURL: r.baseURL };
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
const primaryKey = config.provider === 'openai' ? config.openai.apiKey : config.anthropic.apiKey;
|
|
183
|
+
const primaryBase = config.provider === 'openai' ? config.openai.baseURL : config.anthropic.baseURL;
|
|
184
|
+
config.smallModel = {
|
|
185
|
+
provider: config.provider,
|
|
186
|
+
apiKey: primaryKey,
|
|
187
|
+
model: smallRef,
|
|
188
|
+
baseURL: primaryBase,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
// ── Filter warnings: drop "not set" noise for the INACTIVE provider ──
|
|
193
|
+
// (init writes both provider blocks by default; only warn about the one in use.)
|
|
194
|
+
const inactiveKeyField = provider === 'openai' ? 'anthropic.apiKey' : 'openai.apiKey';
|
|
195
|
+
const relevantWarnings = warnings.filter((w) => {
|
|
196
|
+
// Keep all malformed-ref warnings; only suppress "not set" for the inactive provider.
|
|
197
|
+
if (w.startsWith(inactiveKeyField) && w.includes('is not set'))
|
|
198
|
+
return false;
|
|
199
|
+
return true;
|
|
200
|
+
});
|
|
201
|
+
// ── 5. Resolve the context window limit ──
|
|
202
|
+
// Priority: an explicit user value wins. Otherwise auto-detect, preferring
|
|
203
|
+
// LIVE metadata from the models.dev catalog (populated by ensureModelCatalog()
|
|
204
|
+
// before loadConfig in the CLI paths; empty in offline/unit-test contexts, in
|
|
205
|
+
// which case we fall back to the static table in cost.ts). We store 90% of the
|
|
206
|
+
// real window as the limit, leaving headroom for the completion.
|
|
207
|
+
let contextLimitSource = 'explicit';
|
|
208
|
+
if (config.contextWindowLimit <= 0) {
|
|
209
|
+
const modelId = config.provider === 'openai'
|
|
210
|
+
? config.openai.model
|
|
211
|
+
: config.anthropic.model;
|
|
212
|
+
const providerName = (0, registry_1.isModelRef)(config.model)
|
|
213
|
+
? (0, registry_1.parseModelRef)(config.model).providerName
|
|
214
|
+
: config.provider;
|
|
215
|
+
const live = (0, modelsdev_1.liveContextLimit)(providerName, modelId);
|
|
216
|
+
if (live !== undefined) {
|
|
217
|
+
config.contextWindowLimit = Math.floor(live * 0.9);
|
|
218
|
+
contextLimitSource = 'catalog';
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
config.contextWindowLimit = (0, cost_1.safeContextLimit)(modelId);
|
|
222
|
+
contextLimitSource = 'static';
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
// ── 5b. Fold instruction files into the system prompt ──
|
|
226
|
+
// Explicit `instructions` (relative to the project config) plus auto-loaded
|
|
227
|
+
// AGENTS.md / NOTSLEEP.md from the project root, appended as clearly-labeled
|
|
228
|
+
// context. This is only for the default/base prompt; if the user supplied a
|
|
229
|
+
// fully custom systemPrompt via override we still append project guidance.
|
|
230
|
+
const projectPath = (0, fileconfig_1.findProjectConfig)();
|
|
231
|
+
const projectDir = projectPath ? path.dirname(projectPath) : process.cwd();
|
|
232
|
+
const instr = (0, fileconfig_1.gatherInstructions)(file, projectDir);
|
|
233
|
+
if (instr.text) {
|
|
234
|
+
config.systemPrompt += `\n\n--- PROJECT INSTRUCTIONS ---\n\n${instr.text}`;
|
|
235
|
+
}
|
|
236
|
+
lastConfigSources = {
|
|
237
|
+
fileConfigSources: sources,
|
|
238
|
+
envLoaded,
|
|
239
|
+
warnings: relevantWarnings,
|
|
240
|
+
contextLimitSource,
|
|
241
|
+
instructionFiles: instr.files,
|
|
242
|
+
};
|
|
243
|
+
// ── 6. Validate ──
|
|
244
|
+
// Reject unknown providers early with a clear message. Otherwise an invalid
|
|
245
|
+
// value silently falls through to the anthropic branch and later fails with
|
|
246
|
+
// a confusing "client not initialized" error deep in the run.
|
|
247
|
+
if (config.provider !== 'openai' && config.provider !== 'anthropic') {
|
|
248
|
+
throw new Error(`Unknown provider "${config.provider}". Valid providers are: openai, anthropic.`);
|
|
249
|
+
}
|
|
250
|
+
const activeKey = config.provider === 'openai' ? config.openai?.apiKey : config.anthropic?.apiKey;
|
|
251
|
+
if (!activeKey) {
|
|
252
|
+
if ((0, registry_1.isModelRef)(config.model)) {
|
|
253
|
+
// Registry path: name the provider and how to supply its key.
|
|
254
|
+
const providerName = config.model.slice(0, config.model.indexOf('/'));
|
|
255
|
+
throw new Error(`No API key for provider "${providerName}" (model "${config.model}"). ` +
|
|
256
|
+
`Set its key in the "providers" section of notsleep.json ` +
|
|
257
|
+
`(e.g. "providers": { "${providerName}": { "apiKey": "{env:${providerName.toUpperCase()}_API_KEY}" } }) ` +
|
|
258
|
+
`or export the matching environment variable.`);
|
|
259
|
+
}
|
|
260
|
+
const envVar = config.provider === 'openai' ? 'OPENAI_API_KEY' : 'ANTHROPIC_API_KEY';
|
|
261
|
+
throw new Error(`${envVar} is required when using the ${config.provider} provider. Set it in .env, notsleep.json, or pass it directly. Run "notsleep init" to set up config.`);
|
|
262
|
+
}
|
|
263
|
+
return config;
|
|
264
|
+
}
|
|
265
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";AAAA,+DAA+D;AAC/D,kCAAkC;AAClC,+DAA+D;AAC/D,EAAE;AACF,2BAA2B;AAC3B,0CAA0C;AAC1C,8CAA8C;AAC9C,sDAAsD;AACtD,0BAA0B;AAC1B,yBAAyB;AACzB,+DAA+D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6C/D,wDAEC;AASD,4CAEC;AAUD,gCA2SC;AA7WD,+CAAiC;AACjC,2CAA6B;AAC7B,uCAAyB;AAEzB,6CAAqF;AACrF,iCAA0C;AAC1C,yCAAsF;AACtF,2CAA+C;AAElC,QAAA,qBAAqB,GAAG;;;;;;;;;;;;;8MAayK,CAAC;AAoB/M,sFAAsF;AACtF,SAAgB,sBAAsB,CAAC,GAAwC;IAC7E,iBAAiB,CAAC,kBAAkB,GAAG,GAAG,CAAC;AAC7C,CAAC;AAED,IAAI,iBAAiB,GAAkB;IACrC,iBAAiB,EAAE,EAAE;IACrB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AAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC;IAClG,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,IAAI,IAAA,qBAAU,EAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YAC7B,8DAA8D;YAC9D,MAAM,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;YACtE,MAAM,IAAI,KAAK,CACb,4BAA4B,YAAY,aAAa,MAAM,CAAC,KAAK,MAAM;gBACvE,0DAA0D;gBAC1D,yBAAyB,YAAY,wBAAwB,YAAY,CAAC,WAAW,EAAE,kBAAkB;gBACzG,8CAA8C,CAC/C,CAAC;QACJ,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,mBAAmB,CAAC;QACrF,MAAM,IAAI,KAAK,CAAC,GAAG,MAAM,+BAA+B,MAAM,CAAC,QAAQ,sGAAsG,CAAC,CAAC;IACjL,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface ProjectContext {
|
|
2
|
+
cwd: string;
|
|
3
|
+
language: string;
|
|
4
|
+
framework: string;
|
|
5
|
+
packageManager: string;
|
|
6
|
+
gitBranch: string | null;
|
|
7
|
+
gitDirty: boolean;
|
|
8
|
+
readme: string | null;
|
|
9
|
+
dependencies: string[];
|
|
10
|
+
fileTree: string;
|
|
11
|
+
configFiles: string[];
|
|
12
|
+
summary: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function detectProjectContext(cwd?: string): ProjectContext;
|
|
15
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAoBA,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,oBAAoB,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,cAAc,CA+KjE"}
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================
|
|
3
|
+
// NotSleep - Project Context Auto-Detector
|
|
4
|
+
// ============================================================
|
|
5
|
+
//
|
|
6
|
+
// Scans the current working directory to understand the project:
|
|
7
|
+
// - Git status & branch
|
|
8
|
+
// - package.json / requirements.txt / go.mod etc.
|
|
9
|
+
// - README
|
|
10
|
+
// - File tree (top 3 levels)
|
|
11
|
+
// - Existing config files
|
|
12
|
+
//
|
|
13
|
+
// Produces a context string injected into the system prompt
|
|
14
|
+
// so the agent already knows what it's working with.
|
|
15
|
+
//
|
|
16
|
+
// ============================================================
|
|
17
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
+
}
|
|
23
|
+
Object.defineProperty(o, k2, desc);
|
|
24
|
+
}) : (function(o, m, k, k2) {
|
|
25
|
+
if (k2 === undefined) k2 = k;
|
|
26
|
+
o[k2] = m[k];
|
|
27
|
+
}));
|
|
28
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
+
}) : function(o, v) {
|
|
31
|
+
o["default"] = v;
|
|
32
|
+
});
|
|
33
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
34
|
+
var ownKeys = function(o) {
|
|
35
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
36
|
+
var ar = [];
|
|
37
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
38
|
+
return ar;
|
|
39
|
+
};
|
|
40
|
+
return ownKeys(o);
|
|
41
|
+
};
|
|
42
|
+
return function (mod) {
|
|
43
|
+
if (mod && mod.__esModule) return mod;
|
|
44
|
+
var result = {};
|
|
45
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
46
|
+
__setModuleDefault(result, mod);
|
|
47
|
+
return result;
|
|
48
|
+
};
|
|
49
|
+
})();
|
|
50
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
+
exports.detectProjectContext = detectProjectContext;
|
|
52
|
+
const fs = __importStar(require("fs"));
|
|
53
|
+
const path = __importStar(require("path"));
|
|
54
|
+
const child_process_1 = require("child_process");
|
|
55
|
+
function detectProjectContext(cwd) {
|
|
56
|
+
const dir = cwd || process.cwd();
|
|
57
|
+
const ctx = {
|
|
58
|
+
cwd: dir,
|
|
59
|
+
language: 'unknown',
|
|
60
|
+
framework: 'unknown',
|
|
61
|
+
packageManager: 'unknown',
|
|
62
|
+
gitBranch: null,
|
|
63
|
+
gitDirty: false,
|
|
64
|
+
readme: null,
|
|
65
|
+
dependencies: [],
|
|
66
|
+
fileTree: '',
|
|
67
|
+
configFiles: [],
|
|
68
|
+
summary: '',
|
|
69
|
+
};
|
|
70
|
+
// ─── Git ──────────────────────────────────────────────
|
|
71
|
+
try {
|
|
72
|
+
ctx.gitBranch = (0, child_process_1.execSync)('git rev-parse --abbrev-ref HEAD', { cwd: dir, stdio: ['pipe', 'pipe', 'pipe'] })
|
|
73
|
+
.toString().trim();
|
|
74
|
+
const status = (0, child_process_1.execSync)('git status --porcelain', { cwd: dir, stdio: ['pipe', 'pipe', 'pipe'] })
|
|
75
|
+
.toString().trim();
|
|
76
|
+
ctx.gitDirty = status.length > 0;
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
// not a git repo
|
|
80
|
+
}
|
|
81
|
+
// ─── Language / Package Manager Detection ─────────────
|
|
82
|
+
const detectors = [
|
|
83
|
+
{
|
|
84
|
+
file: 'package.json', lang: 'JavaScript/TypeScript', pm: 'npm',
|
|
85
|
+
framework: (pkg) => {
|
|
86
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
87
|
+
if (deps['next'])
|
|
88
|
+
return 'Next.js';
|
|
89
|
+
if (deps['nuxt'])
|
|
90
|
+
return 'Nuxt';
|
|
91
|
+
if (deps['react'])
|
|
92
|
+
return 'React';
|
|
93
|
+
if (deps['vue'])
|
|
94
|
+
return 'Vue';
|
|
95
|
+
if (deps['svelte'])
|
|
96
|
+
return 'Svelte';
|
|
97
|
+
if (deps['express'])
|
|
98
|
+
return 'Express';
|
|
99
|
+
if (deps['fastify'])
|
|
100
|
+
return 'Fastify';
|
|
101
|
+
if (deps['nestjs'] || deps['@nestjs/core'])
|
|
102
|
+
return 'NestJS';
|
|
103
|
+
if (deps['angular'] || deps['@angular/core'])
|
|
104
|
+
return 'Angular';
|
|
105
|
+
return 'Node.js';
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
{ file: 'requirements.txt', lang: 'Python', pm: 'pip' },
|
|
109
|
+
{ file: 'pyproject.toml', lang: 'Python', pm: 'poetry/pip' },
|
|
110
|
+
{ file: 'Pipfile', lang: 'Python', pm: 'pipenv' },
|
|
111
|
+
{ file: 'go.mod', lang: 'Go', pm: 'go modules' },
|
|
112
|
+
{ file: 'Cargo.toml', lang: 'Rust', pm: 'cargo' },
|
|
113
|
+
{ file: 'pom.xml', lang: 'Java', pm: 'maven' },
|
|
114
|
+
{ file: 'build.gradle', lang: 'Java/Kotlin', pm: 'gradle' },
|
|
115
|
+
{ file: 'Gemfile', lang: 'Ruby', pm: 'bundler' },
|
|
116
|
+
{ file: 'composer.json', lang: 'PHP', pm: 'composer' },
|
|
117
|
+
{ file: 'pubspec.yaml', lang: 'Dart/Flutter', pm: 'pub' },
|
|
118
|
+
];
|
|
119
|
+
for (const det of detectors) {
|
|
120
|
+
const filePath = path.join(dir, det.file);
|
|
121
|
+
if (fs.existsSync(filePath)) {
|
|
122
|
+
ctx.language = det.lang;
|
|
123
|
+
ctx.packageManager = det.pm;
|
|
124
|
+
// Detect framework from package.json
|
|
125
|
+
if (det.file === 'package.json' && det.framework) {
|
|
126
|
+
try {
|
|
127
|
+
const pkg = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
|
128
|
+
ctx.framework = det.framework(pkg);
|
|
129
|
+
// Extract top dependencies
|
|
130
|
+
const deps = Object.keys(pkg.dependencies || {}).slice(0, 15);
|
|
131
|
+
const devDeps = Object.keys(pkg.devDependencies || {}).slice(0, 10);
|
|
132
|
+
ctx.dependencies = [...deps, ...devDeps.map(d => `${d} (dev)`)];
|
|
133
|
+
// Check for yarn/pnpm
|
|
134
|
+
if (fs.existsSync(path.join(dir, 'yarn.lock')))
|
|
135
|
+
ctx.packageManager = 'yarn';
|
|
136
|
+
if (fs.existsSync(path.join(dir, 'pnpm-lock.yaml')))
|
|
137
|
+
ctx.packageManager = 'pnpm';
|
|
138
|
+
if (fs.existsSync(path.join(dir, 'bun.lockb')))
|
|
139
|
+
ctx.packageManager = 'bun';
|
|
140
|
+
}
|
|
141
|
+
catch { /* ignore parse errors */ }
|
|
142
|
+
}
|
|
143
|
+
// Check for TypeScript
|
|
144
|
+
if (fs.existsSync(path.join(dir, 'tsconfig.json'))) {
|
|
145
|
+
ctx.language = 'TypeScript';
|
|
146
|
+
}
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// ─── README ───────────────────────────────────────────
|
|
151
|
+
const readmeNames = ['README.md', 'readme.md', 'README.txt', 'README'];
|
|
152
|
+
for (const name of readmeNames) {
|
|
153
|
+
const readmePath = path.join(dir, name);
|
|
154
|
+
if (fs.existsSync(readmePath)) {
|
|
155
|
+
try {
|
|
156
|
+
const content = fs.readFileSync(readmePath, 'utf-8');
|
|
157
|
+
// Take first 2000 chars
|
|
158
|
+
ctx.readme = content.substring(0, 2000);
|
|
159
|
+
if (content.length > 2000)
|
|
160
|
+
ctx.readme += '\n... [truncated]';
|
|
161
|
+
}
|
|
162
|
+
catch { /* ignore */ }
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
// ─── Config Files ─────────────────────────────────────
|
|
167
|
+
const configPatterns = [
|
|
168
|
+
'.env', '.env.example', '.gitignore', 'Dockerfile', 'docker-compose.yml',
|
|
169
|
+
'tsconfig.json', '.eslintrc.js', '.prettierrc', 'jest.config.js',
|
|
170
|
+
'vite.config.ts', 'next.config.js', 'webpack.config.js',
|
|
171
|
+
'.github/workflows', 'Makefile', 'vercel.json', 'netlify.toml',
|
|
172
|
+
];
|
|
173
|
+
for (const p of configPatterns) {
|
|
174
|
+
if (fs.existsSync(path.join(dir, p))) {
|
|
175
|
+
ctx.configFiles.push(p);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
// ─── File Tree (top 3 levels) ─────────────────────────
|
|
179
|
+
const treeLines = [];
|
|
180
|
+
const skipDirs = new Set(['node_modules', '.git', 'dist', 'build', '__pycache__', '.next', '.nuxt', 'target', 'vendor', '.venv', 'venv']);
|
|
181
|
+
function walk(d, prefix, depth) {
|
|
182
|
+
if (depth > 3 || treeLines.length > 80)
|
|
183
|
+
return;
|
|
184
|
+
try {
|
|
185
|
+
const entries = fs.readdirSync(d, { withFileTypes: true })
|
|
186
|
+
.filter(e => !e.name.startsWith('.') || e.name === '.env.example' || e.name === '.gitignore')
|
|
187
|
+
.filter(e => !skipDirs.has(e.name))
|
|
188
|
+
.sort((a, b) => {
|
|
189
|
+
// Dirs first
|
|
190
|
+
if (a.isDirectory() && !b.isDirectory())
|
|
191
|
+
return -1;
|
|
192
|
+
if (!a.isDirectory() && b.isDirectory())
|
|
193
|
+
return 1;
|
|
194
|
+
return a.name.localeCompare(b.name);
|
|
195
|
+
});
|
|
196
|
+
for (let i = 0; i < entries.length; i++) {
|
|
197
|
+
if (treeLines.length > 80) {
|
|
198
|
+
treeLines.push(prefix + '... (truncated)');
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const isLast = i === entries.length - 1;
|
|
202
|
+
const connector = isLast ? '└── ' : '├── ';
|
|
203
|
+
const childPrefix = isLast ? ' ' : '│ ';
|
|
204
|
+
const entry = entries[i];
|
|
205
|
+
treeLines.push(prefix + connector + entry.name + (entry.isDirectory() ? '/' : ''));
|
|
206
|
+
if (entry.isDirectory()) {
|
|
207
|
+
walk(path.join(d, entry.name), prefix + childPrefix, depth + 1);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
catch { /* ignore permission errors */ }
|
|
212
|
+
}
|
|
213
|
+
walk(dir, '', 0);
|
|
214
|
+
ctx.fileTree = treeLines.join('\n');
|
|
215
|
+
// ─── Build Summary ────────────────────────────────────
|
|
216
|
+
const parts = [];
|
|
217
|
+
parts.push(`Working directory: ${dir}`);
|
|
218
|
+
parts.push(`Language: ${ctx.language} | Framework: ${ctx.framework} | Package manager: ${ctx.packageManager}`);
|
|
219
|
+
if (ctx.gitBranch) {
|
|
220
|
+
parts.push(`Git branch: ${ctx.gitBranch}${ctx.gitDirty ? ' (dirty - uncommitted changes)' : ' (clean)'}`);
|
|
221
|
+
}
|
|
222
|
+
if (ctx.configFiles.length > 0) {
|
|
223
|
+
parts.push(`Config files: ${ctx.configFiles.join(', ')}`);
|
|
224
|
+
}
|
|
225
|
+
if (ctx.dependencies.length > 0) {
|
|
226
|
+
parts.push(`Key dependencies: ${ctx.dependencies.join(', ')}`);
|
|
227
|
+
}
|
|
228
|
+
if (ctx.fileTree) {
|
|
229
|
+
parts.push(`\nProject structure:\n${ctx.fileTree}`);
|
|
230
|
+
}
|
|
231
|
+
if (ctx.readme) {
|
|
232
|
+
parts.push(`\nREADME (excerpt):\n${ctx.readme}`);
|
|
233
|
+
}
|
|
234
|
+
ctx.summary = parts.join('\n');
|
|
235
|
+
return ctx;
|
|
236
|
+
}
|
|
237
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":";AAAA,+DAA+D;AAC/D,2CAA2C;AAC3C,+DAA+D;AAC/D,EAAE;AACF,iEAAiE;AACjE,0BAA0B;AAC1B,oDAAoD;AACpD,aAAa;AACb,+BAA+B;AAC/B,4BAA4B;AAC5B,EAAE;AACF,4DAA4D;AAC5D,qDAAqD;AACrD,EAAE;AACF,+DAA+D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoB/D,oDA+KC;AAjMD,uCAAyB;AACzB,2CAA6B;AAC7B,iDAAyC;AAgBzC,SAAgB,oBAAoB,CAAC,GAAY;IAC/C,MAAM,GAAG,GAAG,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IAEjC,MAAM,GAAG,GAAmB;QAC1B,GAAG,EAAE,GAAG;QACR,QAAQ,EAAE,SAAS;QACnB,SAAS,EAAE,SAAS;QACpB,cAAc,EAAE,SAAS;QACzB,SAAS,EAAE,IAAI;QACf,QAAQ,EAAE,KAAK;QACf,MAAM,EAAE,IAAI;QACZ,YAAY,EAAE,EAAE;QAChB,QAAQ,EAAE,EAAE;QACZ,WAAW,EAAE,EAAE;Q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EAAE,CAAC,CAAC;IACnD,CAAC;IAED,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/B,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/dist/cost.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface ModelPrice {
|
|
2
|
+
/** USD per 1M input (prompt) tokens */
|
|
3
|
+
input: number;
|
|
4
|
+
/** USD per 1M output (completion) tokens */
|
|
5
|
+
output: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Look up the context window size (max input tokens) for a model.
|
|
9
|
+
* Returns the raw model limit; callers should apply a safety margin.
|
|
10
|
+
*/
|
|
11
|
+
export declare function contextWindowForModel(model: string): number;
|
|
12
|
+
/**
|
|
13
|
+
* Compute a safe context window limit for the agent, leaving room for
|
|
14
|
+
* the model's output. Uses 90% of the model's context window, capped
|
|
15
|
+
* so we never exceed what the model actually supports.
|
|
16
|
+
*/
|
|
17
|
+
export declare function safeContextLimit(model: string): number;
|
|
18
|
+
/** Look up the per-1M price for a model name (case-insensitive substring). */
|
|
19
|
+
export declare function priceForModel(model: string): ModelPrice;
|
|
20
|
+
/**
|
|
21
|
+
* Estimate the USD cost of a single call given its token usage.
|
|
22
|
+
*/
|
|
23
|
+
export declare function estimateCost(model: string, promptTokens: number, completionTokens: number): number;
|
|
24
|
+
/** Format a USD amount for display (4 decimals under $1, else 2). */
|
|
25
|
+
export declare function formatUsd(amount: number): string;
|
|
26
|
+
//# sourceMappingURL=cost.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cost.d.ts","sourceRoot":"","sources":["../src/cost.ts"],"names":[],"mappings":"AAWA,MAAM,WAAW,UAAU;IACzB,uCAAuC;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,4CAA4C;IAC5C,MAAM,EAAE,MAAM,CAAC;CAChB;AAyGD;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAM3D;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAKtD;AAED,8EAA8E;AAC9E,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAMvD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,GAAG,MAAM,CAGlG;AAED,qEAAqE;AACrE,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAGhD"}
|