@chozzz/vargos 2.0.4 → 2.0.6
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/dist/lib/async-handlers.d.ts +13 -0
- package/dist/lib/async-handlers.d.ts.map +1 -0
- package/dist/lib/async-handlers.js +6 -0
- package/dist/lib/async-handlers.js.map +1 -0
- package/dist/lib/error-store.d.ts +19 -0
- package/dist/lib/error-store.d.ts.map +1 -0
- package/dist/lib/error-store.js +19 -0
- package/dist/lib/error-store.js.map +1 -0
- package/dist/lib/error.d.ts +11 -0
- package/dist/lib/error.d.ts.map +1 -0
- package/dist/lib/error.js +41 -0
- package/dist/lib/error.js.map +1 -0
- package/dist/lib/frontmatter.d.ts +23 -0
- package/dist/lib/frontmatter.d.ts.map +1 -0
- package/dist/lib/frontmatter.js +136 -0
- package/dist/lib/frontmatter.js.map +1 -0
- package/dist/lib/glob.d.ts +14 -0
- package/dist/lib/glob.d.ts.map +1 -0
- package/dist/lib/glob.js +22 -0
- package/dist/lib/glob.js.map +1 -0
- package/dist/lib/heartbeat.d.ts +23 -0
- package/dist/lib/heartbeat.d.ts.map +1 -0
- package/dist/lib/heartbeat.js +62 -0
- package/dist/lib/heartbeat.js.map +1 -0
- package/dist/lib/html.d.ts +8 -0
- package/dist/lib/html.d.ts.map +1 -0
- package/dist/lib/html.js +28 -0
- package/dist/lib/html.js.map +1 -0
- package/dist/lib/http-validate.d.ts +12 -0
- package/dist/lib/http-validate.d.ts.map +1 -0
- package/dist/lib/http-validate.js +11 -0
- package/dist/lib/http-validate.js.map +1 -0
- package/dist/lib/id.d.ts +3 -0
- package/dist/lib/id.d.ts.map +1 -0
- package/dist/lib/id.js +5 -0
- package/dist/lib/id.js.map +1 -0
- package/dist/lib/logger.d.ts +12 -0
- package/dist/lib/logger.d.ts.map +1 -0
- package/dist/lib/logger.js +28 -0
- package/dist/lib/logger.js.map +1 -0
- package/dist/lib/media-transcribe.d.ts +57 -0
- package/dist/lib/media-transcribe.d.ts.map +1 -0
- package/dist/lib/media-transcribe.js +98 -0
- package/dist/lib/media-transcribe.js.map +1 -0
- package/dist/lib/media.d.ts +7 -0
- package/dist/lib/media.d.ts.map +1 -0
- package/dist/lib/media.js +18 -0
- package/dist/lib/media.js.map +1 -0
- package/dist/lib/mime.d.ts +6 -0
- package/dist/lib/mime.d.ts.map +1 -0
- package/dist/lib/mime.js +71 -0
- package/dist/lib/mime.js.map +1 -0
- package/dist/lib/paginate.d.ts +3 -0
- package/dist/lib/paginate.d.ts.map +1 -0
- package/dist/lib/paginate.js +5 -0
- package/dist/lib/paginate.js.map +1 -0
- package/dist/lib/paths.d.ts +14 -0
- package/dist/lib/paths.d.ts.map +1 -0
- package/dist/lib/paths.js +29 -0
- package/dist/lib/paths.js.map +1 -0
- package/dist/lib/provider-loader.d.ts +10 -0
- package/dist/lib/provider-loader.d.ts.map +1 -0
- package/dist/lib/provider-loader.js +24 -0
- package/dist/lib/provider-loader.js.map +1 -0
- package/dist/lib/retry.d.ts +20 -0
- package/dist/lib/retry.d.ts.map +1 -0
- package/dist/lib/retry.js +40 -0
- package/dist/lib/retry.js.map +1 -0
- package/dist/lib/safe-async.d.ts +27 -0
- package/dist/lib/safe-async.d.ts.map +1 -0
- package/dist/lib/safe-async.js +38 -0
- package/dist/lib/safe-async.js.map +1 -0
- package/dist/lib/skills.d.ts +9 -0
- package/dist/lib/skills.d.ts.map +1 -0
- package/dist/lib/skills.js +15 -0
- package/dist/lib/skills.js.map +1 -0
- package/dist/lib/sleep.d.ts +6 -0
- package/dist/lib/sleep.d.ts.map +1 -0
- package/dist/lib/sleep.js +22 -0
- package/dist/lib/sleep.js.map +1 -0
- package/dist/lib/strip-markdown.d.ts +7 -0
- package/dist/lib/strip-markdown.d.ts.map +1 -0
- package/dist/lib/strip-markdown.js +32 -0
- package/dist/lib/strip-markdown.js.map +1 -0
- package/dist/lib/subagent.d.ts +14 -0
- package/dist/lib/subagent.d.ts.map +1 -0
- package/dist/lib/subagent.js +25 -0
- package/dist/lib/subagent.js.map +1 -0
- package/dist/lib/templates.d.ts +8 -0
- package/dist/lib/templates.d.ts.map +1 -0
- package/dist/lib/templates.js +39 -0
- package/dist/lib/templates.js.map +1 -0
- package/dist/lib/timeout.d.ts +6 -0
- package/dist/lib/timeout.d.ts.map +1 -0
- package/dist/lib/timeout.js +11 -0
- package/dist/lib/timeout.js.map +1 -0
- package/dist/lib/truncate.d.ts +11 -0
- package/dist/lib/truncate.d.ts.map +1 -0
- package/dist/lib/truncate.js +17 -0
- package/dist/lib/truncate.js.map +1 -0
- package/dist/lib/url-expand.d.ts +22 -0
- package/dist/lib/url-expand.d.ts.map +1 -0
- package/dist/lib/url-expand.js +74 -0
- package/dist/lib/url-expand.js.map +1 -0
- package/package.json +2 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Media utilities — constants and helpers for file operations
|
|
3
|
+
*
|
|
4
|
+
* Transcription is implemented in MediaService via the media.transcribeAudio bus event.
|
|
5
|
+
* Image vision APIs can be added to MediaService as needed.
|
|
6
|
+
*/
|
|
7
|
+
export declare const WHISPER_EXTS: Set<string>;
|
|
8
|
+
export declare const MIME_TO_AUDIO_EXT: Record<string, string>;
|
|
9
|
+
export declare const MIME_EXT: Record<string, string>;
|
|
10
|
+
export declare const MEDIA_TYPE_MIME_DEFAULTS: Record<string, string>;
|
|
11
|
+
export declare const EXT_TO_MIME: Record<string, string>;
|
|
12
|
+
export declare const IMAGE_MIMES: {
|
|
13
|
+
readonly 'image/jpeg': true;
|
|
14
|
+
readonly 'image/png': true;
|
|
15
|
+
readonly 'image/gif': true;
|
|
16
|
+
readonly 'image/webp': true;
|
|
17
|
+
readonly 'image/bmp': true;
|
|
18
|
+
readonly 'image/svg+xml': true;
|
|
19
|
+
};
|
|
20
|
+
export declare const AUDIO_MIMES: {
|
|
21
|
+
readonly 'audio/ogg': true;
|
|
22
|
+
readonly 'audio/mpeg': true;
|
|
23
|
+
readonly 'audio/mp4': true;
|
|
24
|
+
readonly 'audio/wav': true;
|
|
25
|
+
readonly 'audio/webm': true;
|
|
26
|
+
readonly 'audio/flac': true;
|
|
27
|
+
readonly 'audio/x-m4a': true;
|
|
28
|
+
readonly 'audio/mp3': true;
|
|
29
|
+
};
|
|
30
|
+
export declare const VIDEO_MIMES: {
|
|
31
|
+
readonly 'video/mp4': true;
|
|
32
|
+
};
|
|
33
|
+
export declare const DOCUMENT_MIMES: {
|
|
34
|
+
readonly 'text/plain': true;
|
|
35
|
+
readonly 'text/markdown': true;
|
|
36
|
+
readonly 'application/pdf': true;
|
|
37
|
+
readonly 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': true;
|
|
38
|
+
readonly 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': true;
|
|
39
|
+
};
|
|
40
|
+
export type ImageMimeType = keyof typeof IMAGE_MIMES;
|
|
41
|
+
export type AudioMimeType = keyof typeof AUDIO_MIMES;
|
|
42
|
+
export type VideoMimeType = keyof typeof VIDEO_MIMES;
|
|
43
|
+
export type DocumentMimeType = keyof typeof DOCUMENT_MIMES;
|
|
44
|
+
/**
|
|
45
|
+
* Get file extension for MIME type
|
|
46
|
+
*/
|
|
47
|
+
export declare function extFromMime(mimeType: string): string;
|
|
48
|
+
/**
|
|
49
|
+
* Get MIME type from file extension
|
|
50
|
+
*/
|
|
51
|
+
export declare function getMimeTypeFromExt(ext: string): string;
|
|
52
|
+
/**
|
|
53
|
+
* Normalize API base URL by removing trailing /v1 (or /v1/)
|
|
54
|
+
* Supports both formats: 'https://api.openai.com' and 'https://api.openai.com/v1'
|
|
55
|
+
*/
|
|
56
|
+
export declare function normalizeApiBaseUrl(baseUrl?: string): string;
|
|
57
|
+
//# sourceMappingURL=media-transcribe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media-transcribe.d.ts","sourceRoot":"","sources":["../../lib/media-transcribe.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,eAAO,MAAM,YAAY,aAAgG,CAAC;AAG1H,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAIpD,CAAC;AAGF,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAY3C,CAAC;AAGF,eAAO,MAAM,wBAAwB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAK3D,CAAC;AAGF,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAS9C,CAAC;AAGF,eAAO,MAAM,WAAW;;;;;;;CAOd,CAAC;AAEX,eAAO,MAAM,WAAW;;;;;;;;;CASd,CAAC;AAEX,eAAO,MAAM,WAAW;;CAEd,CAAC;AAEX,eAAO,MAAM,cAAc;;;;;;CAMjB,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG,MAAM,OAAO,WAAW,CAAC;AACrD,MAAM,MAAM,aAAa,GAAG,MAAM,OAAO,WAAW,CAAC;AACrD,MAAM,MAAM,aAAa,GAAG,MAAM,OAAO,WAAW,CAAC;AACrD,MAAM,MAAM,gBAAgB,GAAG,MAAM,OAAO,cAAc,CAAC;AAE3D;;GAEG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAK5D"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Media utilities — constants and helpers for file operations
|
|
3
|
+
*
|
|
4
|
+
* Transcription is implemented in MediaService via the media.transcribeAudio bus event.
|
|
5
|
+
* Image vision APIs can be added to MediaService as needed.
|
|
6
|
+
*/
|
|
7
|
+
// Supported audio extensions for Whisper API
|
|
8
|
+
export const WHISPER_EXTS = new Set(['.flac', '.m4a', '.mp3', '.mp4', '.mpeg', '.mpga', '.oga', '.ogg', '.wav', '.webm']);
|
|
9
|
+
// MIME type to audio extension mapping
|
|
10
|
+
export const MIME_TO_AUDIO_EXT = {
|
|
11
|
+
'audio/ogg': '.ogg', 'audio/mpeg': '.mp3', 'audio/mp4': '.m4a',
|
|
12
|
+
'audio/wav': '.wav', 'audio/webm': '.webm', 'audio/flac': '.flac',
|
|
13
|
+
'audio/x-m4a': '.m4a', 'audio/mp3': '.mp3',
|
|
14
|
+
};
|
|
15
|
+
// MIME type to file extension mapping (includes images and video)
|
|
16
|
+
export const MIME_EXT = {
|
|
17
|
+
'image/jpeg': '.jpg',
|
|
18
|
+
'image/png': '.png',
|
|
19
|
+
'image/gif': '.gif',
|
|
20
|
+
'image/webp': '.webp',
|
|
21
|
+
'image/bmp': '.bmp',
|
|
22
|
+
'image/svg+xml': '.svg',
|
|
23
|
+
'audio/ogg': '.ogg',
|
|
24
|
+
'audio/mpeg': '.mp3',
|
|
25
|
+
'audio/mp4': '.m4a',
|
|
26
|
+
'video/mp4': '.mp4',
|
|
27
|
+
'application/pdf': '.pdf',
|
|
28
|
+
};
|
|
29
|
+
// Media type to default MIME type mapping (for fallback when MIME is unknown)
|
|
30
|
+
export const MEDIA_TYPE_MIME_DEFAULTS = {
|
|
31
|
+
image: 'image/jpeg',
|
|
32
|
+
audio: 'audio/ogg',
|
|
33
|
+
video: 'video/mp4',
|
|
34
|
+
document: 'application/pdf',
|
|
35
|
+
};
|
|
36
|
+
// Extension to MIME type mapping (inverse of MIME_EXT, includes common variations)
|
|
37
|
+
export const EXT_TO_MIME = {
|
|
38
|
+
'.jpg': 'image/jpeg', '.jpeg': 'image/jpeg',
|
|
39
|
+
'.png': 'image/png', '.gif': 'image/gif', '.webp': 'image/webp',
|
|
40
|
+
'.mp4': 'video/mp4', '.mp3': 'audio/mpeg',
|
|
41
|
+
'.ogg': 'audio/ogg', '.m4a': 'audio/mp4',
|
|
42
|
+
'.pdf': 'application/pdf',
|
|
43
|
+
'.txt': 'text/plain', '.md': 'text/markdown',
|
|
44
|
+
'.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
45
|
+
'.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
46
|
+
};
|
|
47
|
+
// Typed MIME constants by media type
|
|
48
|
+
export const IMAGE_MIMES = {
|
|
49
|
+
'image/jpeg': true,
|
|
50
|
+
'image/png': true,
|
|
51
|
+
'image/gif': true,
|
|
52
|
+
'image/webp': true,
|
|
53
|
+
'image/bmp': true,
|
|
54
|
+
'image/svg+xml': true,
|
|
55
|
+
};
|
|
56
|
+
export const AUDIO_MIMES = {
|
|
57
|
+
'audio/ogg': true,
|
|
58
|
+
'audio/mpeg': true,
|
|
59
|
+
'audio/mp4': true,
|
|
60
|
+
'audio/wav': true,
|
|
61
|
+
'audio/webm': true,
|
|
62
|
+
'audio/flac': true,
|
|
63
|
+
'audio/x-m4a': true,
|
|
64
|
+
'audio/mp3': true,
|
|
65
|
+
};
|
|
66
|
+
export const VIDEO_MIMES = {
|
|
67
|
+
'video/mp4': true,
|
|
68
|
+
};
|
|
69
|
+
export const DOCUMENT_MIMES = {
|
|
70
|
+
'text/plain': true,
|
|
71
|
+
'text/markdown': true,
|
|
72
|
+
'application/pdf': true,
|
|
73
|
+
'application/vnd.openxmlformats-officedocument.wordprocessingml.document': true,
|
|
74
|
+
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': true,
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Get file extension for MIME type
|
|
78
|
+
*/
|
|
79
|
+
export function extFromMime(mimeType) {
|
|
80
|
+
return MIME_EXT[mimeType] || '.bin';
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Get MIME type from file extension
|
|
84
|
+
*/
|
|
85
|
+
export function getMimeTypeFromExt(ext) {
|
|
86
|
+
return EXT_TO_MIME[ext.toLowerCase()] || 'image/jpeg';
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Normalize API base URL by removing trailing /v1 (or /v1/)
|
|
90
|
+
* Supports both formats: 'https://api.openai.com' and 'https://api.openai.com/v1'
|
|
91
|
+
*/
|
|
92
|
+
export function normalizeApiBaseUrl(baseUrl) {
|
|
93
|
+
let url = baseUrl ?? 'https://api.openai.com';
|
|
94
|
+
// Remove trailing /v1 or /v1/ if present
|
|
95
|
+
url = url.replace(/\/v1\/?$/, '');
|
|
96
|
+
return url;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=media-transcribe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media-transcribe.js","sourceRoot":"","sources":["../../lib/media-transcribe.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,6CAA6C;AAC7C,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAE1H,uCAAuC;AACvC,MAAM,CAAC,MAAM,iBAAiB,GAA2B;IACvD,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM;IAC9D,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO;IACjE,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM;CAC3C,CAAC;AAEF,kEAAkE;AAClE,MAAM,CAAC,MAAM,QAAQ,GAA2B;IAC9C,YAAY,EAAE,MAAM;IACpB,WAAW,EAAE,MAAM;IACnB,WAAW,EAAE,MAAM;IACnB,YAAY,EAAE,OAAO;IACrB,WAAW,EAAE,MAAM;IACnB,eAAe,EAAE,MAAM;IACvB,WAAW,EAAE,MAAM;IACnB,YAAY,EAAE,MAAM;IACpB,WAAW,EAAE,MAAM;IACnB,WAAW,EAAE,MAAM;IACnB,iB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AE,IAAI;IACvB,yEAAyE,EAAE,IAAI;IAC/E,mEAAmE,EAAE,IAAI;CACjE,CAAC;AAOX;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,QAAgB;IAC1C,OAAO,QAAQ,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC;AACtC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAW;IAC5C,OAAO,WAAW,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,IAAI,YAAY,CAAC;AACxD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAgB;IAClD,IAAI,GAAG,GAAG,OAAO,IAAI,wBAAwB,CAAC;IAC9C,yCAAyC;IACzC,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAClC,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../../lib/media.ts"],"names":[],"mappings":"AAKA,wBAAsB,SAAS,CAAC,MAAM,EAAE;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG,OAAO,CAAC,MAAM,CAAC,CAelB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { extFromMime } from './media-transcribe.js';
|
|
5
|
+
export async function saveMedia(params) {
|
|
6
|
+
const dir = path.join(params.mediaDir, params.sessionKey.replace(/:/g, '-'));
|
|
7
|
+
await mkdir(dir, { recursive: true });
|
|
8
|
+
const now = new Date();
|
|
9
|
+
const date = now.toISOString().slice(0, 10);
|
|
10
|
+
const time = now.toISOString().slice(11, 19).replace(/:/g, '');
|
|
11
|
+
const hash = createHash('sha256').update(params.buffer).digest('hex').slice(0, 4);
|
|
12
|
+
const ext = extFromMime(params.mimeType);
|
|
13
|
+
const filename = `${date}_${time}_${hash}${ext}`;
|
|
14
|
+
const filepath = path.join(dir, filename);
|
|
15
|
+
await writeFile(filepath, params.buffer);
|
|
16
|
+
return filepath;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=media.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media.js","sourceRoot":"","sources":["../../lib/media.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpD,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,MAK/B;IACC,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;IAC7E,MAAM,KAAK,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAEtC,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,MAAM,IAAI,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC5C,MAAM,IAAI,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAC/D,MAAM,IAAI,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAClF,MAAM,GAAG,GAAG,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAEzC,MAAM,QAAQ,GAAG,GAAG,IAAI,IAAI,IAAI,IAAI,IAAI,GAAG,GAAG,EAAE,CAAC;IACjD,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAE1C,MAAM,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACzC,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mime.d.ts","sourceRoot":"","sources":["../../lib/mime.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAsB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA2EpE"}
|
package/dist/lib/mime.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIME type detection from file buffer
|
|
3
|
+
* Simple implementation based on magic numbers
|
|
4
|
+
*/
|
|
5
|
+
export async function detectMimeType(buffer) {
|
|
6
|
+
// Check magic numbers
|
|
7
|
+
if (buffer.length < 4) {
|
|
8
|
+
return 'application/octet-stream';
|
|
9
|
+
}
|
|
10
|
+
const hex = buffer.toString('hex', 0, 4);
|
|
11
|
+
// PNG
|
|
12
|
+
if (hex.startsWith('89504e47')) {
|
|
13
|
+
return 'image/png';
|
|
14
|
+
}
|
|
15
|
+
// JPEG
|
|
16
|
+
if (hex.startsWith('ffd8ff')) {
|
|
17
|
+
return 'image/jpeg';
|
|
18
|
+
}
|
|
19
|
+
// GIF
|
|
20
|
+
if (hex.startsWith('47494638')) {
|
|
21
|
+
return 'image/gif';
|
|
22
|
+
}
|
|
23
|
+
// WebP
|
|
24
|
+
if (hex.startsWith('52494646') && buffer.length >= 12) {
|
|
25
|
+
const webpHex = buffer.toString('hex', 8, 12);
|
|
26
|
+
if (webpHex.startsWith('57454250')) {
|
|
27
|
+
return 'image/webp';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
// BMP
|
|
31
|
+
if (hex.startsWith('424d')) {
|
|
32
|
+
return 'image/bmp';
|
|
33
|
+
}
|
|
34
|
+
// SVG (check content)
|
|
35
|
+
const contentStart = buffer.toString('utf-8', 0, Math.min(100, buffer.length));
|
|
36
|
+
if (contentStart.includes('<?xml') && contentStart.includes('<svg')) {
|
|
37
|
+
return 'image/svg+xml';
|
|
38
|
+
}
|
|
39
|
+
if (contentStart.includes('<svg')) {
|
|
40
|
+
return 'image/svg+xml';
|
|
41
|
+
}
|
|
42
|
+
// Text files
|
|
43
|
+
const textContent = buffer.toString('utf-8', 0, Math.min(100, buffer.length));
|
|
44
|
+
if (textContent.includes('<?xml')) {
|
|
45
|
+
return 'application/xml';
|
|
46
|
+
}
|
|
47
|
+
if (textContent.includes('<!DOCTYPE html') || textContent.includes('<html')) {
|
|
48
|
+
return 'text/html';
|
|
49
|
+
}
|
|
50
|
+
if (textContent.includes('{') || textContent.includes('[')) {
|
|
51
|
+
// Might be JSON
|
|
52
|
+
try {
|
|
53
|
+
JSON.parse(textContent.slice(0, textContent.indexOf('\n')) || textContent);
|
|
54
|
+
return 'application/json';
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// Not valid JSON
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// Check if mostly printable (text)
|
|
61
|
+
const printable = buffer.slice(0, Math.min(100, buffer.length)).toString('utf-8');
|
|
62
|
+
const nonPrintable = [...printable].filter(c => {
|
|
63
|
+
const code = c.charCodeAt(0);
|
|
64
|
+
return code < 32 && code !== 9 && code !== 10 && code !== 13;
|
|
65
|
+
}).length;
|
|
66
|
+
if (nonPrintable === 0) {
|
|
67
|
+
return 'text/plain';
|
|
68
|
+
}
|
|
69
|
+
return 'application/octet-stream';
|
|
70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AC,CAAC;IAClF,MAAM,YAAY,GAAG,CAAC,GAAG,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE;QAC7C,MAAM,IAAI,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAC7B,OAAO,IAAI,GAAG,EAAE,IAAI,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,EAAE,IAAI,IAAI,KAAK,EAAE,CAAC;IAC/D,CAAC,CAAC,CAAC,MAAM,CAAC;IAEV,IAAI,YAAY,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,OAAO,0BAA0B,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paginate.d.ts","sourceRoot":"","sources":["../../lib/paginate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,IAAI,GAAE,MAAU,EAAE,KAAK,GAAE,MAAW,GAAG,UAAU,CAAC,CAAC,CAAC,CAG3F"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paginate.js","sourceRoot":"","sources":["../../lib/paginate.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,QAAQ,CAAI,KAAU,EAAE,OAAe,CAAC,EAAE,QAAgB,EAAE;IAC1E,MAAM,KAAK,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC;IACjC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AACnE,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface DataPaths {
|
|
2
|
+
dataDir: string;
|
|
3
|
+
workspaceDir: string;
|
|
4
|
+
sessionsDir: string;
|
|
5
|
+
channelsDir: string;
|
|
6
|
+
cronDir: string;
|
|
7
|
+
logsDir: string;
|
|
8
|
+
cacheDir: string;
|
|
9
|
+
configFile: string;
|
|
10
|
+
}
|
|
11
|
+
/** Cached singleton — reads $VARGOS_DATA_DIR or ~/.vargos on first call. */
|
|
12
|
+
export declare function getDataPaths(): DataPaths;
|
|
13
|
+
export declare function resetDataPaths(): void;
|
|
14
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../lib/paths.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACpB;AAID,4EAA4E;AAC5E,wBAAgB,YAAY,IAAI,SAAS,CAyBxC;AAED,wBAAgB,cAAc,IAAI,IAAI,CAAmB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
let _cache = null;
|
|
4
|
+
/** Cached singleton — reads $VARGOS_DATA_DIR or ~/.vargos on first call. */
|
|
5
|
+
export function getDataPaths() {
|
|
6
|
+
if (_cache)
|
|
7
|
+
return _cache;
|
|
8
|
+
const env = process.env.VARGOS_DATA_DIR?.trim();
|
|
9
|
+
const dataDir = env
|
|
10
|
+
? (env.startsWith('~') ? path.join(os.homedir(), env.slice(1)) : env)
|
|
11
|
+
: path.join(os.homedir(), '.vargos');
|
|
12
|
+
const xdg = process.env.XDG_CACHE_HOME?.trim();
|
|
13
|
+
const base = xdg
|
|
14
|
+
? (xdg.startsWith('~') ? path.join(os.homedir(), xdg.slice(1)) : xdg)
|
|
15
|
+
: path.join(os.homedir(), '.cache');
|
|
16
|
+
_cache = {
|
|
17
|
+
dataDir,
|
|
18
|
+
workspaceDir: path.join(dataDir, 'workspace'),
|
|
19
|
+
sessionsDir: path.join(dataDir, 'sessions'),
|
|
20
|
+
channelsDir: path.join(dataDir, 'channels'),
|
|
21
|
+
cronDir: path.join(dataDir, 'cron'),
|
|
22
|
+
logsDir: path.join(dataDir, 'logs'),
|
|
23
|
+
cacheDir: path.join(base, 'vargos'),
|
|
24
|
+
configFile: path.join(dataDir, 'config.json'),
|
|
25
|
+
};
|
|
26
|
+
return _cache;
|
|
27
|
+
}
|
|
28
|
+
export function resetDataPaths() { _cache = null; }
|
|
29
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../lib/paths.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,SAAS,CAAC;AAazB,IAAI,MAAM,GAAqB,IAAI,CAAC;AAEpC,4EAA4E;AAC5E,MAAM,UAAU,YAAY;IAC1B,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC;IAE1B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,IAAI,EAAE,CAAC;IAChD,MAAM,OAAO,GAAG,GAAG;QACjB,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QACrE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,CAAC,CAAC;IAEvC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,EAAE,CAAC;IAC/C,MAAM,IAAI,GAAG,GAAG;QACd,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QACrE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,QAAQ,CAAC,CAAC;IAEtC,MAAM,GAAG;QACP,OAAO;QACP,YAAY,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC;QAC7C,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC;QAC3C,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC;QAC3C,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC;QACnC,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC;QACnC,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC;QACnC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,aAAa,CAAC;KAC9C,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,cAAc,KAAW,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic dynamic provider loader — reusable across services.
|
|
3
|
+
* Supports lazy-loaded providers with error handling and logging.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Loads and returns providers from a registry of lazy loaders.
|
|
7
|
+
* Logs warnings for failed providers, continues loading others.
|
|
8
|
+
*/
|
|
9
|
+
export declare function loadProviders<T>(providerRegistry: Record<string, () => Promise<T>>): Promise<T[]>;
|
|
10
|
+
//# sourceMappingURL=provider-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-loader.d.ts","sourceRoot":"","sources":["../../lib/provider-loader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH;;;GAGG;AACH,wBAAsB,aAAa,CAAC,CAAC,EACnC,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC,GACjD,OAAO,CAAC,CAAC,EAAE,CAAC,CAWd"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic dynamic provider loader — reusable across services.
|
|
3
|
+
* Supports lazy-loaded providers with error handling and logging.
|
|
4
|
+
*/
|
|
5
|
+
import { createLogger } from './logger.js';
|
|
6
|
+
const log = createLogger('provider-loader');
|
|
7
|
+
/**
|
|
8
|
+
* Loads and returns providers from a registry of lazy loaders.
|
|
9
|
+
* Logs warnings for failed providers, continues loading others.
|
|
10
|
+
*/
|
|
11
|
+
export async function loadProviders(providerRegistry) {
|
|
12
|
+
const loaded = [];
|
|
13
|
+
for (const [name, loader] of Object.entries(providerRegistry)) {
|
|
14
|
+
try {
|
|
15
|
+
const provider = await loader();
|
|
16
|
+
loaded.push(provider);
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
log.warn(`failed to load provider "${name}": ${err instanceof Error ? err.message : String(err)}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return loaded;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=provider-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-loader.js","sourceRoot":"","sources":["../../lib/provider-loader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,GAAG,GAAG,YAAY,CAAC,iBAAiB,CAAC,CAAC;AAE5C;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,gBAAkD;IAElD,MAAM,MAAM,GAAQ,EAAE,CAAC;IACvB,KAAK,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAAE,CAAC;QAC9D,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,MAAM,EAAE,CAAC;YAChC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACxB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,GAAG,CAAC,IAAI,CAAC,4BAA4B,IAAI,MAAM,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACrG,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured retry with exponential backoff.
|
|
3
|
+
* Pure utility — no domain imports, no side effects beyond timing.
|
|
4
|
+
*/
|
|
5
|
+
export interface RetryConfig {
|
|
6
|
+
/** Max number of retry attempts after initial failure. Default: 3 */
|
|
7
|
+
maxRetries?: number;
|
|
8
|
+
/** Base delay in ms for backoff calculation. Default: 1000 */
|
|
9
|
+
baseMs?: number;
|
|
10
|
+
/** Maximum delay cap in ms. Default: 30_000 */
|
|
11
|
+
maxMs?: number;
|
|
12
|
+
/** Add up to 25% random jitter to each delay. Default: true */
|
|
13
|
+
jitter?: boolean;
|
|
14
|
+
/** Return false to rethrow immediately without retrying. Default: always retry */
|
|
15
|
+
shouldRetry?: (error: unknown) => boolean;
|
|
16
|
+
/** Abort mid-retry on signal cancellation */
|
|
17
|
+
signal?: AbortSignal;
|
|
18
|
+
}
|
|
19
|
+
export declare function withRetry<T>(fn: () => Promise<T>, config?: RetryConfig): Promise<T>;
|
|
20
|
+
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../lib/retry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,WAAW,WAAW;IAC1B,qEAAqE;IACrE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8DAA8D;IAC9D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+DAA+D;IAC/D,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,kFAAkF;IAClF,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;IAC1C,6CAA6C;IAC7C,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AASD,wBAAsB,SAAS,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CA+BzF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured retry with exponential backoff.
|
|
3
|
+
* Pure utility — no domain imports, no side effects beyond timing.
|
|
4
|
+
*/
|
|
5
|
+
import { sleep } from './sleep.js';
|
|
6
|
+
function computeDelay(attempt, baseMs, maxMs, jitter) {
|
|
7
|
+
const base = Math.min(baseMs * 2 ** attempt, maxMs);
|
|
8
|
+
// Jitter adds 0–25% of the capped delay to spread retries
|
|
9
|
+
const extra = jitter ? Math.random() * 0.25 * base : 0;
|
|
10
|
+
return base + extra;
|
|
11
|
+
}
|
|
12
|
+
export async function withRetry(fn, config) {
|
|
13
|
+
const maxRetries = config?.maxRetries ?? 3;
|
|
14
|
+
const baseMs = config?.baseMs ?? 1000;
|
|
15
|
+
const maxMs = config?.maxMs ?? 30_000;
|
|
16
|
+
const jitter = config?.jitter ?? true;
|
|
17
|
+
const shouldRetry = config?.shouldRetry ?? (() => true);
|
|
18
|
+
const signal = config?.signal;
|
|
19
|
+
let lastError;
|
|
20
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
21
|
+
try {
|
|
22
|
+
return await fn();
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
lastError = err;
|
|
26
|
+
if (!shouldRetry(err))
|
|
27
|
+
throw err;
|
|
28
|
+
if (signal?.aborted) {
|
|
29
|
+
throw signal.reason ?? new DOMException('Aborted', 'AbortError');
|
|
30
|
+
}
|
|
31
|
+
// No delay after final attempt — just fall through and rethrow
|
|
32
|
+
if (attempt === maxRetries)
|
|
33
|
+
break;
|
|
34
|
+
const delay = computeDelay(attempt, baseMs, maxMs, jitter);
|
|
35
|
+
await sleep(delay, signal);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
throw lastError;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=retry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../../lib/retry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAiBnC,SAAS,YAAY,CAAC,OAAe,EAAE,MAAc,EAAE,KAAa,EAAE,MAAe;IACnF,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,EAAE,KAAK,CAAC,CAAC;IACpD,0DAA0D;IAC1D,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IACvD,OAAO,IAAI,GAAG,KAAK,CAAC;AACtB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS,CAAI,EAAoB,EAAE,MAAoB;IAC3E,MAAM,UAAU,GAAG,MAAM,EAAE,UAAU,IAAI,CAAC,CAAC;IAC3C,MAAM,MAAM,GAAG,MAAM,EAAE,MAAM,IAAI,IAAI,CAAC;IACtC,MAAM,KAAK,GAAG,MAAM,EAAE,KAAK,IAAI,MAAM,CAAC;IACtC,MAAM,MAAM,GAAG,MAAM,EAAE,MAAM,IAAI,IAAI,CAAC;IACtC,MAAM,WAAW,GAAG,MAAM,EAAE,WAAW,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;IACxD,MAAM,MAAM,GAAG,MAAM,EAAE,MAAM,CAAC;IAE9B,IAAI,SAAkB,CAAC;IAEvB,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,IAAI,UAAU,EAAE,OAAO,EAAE,EAAE,CAAC;QACvD,IAAI,CAAC;YACH,OAAO,MAAM,EAAE,EAAE,CAAC;QACpB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,SAAS,GAAG,GAAG,CAAC;YAEhB,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC;gBAAE,MAAM,GAAG,CAAC;YAEjC,IAAI,MAAM,EAAE,OAAO,EAAE,CAAC;gBACpB,MAAM,MAAM,CAAC,MAAM,IAAI,IAAI,YAAY,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;YACnE,CAAC;YAED,+DAA+D;YAC/D,IAAI,OAAO,KAAK,UAAU;gBAAE,MAAM;YAElC,MAAM,KAAK,GAAG,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;YAC3D,MAAM,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;IAED,MAAM,SAAS,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safe async execution utilities — centralized error context and handling.
|
|
3
|
+
* Reduces boilerplate in services that wrap async operations with logging.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Execute async operation with automatic error logging.
|
|
7
|
+
* Returns result or undefined if operation throws.
|
|
8
|
+
*/
|
|
9
|
+
export declare function safeAwait<T>(promise: Promise<T>, context: {
|
|
10
|
+
operation: string;
|
|
11
|
+
service: string;
|
|
12
|
+
log: {
|
|
13
|
+
error(msg: string, data?: unknown): void;
|
|
14
|
+
};
|
|
15
|
+
}): Promise<T | undefined>;
|
|
16
|
+
/**
|
|
17
|
+
* Wrap async function with error context logging.
|
|
18
|
+
* Useful for event handlers and callbacks.
|
|
19
|
+
*/
|
|
20
|
+
export declare function withErrorContext<Args extends unknown[], R>(fn: (...args: Args) => Promise<R>, context: {
|
|
21
|
+
operation: string;
|
|
22
|
+
service: string;
|
|
23
|
+
log: {
|
|
24
|
+
error(msg: string, data?: unknown): void;
|
|
25
|
+
};
|
|
26
|
+
}): (...args: Args) => Promise<R | undefined>;
|
|
27
|
+
//# sourceMappingURL=safe-async.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safe-async.d.ts","sourceRoot":"","sources":["../../lib/safe-async.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;GAGG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAC/B,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,OAAO,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE;QAAE,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;KAAE,CAAA;CAAE,GACjG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CASxB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,SAAS,OAAO,EAAE,EAAE,CAAC,EACxD,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,EACjC,OAAO,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE;QAAE,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;KAAE,CAAA;CAAE,GACjG,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAW3C"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safe async execution utilities — centralized error context and handling.
|
|
3
|
+
* Reduces boilerplate in services that wrap async operations with logging.
|
|
4
|
+
*/
|
|
5
|
+
import { toMessage } from './error.js';
|
|
6
|
+
/**
|
|
7
|
+
* Execute async operation with automatic error logging.
|
|
8
|
+
* Returns result or undefined if operation throws.
|
|
9
|
+
*/
|
|
10
|
+
export async function safeAwait(promise, context) {
|
|
11
|
+
try {
|
|
12
|
+
return await promise;
|
|
13
|
+
}
|
|
14
|
+
catch (err) {
|
|
15
|
+
context.log.error(`${context.operation} failed in ${context.service}`, {
|
|
16
|
+
error: toMessage(err),
|
|
17
|
+
});
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Wrap async function with error context logging.
|
|
23
|
+
* Useful for event handlers and callbacks.
|
|
24
|
+
*/
|
|
25
|
+
export function withErrorContext(fn, context) {
|
|
26
|
+
return async (...args) => {
|
|
27
|
+
try {
|
|
28
|
+
return await fn(...args);
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
context.log.error(`${context.operation} failed`, {
|
|
32
|
+
error: toMessage(err),
|
|
33
|
+
});
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=safe-async.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safe-async.js","sourceRoot":"","sources":["../../lib/safe-async.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,OAAmB,EACnB,OAAkG;IAElG,IAAI,CAAC;QACH,OAAO,MAAM,OAAO,CAAC;IACvB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,SAAS,cAAc,OAAO,CAAC,OAAO,EAAE,EAAE;YACrE,KAAK,EAAE,SAAS,CAAC,GAAG,CAAC;SACtB,CAAC,CAAC;QACH,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAC9B,EAAiC,EACjC,OAAkG;IAElG,OAAO,KAAK,EAAE,GAAG,IAAU,EAAE,EAAE;QAC7B,IAAI,CAAC;YACH,OAAO,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;QAC3B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,SAAS,SAAS,EAAE;gBAC/C,KAAK,EAAE,SAAS,CAAC,GAAG,CAAC;aACtB,CAAC,CAAC;YACH,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve `<root>/skills/` for each input root, filtered to directories that exist on disk.
|
|
3
|
+
* Order is preserved (caller-defined precedence). Used to feed Pi SDK's `additionalSkillPaths`.
|
|
4
|
+
*
|
|
5
|
+
* Pi SDK's `DefaultResourceLoader` already auto-loads `<agentDir>/skills/` and
|
|
6
|
+
* `<cwd>/.pi/skills/` — don't pass those here, they'd double-load.
|
|
7
|
+
*/
|
|
8
|
+
export declare function resolveSkillPaths(...roots: string[]): string[];
|
|
9
|
+
//# sourceMappingURL=skills.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skills.d.ts","sourceRoot":"","sources":["../../lib/skills.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAI9D"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
/**
|
|
4
|
+
* Resolve `<root>/skills/` for each input root, filtered to directories that exist on disk.
|
|
5
|
+
* Order is preserved (caller-defined precedence). Used to feed Pi SDK's `additionalSkillPaths`.
|
|
6
|
+
*
|
|
7
|
+
* Pi SDK's `DefaultResourceLoader` already auto-loads `<agentDir>/skills/` and
|
|
8
|
+
* `<cwd>/.pi/skills/` — don't pass those here, they'd double-load.
|
|
9
|
+
*/
|
|
10
|
+
export function resolveSkillPaths(...roots) {
|
|
11
|
+
return roots
|
|
12
|
+
.map(p => path.join(p, 'skills'))
|
|
13
|
+
.filter(p => existsSync(p));
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=skills.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skills.js","sourceRoot":"","sources":["../../lib/skills.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,GAAG,KAAe;IAClD,OAAO,KAAK;SACT,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;SAChC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sleep.d.ts","sourceRoot":"","sources":["../../lib/sleep.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAmBrE"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interruptible sleep utility.
|
|
3
|
+
* Resolves after `ms` milliseconds, or rejects early if the signal is aborted.
|
|
4
|
+
*/
|
|
5
|
+
export function sleep(ms, signal) {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
if (signal?.aborted) {
|
|
8
|
+
reject(signal.reason ?? new DOMException('Aborted', 'AbortError'));
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const onAbort = () => {
|
|
12
|
+
clearTimeout(timer);
|
|
13
|
+
reject(signal.reason ?? new DOMException('Aborted', 'AbortError'));
|
|
14
|
+
};
|
|
15
|
+
const timer = setTimeout(() => {
|
|
16
|
+
signal?.removeEventListener('abort', onAbort);
|
|
17
|
+
resolve();
|
|
18
|
+
}, ms);
|
|
19
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=sleep.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sleep.js","sourceRoot":"","sources":["../../lib/sleep.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,KAAK,CAAC,EAAU,EAAE,MAAoB;IACpD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,IAAI,MAAM,EAAE,OAAO,EAAE,CAAC;YACpB,MAAM,CAAC,MAAM,CAAC,MAAM,IAAI,IAAI,YAAY,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC;YACnE,OAAO;QACT,CAAC;QAED,MAAM,OAAO,GAAG,GAAG,EAAE;YACnB,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,MAAM,CAAC,MAAO,CAAC,MAAM,IAAI,IAAI,YAAY,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC;QACtE,CAAC,CAAC;QAEF,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YAC5B,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC9C,OAAO,EAAE,CAAC;QACZ,CAAC,EAAE,EAAE,CAAC,CAAC;QAEP,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7D,CAAC,CAAC,CAAC;AACL,CAAC"}
|