@pi-unipi/core 0.1.10 → 0.1.12
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/constants.ts +3 -2
- package/events.ts +19 -1
- package/index.ts +1 -0
- package/model-cache.ts +70 -0
- package/package.json +1 -1
package/constants.ts
CHANGED
|
@@ -158,9 +158,11 @@ export const UTILITY_COMMANDS = {
|
|
|
158
158
|
CLEANUP: "cleanup",
|
|
159
159
|
ENV: "env",
|
|
160
160
|
DOCTOR: "doctor",
|
|
161
|
-
|
|
161
|
+
BADGE_NAME: "badge-name",
|
|
162
162
|
BADGE_GEN: "badge-gen",
|
|
163
163
|
BADGE_TOGGLE: "badge-toggle",
|
|
164
|
+
BADGE_SETTINGS: "badge-settings",
|
|
165
|
+
UTIL_SETTINGS: "util-settings",
|
|
164
166
|
} as const;
|
|
165
167
|
|
|
166
168
|
/** Utility tool names */
|
|
@@ -247,7 +249,6 @@ export const COMPACTOR_DIRS = {
|
|
|
247
249
|
export const KANBOARD_COMMANDS = {
|
|
248
250
|
KANBOARD: "kanboard",
|
|
249
251
|
KANBOARD_DOCTOR: "kanboard-doctor",
|
|
250
|
-
NAME_GEN: "name-gen",
|
|
251
252
|
} as const;
|
|
252
253
|
|
|
253
254
|
/** Kanboard directory paths */
|
package/events.ts
CHANGED
|
@@ -78,6 +78,9 @@ export const UNIPI_EVENTS = {
|
|
|
78
78
|
|
|
79
79
|
/** Badge generation requested (from kanboard or other module) */
|
|
80
80
|
BADGE_GENERATE_REQUEST: "unipi:badge:generate:request",
|
|
81
|
+
|
|
82
|
+
/** Agent asked user a question (ask_user tool invoked) */
|
|
83
|
+
ASK_USER_PROMPT: "unipi:ask-user:prompt",
|
|
81
84
|
} as const;
|
|
82
85
|
|
|
83
86
|
/** Payload for MODULE_READY / MODULE_GONE */
|
|
@@ -306,6 +309,20 @@ export interface UnipiBadgeGenerateRequestEvent {
|
|
|
306
309
|
conversationSummary?: string;
|
|
307
310
|
}
|
|
308
311
|
|
|
312
|
+
/** Payload for ASK_USER_PROMPT */
|
|
313
|
+
export interface UnipiAskUserPromptEvent {
|
|
314
|
+
/** Question being asked */
|
|
315
|
+
question: string;
|
|
316
|
+
/** Additional context */
|
|
317
|
+
context?: string;
|
|
318
|
+
/** Number of options provided */
|
|
319
|
+
optionCount?: number;
|
|
320
|
+
/** Whether multi-select mode */
|
|
321
|
+
allowMultiple?: boolean;
|
|
322
|
+
/** Whether freeform input allowed */
|
|
323
|
+
allowFreeform?: boolean;
|
|
324
|
+
}
|
|
325
|
+
|
|
309
326
|
/** Payload for NOTIFICATION_SENT */
|
|
310
327
|
export interface UnipiNotificationSentEvent {
|
|
311
328
|
/** Event type that triggered notification */
|
|
@@ -341,4 +358,5 @@ export type UnipiEventPayload =
|
|
|
341
358
|
| UnipiUtilityDiagnosticsEvent
|
|
342
359
|
| UnipiUtilityLifecycleEvent
|
|
343
360
|
| UnipiNotificationSentEvent
|
|
344
|
-
| UnipiBadgeGenerateRequestEvent
|
|
361
|
+
| UnipiBadgeGenerateRequestEvent
|
|
362
|
+
| UnipiAskUserPromptEvent;
|
package/index.ts
CHANGED
package/model-cache.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @pi-unipi/core — Model Cache
|
|
3
|
+
*
|
|
4
|
+
* File-based model list cache at ~/.unipi/config/models-cache.json.
|
|
5
|
+
* Allows TUI components and other packages to list available models
|
|
6
|
+
* without needing ctx.modelRegistry at runtime.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import * as fs from "node:fs";
|
|
10
|
+
import * as path from "node:path";
|
|
11
|
+
|
|
12
|
+
/** Path to the model cache directory */
|
|
13
|
+
const CACHE_DIR = path.join(
|
|
14
|
+
process.env.HOME ?? process.env.USERPROFILE ?? "~",
|
|
15
|
+
".unipi/config",
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
/** Path to the model cache file */
|
|
19
|
+
const CACHE_FILE = path.join(CACHE_DIR, "models-cache.json");
|
|
20
|
+
|
|
21
|
+
/** A single cached model entry */
|
|
22
|
+
export interface CachedModel {
|
|
23
|
+
/** Model provider (e.g. "openai", "anthropic") */
|
|
24
|
+
provider: string;
|
|
25
|
+
/** Model ID (e.g. "gpt-4o", "claude-sonnet-4-6") */
|
|
26
|
+
id: string;
|
|
27
|
+
/** Optional display name */
|
|
28
|
+
name?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The full model cache structure */
|
|
32
|
+
export interface ModelCache {
|
|
33
|
+
/** ISO timestamp of last cache write */
|
|
34
|
+
updatedAt: string;
|
|
35
|
+
/** List of cached models */
|
|
36
|
+
models: CachedModel[];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Read cached model list from disk.
|
|
41
|
+
* Returns empty array if no cache file exists or it's malformed.
|
|
42
|
+
*/
|
|
43
|
+
export function readModelCache(): CachedModel[] {
|
|
44
|
+
try {
|
|
45
|
+
if (!fs.existsSync(CACHE_FILE)) return [];
|
|
46
|
+
const parsed = JSON.parse(fs.readFileSync(CACHE_FILE, "utf-8"));
|
|
47
|
+
return Array.isArray(parsed.models) ? parsed.models : [];
|
|
48
|
+
} catch {
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Write model list to cache file.
|
|
55
|
+
* Creates directory if needed. Best effort — silently ignores errors.
|
|
56
|
+
*/
|
|
57
|
+
export function writeModelCache(models: CachedModel[]): void {
|
|
58
|
+
try {
|
|
59
|
+
if (!fs.existsSync(CACHE_DIR)) {
|
|
60
|
+
fs.mkdirSync(CACHE_DIR, { recursive: true });
|
|
61
|
+
}
|
|
62
|
+
const cache: ModelCache = {
|
|
63
|
+
updatedAt: new Date().toISOString(),
|
|
64
|
+
models,
|
|
65
|
+
};
|
|
66
|
+
fs.writeFileSync(CACHE_FILE, JSON.stringify(cache, null, 2) + "\n", "utf-8");
|
|
67
|
+
} catch {
|
|
68
|
+
// Best effort — cache is optional
|
|
69
|
+
}
|
|
70
|
+
}
|