ultracode-shared 1.3.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/LICENSE +21 -0
- package/README.md +30 -0
- package/dist/constants.d.ts +33 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +37 -0
- package/dist/constants.js.map +1 -0
- package/dist/errors.d.ts +113 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +155 -0
- package/dist/errors.js.map +1 -0
- package/dist/events/EventBus.d.ts +36 -0
- package/dist/events/EventBus.d.ts.map +1 -0
- package/dist/events/EventBus.js +83 -0
- package/dist/events/EventBus.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +65 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +74 -0
- package/dist/logger.js.map +1 -0
- package/dist/types/agent.d.ts +68 -0
- package/dist/types/agent.d.ts.map +1 -0
- package/dist/types/agent.js +9 -0
- package/dist/types/agent.js.map +1 -0
- package/dist/types/config.d.ts +265 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +103 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/events.d.ts +78 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/events.js +10 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/memory.d.ts +53 -0
- package/dist/types/memory.d.ts.map +1 -0
- package/dist/types/memory.js +9 -0
- package/dist/types/memory.js.map +1 -0
- package/dist/types/provider.d.ts +129 -0
- package/dist/types/provider.d.ts.map +1 -0
- package/dist/types/provider.js +10 -0
- package/dist/types/provider.js.map +1 -0
- package/dist/types/tool.d.ts +122 -0
- package/dist/types/tool.d.ts.map +1 -0
- package/dist/types/tool.js +11 -0
- package/dist/types/tool.js.map +1 -0
- package/dist/types/versioning.d.ts +141 -0
- package/dist/types/versioning.d.ts.map +1 -0
- package/dist/types/versioning.js +8 -0
- package/dist/types/versioning.js.map +1 -0
- package/dist/utils/async.d.ts +17 -0
- package/dist/utils/async.d.ts.map +1 -0
- package/dist/utils/async.js +45 -0
- package/dist/utils/async.js.map +1 -0
- package/dist/utils/id.d.ts +13 -0
- package/dist/utils/id.d.ts.map +1 -0
- package/dist/utils/id.js +17 -0
- package/dist/utils/id.js.map +1 -0
- package/dist/utils/index.d.ts +11 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +10 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/math.d.ts +15 -0
- package/dist/utils/math.d.ts.map +1 -0
- package/dist/utils/math.js +25 -0
- package/dist/utils/math.js.map +1 -0
- package/dist/utils/object.d.ts +36 -0
- package/dist/utils/object.d.ts.map +1 -0
- package/dist/utils/object.js +122 -0
- package/dist/utils/object.js.map +1 -0
- package/dist/utils/serializeError.d.ts +15 -0
- package/dist/utils/serializeError.d.ts.map +1 -0
- package/dist/utils/serializeError.js +69 -0
- package/dist/utils/serializeError.js.map +1 -0
- package/dist/utils/truncate.d.ts +29 -0
- package/dist/utils/truncate.d.ts.map +1 -0
- package/dist/utils/truncate.js +42 -0
- package/dist/utils/truncate.js.map +1 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 UltraCode Team / SIMO GmbH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# ultracode-shared
|
|
2
|
+
|
|
3
|
+
> Shared types, contracts, errors and utilities for UltraCode AI.
|
|
4
|
+
|
|
5
|
+
Part of the [UltraCode AI](https://github.com/AndreasSchwan-SIMO/UltraCode) monorepo.
|
|
6
|
+
This is an internal foundation package consumed by
|
|
7
|
+
[`ultracode-core`](https://www.npmjs.com/package/ultracode-core) and the
|
|
8
|
+
[`ultracode`](https://www.npmjs.com/package/ultracode) CLI.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install ultracode-shared
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Requires Node.js `>=22.13.0`. ESM only.
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { /* types, contracts, error classes, utilities */ } from "ultracode-shared";
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Provides the cross-package type definitions, interface contracts, the typed error
|
|
25
|
+
model (e.g. `VersioningError`, `ProviderError`, `SessionError`, `ToolError`) and
|
|
26
|
+
small shared utilities used throughout UltraCode AI.
|
|
27
|
+
|
|
28
|
+
## License
|
|
29
|
+
|
|
30
|
+
[MIT](./LICENSE) © UltraCode AI Team / SIMO GmbH
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project-wide constants shared across UltraCode packages.
|
|
3
|
+
*/
|
|
4
|
+
/** Current package/protocol version. */
|
|
5
|
+
export declare const VERSION: "0.1.0";
|
|
6
|
+
/**
|
|
7
|
+
* Candidate project-level config file names, in resolution order
|
|
8
|
+
* (first match wins). Paths are relative to the project root.
|
|
9
|
+
*/
|
|
10
|
+
export declare const CONFIG_FILE_NAMES: readonly [".ultracode/config.toml", ".vibe/config.toml", ".ultracode.toml"];
|
|
11
|
+
/** User-level config directory (tilde-prefixed; expanded by the loader). */
|
|
12
|
+
export declare const USER_CONFIG_DIR: "~/.ultracode";
|
|
13
|
+
/** User-level config file path. */
|
|
14
|
+
export declare const USER_CONFIG_FILE: "~/.ultracode/config.toml";
|
|
15
|
+
/** User-level `.env` file path holding API keys. */
|
|
16
|
+
export declare const USER_ENV_FILE: "~/.ultracode/.env";
|
|
17
|
+
/** Prefix for UltraCode-specific environment variables (e.g. `ULTRACODE_DEBUG`). */
|
|
18
|
+
export declare const ENV_PREFIX: "ULTRACODE_";
|
|
19
|
+
/** Default directory for persisted sessions. */
|
|
20
|
+
export declare const DEFAULT_SESSION_DIR: "~/.ultracode/sessions";
|
|
21
|
+
/** Directory holding user-authored system prompts. */
|
|
22
|
+
export declare const PROMPTS_DIR: "~/.ultracode/prompts";
|
|
23
|
+
/** Hard cap on a single tool's output, in characters, before truncation. */
|
|
24
|
+
export declare const MAX_TOOL_OUTPUT_CHARS: 100000;
|
|
25
|
+
/** Default per-request provider timeout, in milliseconds. */
|
|
26
|
+
export declare const DEFAULT_PROVIDER_TIMEOUT_MS: 60000;
|
|
27
|
+
/** Default maximum provider retry attempts. */
|
|
28
|
+
export declare const DEFAULT_MAX_RETRIES: 3;
|
|
29
|
+
/** Default base retry delay, in milliseconds. */
|
|
30
|
+
export declare const DEFAULT_RETRY_DELAY_MS: 1000;
|
|
31
|
+
/** Default changelog file name. */
|
|
32
|
+
export declare const DEFAULT_CHANGELOG_FILE: "CHANGELOG.md";
|
|
33
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,wCAAwC;AACxC,eAAO,MAAM,OAAO,EAAG,OAAgB,CAAC;AAExC;;;GAGG;AACH,eAAO,MAAM,iBAAiB,6EAIpB,CAAC;AAEX,4EAA4E;AAC5E,eAAO,MAAM,eAAe,EAAG,cAAuB,CAAC;AAEvD,mCAAmC;AACnC,eAAO,MAAM,gBAAgB,EAAG,0BAAmC,CAAC;AAEpE,oDAAoD;AACpD,eAAO,MAAM,aAAa,EAAG,mBAA4B,CAAC;AAE1D,oFAAoF;AACpF,eAAO,MAAM,UAAU,EAAG,YAAqB,CAAC;AAEhD,gDAAgD;AAChD,eAAO,MAAM,mBAAmB,EAAG,uBAAgC,CAAC;AAEpE,sDAAsD;AACtD,eAAO,MAAM,WAAW,EAAG,sBAA+B,CAAC;AAE3D,4EAA4E;AAC5E,eAAO,MAAM,qBAAqB,EAAG,MAAgB,CAAC;AAEtD,6DAA6D;AAC7D,eAAO,MAAM,2BAA2B,EAAG,KAAe,CAAC;AAE3D,+CAA+C;AAC/C,eAAO,MAAM,mBAAmB,EAAG,CAAU,CAAC;AAE9C,iDAAiD;AACjD,eAAO,MAAM,sBAAsB,EAAG,IAAc,CAAC;AAErD,mCAAmC;AACnC,eAAO,MAAM,sBAAsB,EAAG,cAAuB,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project-wide constants shared across UltraCode packages.
|
|
3
|
+
*/
|
|
4
|
+
/** Current package/protocol version. */
|
|
5
|
+
export const VERSION = "0.1.0";
|
|
6
|
+
/**
|
|
7
|
+
* Candidate project-level config file names, in resolution order
|
|
8
|
+
* (first match wins). Paths are relative to the project root.
|
|
9
|
+
*/
|
|
10
|
+
export const CONFIG_FILE_NAMES = [
|
|
11
|
+
".ultracode/config.toml",
|
|
12
|
+
".vibe/config.toml",
|
|
13
|
+
".ultracode.toml",
|
|
14
|
+
];
|
|
15
|
+
/** User-level config directory (tilde-prefixed; expanded by the loader). */
|
|
16
|
+
export const USER_CONFIG_DIR = "~/.ultracode";
|
|
17
|
+
/** User-level config file path. */
|
|
18
|
+
export const USER_CONFIG_FILE = "~/.ultracode/config.toml";
|
|
19
|
+
/** User-level `.env` file path holding API keys. */
|
|
20
|
+
export const USER_ENV_FILE = "~/.ultracode/.env";
|
|
21
|
+
/** Prefix for UltraCode-specific environment variables (e.g. `ULTRACODE_DEBUG`). */
|
|
22
|
+
export const ENV_PREFIX = "ULTRACODE_";
|
|
23
|
+
/** Default directory for persisted sessions. */
|
|
24
|
+
export const DEFAULT_SESSION_DIR = "~/.ultracode/sessions";
|
|
25
|
+
/** Directory holding user-authored system prompts. */
|
|
26
|
+
export const PROMPTS_DIR = "~/.ultracode/prompts";
|
|
27
|
+
/** Hard cap on a single tool's output, in characters, before truncation. */
|
|
28
|
+
export const MAX_TOOL_OUTPUT_CHARS = 100_000;
|
|
29
|
+
/** Default per-request provider timeout, in milliseconds. */
|
|
30
|
+
export const DEFAULT_PROVIDER_TIMEOUT_MS = 60_000;
|
|
31
|
+
/** Default maximum provider retry attempts. */
|
|
32
|
+
export const DEFAULT_MAX_RETRIES = 3;
|
|
33
|
+
/** Default base retry delay, in milliseconds. */
|
|
34
|
+
export const DEFAULT_RETRY_DELAY_MS = 1_000;
|
|
35
|
+
/** Default changelog file name. */
|
|
36
|
+
export const DEFAULT_CHANGELOG_FILE = "CHANGELOG.md";
|
|
37
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,wCAAwC;AACxC,MAAM,CAAC,MAAM,OAAO,GAAG,OAAgB,CAAC;AAExC;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,wBAAwB;IACxB,mBAAmB;IACnB,iBAAiB;CACT,CAAC;AAEX,4EAA4E;AAC5E,MAAM,CAAC,MAAM,eAAe,GAAG,cAAuB,CAAC;AAEvD,mCAAmC;AACnC,MAAM,CAAC,MAAM,gBAAgB,GAAG,0BAAmC,CAAC;AAEpE,oDAAoD;AACpD,MAAM,CAAC,MAAM,aAAa,GAAG,mBAA4B,CAAC;AAE1D,oFAAoF;AACpF,MAAM,CAAC,MAAM,UAAU,GAAG,YAAqB,CAAC;AAEhD,gDAAgD;AAChD,MAAM,CAAC,MAAM,mBAAmB,GAAG,uBAAgC,CAAC;AAEpE,sDAAsD;AACtD,MAAM,CAAC,MAAM,WAAW,GAAG,sBAA+B,CAAC;AAE3D,4EAA4E;AAC5E,MAAM,CAAC,MAAM,qBAAqB,GAAG,OAAgB,CAAC;AAEtD,6DAA6D;AAC7D,MAAM,CAAC,MAAM,2BAA2B,GAAG,MAAe,CAAC;AAE3D,+CAA+C;AAC/C,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAU,CAAC;AAE9C,iDAAiD;AACjD,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAc,CAAC;AAErD,mCAAmC;AACnC,MAAM,CAAC,MAAM,sBAAsB,GAAG,cAAuB,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error hierarchy for UltraCode.
|
|
3
|
+
*
|
|
4
|
+
* All runtime errors thrown across UltraCode packages derive from
|
|
5
|
+
* {@link UltraCodeError}. Each error carries a stable, machine-readable
|
|
6
|
+
* `code`, an optional underlying `cause`, and arbitrary structured
|
|
7
|
+
* `details`. Errors are `instanceof`-safe across transpilation targets
|
|
8
|
+
* (via `Object.setPrototypeOf`) and serialise cleanly via `toJSON()`.
|
|
9
|
+
*/
|
|
10
|
+
/** Structured, JSON-safe representation of an {@link UltraCodeError}. */
|
|
11
|
+
export interface SerializedError {
|
|
12
|
+
/** Class name of the error (e.g. `"ConfigError"`). */
|
|
13
|
+
name: string;
|
|
14
|
+
/** Human-readable message. */
|
|
15
|
+
message: string;
|
|
16
|
+
/** Stable machine-readable error code. */
|
|
17
|
+
code: string;
|
|
18
|
+
/** Optional stack trace, when available. */
|
|
19
|
+
stack?: string;
|
|
20
|
+
/** Structured, JSON-safe detail payload. */
|
|
21
|
+
details?: Record<string, unknown>;
|
|
22
|
+
/** Serialised underlying cause, if any. */
|
|
23
|
+
cause?: unknown;
|
|
24
|
+
}
|
|
25
|
+
/** Options accepted by every {@link UltraCodeError} subclass. */
|
|
26
|
+
export interface UltraCodeErrorOptions {
|
|
27
|
+
/** Underlying error or value that triggered this error. */
|
|
28
|
+
cause?: unknown;
|
|
29
|
+
/** Structured, JSON-safe detail payload. */
|
|
30
|
+
details?: Record<string, unknown>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Abstract base class for all UltraCode errors.
|
|
34
|
+
*
|
|
35
|
+
* Subclasses MUST provide a stable {@link UltraCodeError.code}. The base
|
|
36
|
+
* class normalises `name`, fixes the prototype chain for reliable
|
|
37
|
+
* `instanceof` checks, and captures a stack trace where supported.
|
|
38
|
+
*/
|
|
39
|
+
export declare abstract class UltraCodeError extends Error {
|
|
40
|
+
/** Stable, machine-readable error code (e.g. `"CONFIG_ERROR"`). */
|
|
41
|
+
readonly code: string;
|
|
42
|
+
/** Structured, JSON-safe detail payload. */
|
|
43
|
+
readonly details?: Record<string, unknown>;
|
|
44
|
+
protected constructor(code: string, message: string, options?: UltraCodeErrorOptions);
|
|
45
|
+
/** JSON-safe representation, suitable for transport and event buses. */
|
|
46
|
+
toJSON(): SerializedError;
|
|
47
|
+
}
|
|
48
|
+
/** Configuration loading, parsing or validation failed. */
|
|
49
|
+
export declare class ConfigError extends UltraCodeError {
|
|
50
|
+
constructor(message: string, options?: UltraCodeErrorOptions);
|
|
51
|
+
}
|
|
52
|
+
/** Options specific to {@link ProviderError}. */
|
|
53
|
+
export interface ProviderErrorOptions extends UltraCodeErrorOptions {
|
|
54
|
+
/** Provider name that produced the error (e.g. `"mistral"`). */
|
|
55
|
+
provider: string;
|
|
56
|
+
/** HTTP status code, when the error originated from an HTTP response. */
|
|
57
|
+
statusCode?: number;
|
|
58
|
+
/** Whether the operation may succeed if retried. Defaults to `false`. */
|
|
59
|
+
retryable?: boolean;
|
|
60
|
+
}
|
|
61
|
+
/** An LLM provider request failed. */
|
|
62
|
+
export declare class ProviderError extends UltraCodeError {
|
|
63
|
+
/** Provider name that produced the error. */
|
|
64
|
+
readonly provider: string;
|
|
65
|
+
/** HTTP status code, when applicable. */
|
|
66
|
+
readonly statusCode?: number;
|
|
67
|
+
/** Whether the operation may succeed if retried. */
|
|
68
|
+
readonly retryable: boolean;
|
|
69
|
+
constructor(message: string, options: ProviderErrorOptions);
|
|
70
|
+
toJSON(): SerializedError;
|
|
71
|
+
}
|
|
72
|
+
/** Options specific to {@link ToolError} and its subclasses. */
|
|
73
|
+
export interface ToolErrorOptions extends UltraCodeErrorOptions {
|
|
74
|
+
/** Name of the tool that failed. */
|
|
75
|
+
toolName: string;
|
|
76
|
+
}
|
|
77
|
+
/** A tool encountered an error during execution. */
|
|
78
|
+
export declare class ToolError extends UltraCodeError {
|
|
79
|
+
/** Name of the tool that failed. */
|
|
80
|
+
readonly toolName: string;
|
|
81
|
+
constructor(message: string, options: ToolErrorOptions);
|
|
82
|
+
constructor(code: string, message: string, options: ToolErrorOptions);
|
|
83
|
+
toJSON(): SerializedError;
|
|
84
|
+
}
|
|
85
|
+
/** A tool was invoked but the user/permission system denied it. */
|
|
86
|
+
export declare class ToolPermissionDeniedError extends ToolError {
|
|
87
|
+
constructor(message: string, options: ToolErrorOptions);
|
|
88
|
+
}
|
|
89
|
+
/** A tool exceeded its configured execution timeout. */
|
|
90
|
+
export declare class ToolTimeoutError extends ToolError {
|
|
91
|
+
constructor(message: string, options: ToolErrorOptions);
|
|
92
|
+
}
|
|
93
|
+
/** A tool was requested that is not registered. */
|
|
94
|
+
export declare class ToolNotFoundError extends ToolError {
|
|
95
|
+
constructor(message: string, options: ToolErrorOptions);
|
|
96
|
+
}
|
|
97
|
+
/** An agent failed during its run lifecycle. */
|
|
98
|
+
export declare class AgentError extends UltraCodeError {
|
|
99
|
+
constructor(message: string, options?: UltraCodeErrorOptions);
|
|
100
|
+
}
|
|
101
|
+
/** A session operation (create, load, append, prune) failed. */
|
|
102
|
+
export declare class SessionError extends UltraCodeError {
|
|
103
|
+
constructor(message: string, options?: UltraCodeErrorOptions);
|
|
104
|
+
}
|
|
105
|
+
/** A versioning / release-planning operation failed. */
|
|
106
|
+
export declare class VersioningError extends UltraCodeError {
|
|
107
|
+
constructor(message: string, options?: UltraCodeErrorOptions);
|
|
108
|
+
}
|
|
109
|
+
/** Input validation failed (e.g. tool argument schema mismatch). */
|
|
110
|
+
export declare class ValidationError extends UltraCodeError {
|
|
111
|
+
constructor(message: string, options?: UltraCodeErrorOptions);
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,yEAAyE;AACzE,MAAM,WAAW,eAAe;IAC9B,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,8BAA8B;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,4CAA4C;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4CAA4C;IAC5C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,2CAA2C;IAC3C,KAAK,CAAC,EAAE,OAAO,CAAC;CAC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,oDAAoD;AACpD,qBAAa,SAAU,SAAQ,cAAc;IAC3C,oCAAoC;IACpC,SAAgB,QAAQ,EAAE,MAAM,CAAC;gBAErB,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB;gBAC1C,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB;IASpD,MAAM,IAAI,eAAe;CAM1C;AAED,mEAAmE;AACnE,qBAAa,yBAA0B,SAAQ,SAAS;gBAC1C,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB;CAGvD;AAED,wDAAwD;AACxD,qBAAa,gBAAiB,SAAQ,SAAS;gBACjC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB;CAGvD;AAED,mDAAmD;AACnD,qBAAa,iBAAkB,SAAQ,SAAS;gBAClC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB;CAGvD;AAED,gDAAgD;AAChD,qBAAa,UAAW,SAAQ,cAAc;gBAChC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B;CAGjE;AAED,gEAAgE;AAChE,qBAAa,YAAa,SAAQ,cAAc;gBAClC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B;CAGjE;AAED,wDAAwD;AACxD,qBAAa,eAAgB,SAAQ,cAAc;gBACrC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B;CAGjE;AAED,oEAAoE;AACpE,qBAAa,eAAgB,SAAQ,cAAc;gBACrC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B;CAGjE"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error hierarchy for UltraCode.
|
|
3
|
+
*
|
|
4
|
+
* All runtime errors thrown across UltraCode packages derive from
|
|
5
|
+
* {@link UltraCodeError}. Each error carries a stable, machine-readable
|
|
6
|
+
* `code`, an optional underlying `cause`, and arbitrary structured
|
|
7
|
+
* `details`. Errors are `instanceof`-safe across transpilation targets
|
|
8
|
+
* (via `Object.setPrototypeOf`) and serialise cleanly via `toJSON()`.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Abstract base class for all UltraCode errors.
|
|
12
|
+
*
|
|
13
|
+
* Subclasses MUST provide a stable {@link UltraCodeError.code}. The base
|
|
14
|
+
* class normalises `name`, fixes the prototype chain for reliable
|
|
15
|
+
* `instanceof` checks, and captures a stack trace where supported.
|
|
16
|
+
*/
|
|
17
|
+
export class UltraCodeError extends Error {
|
|
18
|
+
/** Stable, machine-readable error code (e.g. `"CONFIG_ERROR"`). */
|
|
19
|
+
code;
|
|
20
|
+
/** Structured, JSON-safe detail payload. */
|
|
21
|
+
details;
|
|
22
|
+
constructor(code, message, options = {}) {
|
|
23
|
+
// `cause` is part of the standard ErrorOptions in ES2022.
|
|
24
|
+
super(message, options.cause !== undefined ? { cause: options.cause } : undefined);
|
|
25
|
+
this.code = code;
|
|
26
|
+
this.details = options.details;
|
|
27
|
+
this.name = new.target.name;
|
|
28
|
+
// Restore prototype chain so `instanceof` works after transpilation/bundling.
|
|
29
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
30
|
+
// Capture a clean stack trace where the V8 API is available.
|
|
31
|
+
if (typeof Error.captureStackTrace === "function") {
|
|
32
|
+
Error.captureStackTrace(this, new.target);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** JSON-safe representation, suitable for transport and event buses. */
|
|
36
|
+
toJSON() {
|
|
37
|
+
const out = {
|
|
38
|
+
name: this.name,
|
|
39
|
+
message: this.message,
|
|
40
|
+
code: this.code,
|
|
41
|
+
};
|
|
42
|
+
if (this.stack !== undefined)
|
|
43
|
+
out.stack = this.stack;
|
|
44
|
+
if (this.details !== undefined)
|
|
45
|
+
out.details = this.details;
|
|
46
|
+
if (this.cause !== undefined)
|
|
47
|
+
out.cause = serializeCause(this.cause);
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** Reduce an arbitrary `cause` to a JSON-safe form without throwing. */
|
|
52
|
+
function serializeCause(cause) {
|
|
53
|
+
if (cause instanceof UltraCodeError)
|
|
54
|
+
return cause.toJSON();
|
|
55
|
+
if (cause instanceof Error) {
|
|
56
|
+
const out = { name: cause.name, message: cause.message, code: "ERROR" };
|
|
57
|
+
if (cause.stack !== undefined)
|
|
58
|
+
out.stack = cause.stack;
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
return cause;
|
|
62
|
+
}
|
|
63
|
+
/** Configuration loading, parsing or validation failed. */
|
|
64
|
+
export class ConfigError extends UltraCodeError {
|
|
65
|
+
constructor(message, options = {}) {
|
|
66
|
+
super("CONFIG_ERROR", message, options);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** An LLM provider request failed. */
|
|
70
|
+
export class ProviderError extends UltraCodeError {
|
|
71
|
+
/** Provider name that produced the error. */
|
|
72
|
+
provider;
|
|
73
|
+
/** HTTP status code, when applicable. */
|
|
74
|
+
statusCode;
|
|
75
|
+
/** Whether the operation may succeed if retried. */
|
|
76
|
+
retryable;
|
|
77
|
+
constructor(message, options) {
|
|
78
|
+
super("PROVIDER_ERROR", message, options);
|
|
79
|
+
this.provider = options.provider;
|
|
80
|
+
this.statusCode = options.statusCode;
|
|
81
|
+
this.retryable = options.retryable ?? false;
|
|
82
|
+
}
|
|
83
|
+
toJSON() {
|
|
84
|
+
return {
|
|
85
|
+
...super.toJSON(),
|
|
86
|
+
details: {
|
|
87
|
+
...this.details,
|
|
88
|
+
provider: this.provider,
|
|
89
|
+
statusCode: this.statusCode,
|
|
90
|
+
retryable: this.retryable,
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/** A tool encountered an error during execution. */
|
|
96
|
+
export class ToolError extends UltraCodeError {
|
|
97
|
+
/** Name of the tool that failed. */
|
|
98
|
+
toolName;
|
|
99
|
+
constructor(a, b, c) {
|
|
100
|
+
const code = typeof c === "undefined" ? "TOOL_ERROR" : a;
|
|
101
|
+
const message = typeof c === "undefined" ? a : b;
|
|
102
|
+
const options = (typeof c === "undefined" ? b : c);
|
|
103
|
+
super(code, message, options);
|
|
104
|
+
this.toolName = options.toolName;
|
|
105
|
+
}
|
|
106
|
+
toJSON() {
|
|
107
|
+
return {
|
|
108
|
+
...super.toJSON(),
|
|
109
|
+
details: { ...this.details, toolName: this.toolName },
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/** A tool was invoked but the user/permission system denied it. */
|
|
114
|
+
export class ToolPermissionDeniedError extends ToolError {
|
|
115
|
+
constructor(message, options) {
|
|
116
|
+
super("TOOL_PERMISSION_DENIED", message, options);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/** A tool exceeded its configured execution timeout. */
|
|
120
|
+
export class ToolTimeoutError extends ToolError {
|
|
121
|
+
constructor(message, options) {
|
|
122
|
+
super("TOOL_TIMEOUT", message, options);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/** A tool was requested that is not registered. */
|
|
126
|
+
export class ToolNotFoundError extends ToolError {
|
|
127
|
+
constructor(message, options) {
|
|
128
|
+
super("TOOL_NOT_FOUND", message, options);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/** An agent failed during its run lifecycle. */
|
|
132
|
+
export class AgentError extends UltraCodeError {
|
|
133
|
+
constructor(message, options = {}) {
|
|
134
|
+
super("AGENT_ERROR", message, options);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/** A session operation (create, load, append, prune) failed. */
|
|
138
|
+
export class SessionError extends UltraCodeError {
|
|
139
|
+
constructor(message, options = {}) {
|
|
140
|
+
super("SESSION_ERROR", message, options);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/** A versioning / release-planning operation failed. */
|
|
144
|
+
export class VersioningError extends UltraCodeError {
|
|
145
|
+
constructor(message, options = {}) {
|
|
146
|
+
super("VERSIONING_ERROR", message, options);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/** Input validation failed (e.g. tool argument schema mismatch). */
|
|
150
|
+
export class ValidationError extends UltraCodeError {
|
|
151
|
+
constructor(message, options = {}) {
|
|
152
|
+
super("VALIDATION_ERROR", message, options);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA0BH;;;;;;GAMG;AACH,MAAM,OAAgB,cAAe,SAAQ,KAAK;IAChD,mEAAmE;IACnD,IAAI,CAAS;IAC7B,4CAA4C;IAC5B,OAAO,CAA2B;IAElD,YAAsB,IAAY,EAAE,OAAe,EAAE,UAAiC,EAAE;QACtF,0DAA0D;QAC1D,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QACnF,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;QAC5B,8EAA8E;QAC9E,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAClD,6DAA6D;QAC7D,IAAI,OAAQ,KAAyC,CAAC,iBAAiB,KAAK,UAAU,EAAE,CAAC;YACtF,KAA4E,CAAC,iBAAiB,CAC7F,IAAI,EACJ,GAAG,CAAC,MAAM,CACX,CAAC;QACJ,CAAC;IACH,CAAC;IAED,wEAAwE;IACjE,MAAM;QACX,MAAM,GAAG,GAAoB;YAC3B,IA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;IAC9C,CAAC;CACF"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Concrete {@link IEventBus} implementation.
|
|
3
|
+
*
|
|
4
|
+
* Design notes:
|
|
5
|
+
* - **Handler isolation:** a throwing handler is caught so it cannot prevent
|
|
6
|
+
* sibling handlers from running. Caught errors are reported via an optional
|
|
7
|
+
* `onHandlerError` callback (defaulting to `console.error`).
|
|
8
|
+
* - **Safe mutation during emit:** `emit` iterates over a snapshot of the
|
|
9
|
+
* handler set, so subscribing/unsubscribing from within a handler does not
|
|
10
|
+
* disturb the in-flight dispatch and never throws.
|
|
11
|
+
*/
|
|
12
|
+
import type { EventHandler, IEventBus, UltraCodeEvent, UltraCodeEventType } from "../types/events.js";
|
|
13
|
+
/** Options for {@link EventBus}. */
|
|
14
|
+
export interface EventBusOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Invoked when a handler throws. Receives the thrown value and the event that
|
|
17
|
+
* was being dispatched. Defaults to logging via `console.error`. This callback
|
|
18
|
+
* is itself wrapped so that a throwing reporter cannot break dispatch.
|
|
19
|
+
*/
|
|
20
|
+
onHandlerError?: (error: unknown, event: UltraCodeEvent) => void;
|
|
21
|
+
}
|
|
22
|
+
export declare class EventBus implements IEventBus {
|
|
23
|
+
/** Per-type subscriber sets. A `Set` gives O(1) add/remove and dedupes. */
|
|
24
|
+
private readonly handlers;
|
|
25
|
+
private readonly onHandlerError;
|
|
26
|
+
constructor(options?: EventBusOptions);
|
|
27
|
+
on<T extends UltraCodeEventType>(type: T, handler: EventHandler<T>): () => void;
|
|
28
|
+
emit(event: UltraCodeEvent): void;
|
|
29
|
+
/** Number of subscribers for a given event type (useful for tests/diagnostics). */
|
|
30
|
+
listenerCount(type: UltraCodeEventType): number;
|
|
31
|
+
/** Remove all subscribers, optionally for a single event type. */
|
|
32
|
+
removeAll(type?: UltraCodeEventType): void;
|
|
33
|
+
/** Invoke the error reporter without ever letting it throw. */
|
|
34
|
+
private reportSafely;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=EventBus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventBus.d.ts","sourceRoot":"","sources":["../../src/events/EventBus.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,SAAS,EACT,cAAc,EACd,kBAAkB,EACnB,MAAM,oBAAoB,CAAC;AAE5B,oCAAoC;AACpC,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;CAClE;AAKD,qBAAa,QAAS,YAAW,SAAS;IACxC,2EAA2E;IAC3E,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAkD;IAC3E,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAkD;gBAErE,OAAO,GAAE,eAAoB;IASzC,EAAE,CAAC,CAAC,SAAS,kBAAkB,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI;IAsB/E,IAAI,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI;IAcjC,mFAAmF;IACnF,aAAa,CAAC,IAAI,EAAE,kBAAkB,GAAG,MAAM;IAI/C,kEAAkE;IAClE,SAAS,CAAC,IAAI,CAAC,EAAE,kBAAkB,GAAG,IAAI;IAK1C,+DAA+D;IAC/D,OAAO,CAAC,YAAY;CAOrB"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Concrete {@link IEventBus} implementation.
|
|
3
|
+
*
|
|
4
|
+
* Design notes:
|
|
5
|
+
* - **Handler isolation:** a throwing handler is caught so it cannot prevent
|
|
6
|
+
* sibling handlers from running. Caught errors are reported via an optional
|
|
7
|
+
* `onHandlerError` callback (defaulting to `console.error`).
|
|
8
|
+
* - **Safe mutation during emit:** `emit` iterates over a snapshot of the
|
|
9
|
+
* handler set, so subscribing/unsubscribing from within a handler does not
|
|
10
|
+
* disturb the in-flight dispatch and never throws.
|
|
11
|
+
*/
|
|
12
|
+
export class EventBus {
|
|
13
|
+
/** Per-type subscriber sets. A `Set` gives O(1) add/remove and dedupes. */
|
|
14
|
+
handlers = new Map();
|
|
15
|
+
onHandlerError;
|
|
16
|
+
constructor(options = {}) {
|
|
17
|
+
this.onHandlerError =
|
|
18
|
+
options.onHandlerError ??
|
|
19
|
+
((error, event) => {
|
|
20
|
+
// Default reporter; never throws.
|
|
21
|
+
console.error(`[EventBus] handler for "${event.type}" threw:`, error);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
on(type, handler) {
|
|
25
|
+
let set = this.handlers.get(type);
|
|
26
|
+
if (set === undefined) {
|
|
27
|
+
set = new Set();
|
|
28
|
+
this.handlers.set(type, set);
|
|
29
|
+
}
|
|
30
|
+
// Safe: EventHandler<T> is invoked only with EventOfType<T> values, which
|
|
31
|
+
// `emit` guarantees by routing on the event's own discriminator.
|
|
32
|
+
const erased = handler;
|
|
33
|
+
set.add(erased);
|
|
34
|
+
let active = true;
|
|
35
|
+
return () => {
|
|
36
|
+
if (!active)
|
|
37
|
+
return; // idempotent unsubscribe
|
|
38
|
+
active = false;
|
|
39
|
+
const current = this.handlers.get(type);
|
|
40
|
+
if (current === undefined)
|
|
41
|
+
return;
|
|
42
|
+
current.delete(erased);
|
|
43
|
+
if (current.size === 0)
|
|
44
|
+
this.handlers.delete(type);
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
emit(event) {
|
|
48
|
+
const set = this.handlers.get(event.type);
|
|
49
|
+
if (set === undefined || set.size === 0)
|
|
50
|
+
return;
|
|
51
|
+
// Snapshot so unsubscribe/subscribe during dispatch is safe and predictable.
|
|
52
|
+
const snapshot = Array.from(set);
|
|
53
|
+
for (const handler of snapshot) {
|
|
54
|
+
try {
|
|
55
|
+
handler(event);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
this.reportSafely(error, event);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/** Number of subscribers for a given event type (useful for tests/diagnostics). */
|
|
63
|
+
listenerCount(type) {
|
|
64
|
+
return this.handlers.get(type)?.size ?? 0;
|
|
65
|
+
}
|
|
66
|
+
/** Remove all subscribers, optionally for a single event type. */
|
|
67
|
+
removeAll(type) {
|
|
68
|
+
if (type === undefined)
|
|
69
|
+
this.handlers.clear();
|
|
70
|
+
else
|
|
71
|
+
this.handlers.delete(type);
|
|
72
|
+
}
|
|
73
|
+
/** Invoke the error reporter without ever letting it throw. */
|
|
74
|
+
reportSafely(error, event) {
|
|
75
|
+
try {
|
|
76
|
+
this.onHandlerError(error, event);
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
/* a throwing reporter must not break dispatch */
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=EventBus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventBus.js","sourceRoot":"","sources":["../../src/events/EventBus.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAsBH,MAAM,OAAO,QAAQ;IACnB,2EAA2E;IAC1D,QAAQ,GAAG,IAAI,GAAG,EAAuC,CAAC;IAC1D,cAAc,CAAkD;IAEjF,YAAY,UAA2B,EAAE;QACvC,IAAI,CAAC,cAAc;YACjB,OAAO,CAAC,cAAc;gBACtB,CAAC,CAAC,KAAK,EAAE,KAAK,EAAQ,EAAE;oBACtB,kCAAkC;oBAClC,OAAO,CAAC,KAAK,CAAC,2BAA2B,KAAK,CAAC,IAAI,UAAU,EAAE,KAAK,CAAC,CAAC;gBACxE,CAAC,CAAC,CAAC;IACP,CAAC;IAED,EAAE,CAA+B,IAAO,EAAE,OAAwB;QAChE,IAAI,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC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;QACH,CAAC;IACH,CAAC;IAED,mFAAmF;IACnF,aAAa,CAAC,IAAwB;QACpC,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,IAAI,CAAC,CAAC;IAC5C,CAAC;IAED,kEAAkE;IAClE,SAAS,CAAC,IAAyB;QACjC,IAAI,IAAI,KAAK,SAAS;YAAE,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;;YACzC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAED,+DAA+D;IACvD,YAAY,CAAC,KAAc,EAAE,KAAqB;QACxD,IAAI,CAAC;YACH,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QACpC,CAAC;QAAC,MAAM,CAAC;YACP,iDAAiD;QACnD,CAAC;IACH,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ultracode-shared` — the contract layer.
|
|
3
|
+
*
|
|
4
|
+
* This package defines the types, interfaces, errors, events and utilities that
|
|
5
|
+
* the `core` and `cli` packages build against. It contains no business logic
|
|
6
|
+
* beyond small, pure runtime helpers (errors, EventBus, logger, utils).
|
|
7
|
+
*
|
|
8
|
+
* Import everything from the package root:
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { UltraCodeError, EventBus, deepMerge, type ToolDefinition } from "ultracode-shared";
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export { UltraCodeError, ConfigError, ProviderError, ToolError, ToolPermissionDeniedError, ToolTimeoutError, ToolNotFoundError, AgentError, SessionError, VersioningError, ValidationError, } from "./errors.js";
|
|
14
|
+
export type { SerializedError, UltraCodeErrorOptions, ProviderErrorOptions, ToolErrorOptions, } from "./errors.js";
|
|
15
|
+
export { ConsoleLogger, NoopLogger } from "./logger.js";
|
|
16
|
+
export type { Logger, LogLevel, LogMeta, LogSink, ConsoleLoggerOptions, } from "./logger.js";
|
|
17
|
+
export type { ToolPermission, ToolCategory, ToolParameterSchema, ToolDefinition, ToolContext, ToolResult, ITool, } from "./types/tool.js";
|
|
18
|
+
export type { ProviderName, ProviderId, ChatRole, ChatMessage, ToolCallRequest, CompletionRequest, CompletionChunk, CompletionResult, FinishReason, TokenUsage, ILLMProvider, ProviderOptions, } from "./types/provider.js";
|
|
19
|
+
export type { AgentType, AgentDefinition, AgentRunInput, AgentRunResult, IAgent, } from "./types/agent.js";
|
|
20
|
+
export { DEFAULT_CONFIG } from "./types/config.js";
|
|
21
|
+
export type { DeepPartial, CoreConfig, ProxyConfig, LocalProviderConfig, ProvidersConfig, PerToolConfig, ToolsConfig, AgentConfigEntry, AgentsConfig, UiColors, UiConfig, SessionCompactionConfig, SessionsConfig, GitCommitConfig, GitProtectionConfig, GitConfig, VersioningSemanticConfig, VersioningChannelsConfig, VersioningQualityConfig, VersioningChangelogConfig, VersioningConfig, McpTransport, McpServerConfig, UltraCodeConfig, } from "./types/config.js";
|
|
22
|
+
export type { SessionMeta, SessionRecord, ISessionStore, } from "./types/memory.js";
|
|
23
|
+
export type { BumpType, FileChange, CommitInfo, BreakingChange, SecurityFinding, ChangeAnalysis, VersionSuggestion, Milestone, Risk, ReleasePlan, QualityGateResult, QualityReport, } from "./types/versioning.js";
|
|
24
|
+
export type { ToolExecutedEvent, AgentSwitchedEvent, SessionStartedEvent, SessionEndedEvent, ErrorEvent, VersionSuggestedEvent, UltraCodeEvent, UltraCodeEventType, EventOfType, EventHandler, IEventBus, } from "./types/events.js";
|
|
25
|
+
export { EventBus } from "./events/EventBus.js";
|
|
26
|
+
export type { EventBusOptions } from "./events/EventBus.js";
|
|
27
|
+
export { serializeError, truncate, DEFAULT_TRUNCATE_SUFFIX, isPlainObject, deepMerge, sleep, clamp, generateId, } from "./utils/index.js";
|
|
28
|
+
export type { TruncateOptions } from "./utils/index.js";
|
|
29
|
+
export { VERSION, CONFIG_FILE_NAMES, USER_CONFIG_DIR, USER_CONFIG_FILE, USER_ENV_FILE, ENV_PREFIX, DEFAULT_SESSION_DIR, PROMPTS_DIR, MAX_TOOL_OUTPUT_CHARS, DEFAULT_PROVIDER_TIMEOUT_MS, DEFAULT_MAX_RETRIES, DEFAULT_RETRY_DELAY_MS, DEFAULT_CHANGELOG_FILE, } from "./constants.js";
|
|
30
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAKH,OAAO,EACL,cAAc,EACd,WAAW,EACX,aAAa,EACb,SAAS,EACT,yBAAyB,EACzB,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,EACV,YAAY,EACZ,eAAe,EACf,eAAe,GAChB,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,eAAe,EACf,qBAAqB,EACrB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAKrB,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACxD,YAAY,EACV,MAAM,EACN,QAAQ,EACR,OAAO,EACP,OAAO,EACP,oBAAoB,GACrB,MAAM,aAAa,CAAC;AAKrB,YAAY,EACV,cAAc,EACd,YAAY,EACZ,mBAAmB,EACnB,cAAc,EACd,WAAW,EACX,UAAU,EACV,KAAK,GACN,MAAM,iBAAiB,CAAC;AAKzB,YAAY,EACV,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAK7B,YAAY,EACV,SAAS,EACT,eAAe,EACf,aAAa,EACb,cAAc,EACd,MAAM,GACP,MAAM,kBAAkB,CAAC;AAK1B,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,C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AAsB,GACvB,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ultracode-shared` — the contract layer.
|
|
3
|
+
*
|
|
4
|
+
* This package defines the types, interfaces, errors, events and utilities that
|
|
5
|
+
* the `core` and `cli` packages build against. It contains no business logic
|
|
6
|
+
* beyond small, pure runtime helpers (errors, EventBus, logger, utils).
|
|
7
|
+
*
|
|
8
|
+
* Import everything from the package root:
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { UltraCodeError, EventBus, deepMerge, type ToolDefinition } from "ultracode-shared";
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
/* ----------------------------------------------------------------------------
|
|
14
|
+
* Errors (runtime classes + types)
|
|
15
|
+
* ------------------------------------------------------------------------- */
|
|
16
|
+
export { UltraCodeError, ConfigError, ProviderError, ToolError, ToolPermissionDeniedError, ToolTimeoutError, ToolNotFoundError, AgentError, SessionError, VersioningError, ValidationError, } from "./errors.js";
|
|
17
|
+
/* ----------------------------------------------------------------------------
|
|
18
|
+
* Logging (runtime classes + types)
|
|
19
|
+
* ------------------------------------------------------------------------- */
|
|
20
|
+
export { ConsoleLogger, NoopLogger } from "./logger.js";
|
|
21
|
+
/* ----------------------------------------------------------------------------
|
|
22
|
+
* Configuration (types + DEFAULT_CONFIG value)
|
|
23
|
+
* ------------------------------------------------------------------------- */
|
|
24
|
+
export { DEFAULT_CONFIG } from "./types/config.js";
|
|
25
|
+
export { EventBus } from "./events/EventBus.js";
|
|
26
|
+
/* ----------------------------------------------------------------------------
|
|
27
|
+
* Utilities (runtime functions)
|
|
28
|
+
* ------------------------------------------------------------------------- */
|
|
29
|
+
export { serializeError, truncate, DEFAULT_TRUNCATE_SUFFIX, isPlainObject, deepMerge, sleep, clamp, generateId, } from "./utils/index.js";
|
|
30
|
+
/* ----------------------------------------------------------------------------
|
|
31
|
+
* Constants
|
|
32
|
+
* ------------------------------------------------------------------------- */
|
|
33
|
+
export { VERSION, CONFIG_FILE_NAMES, USER_CONFIG_DIR, USER_CONFIG_FILE, USER_ENV_FILE, ENV_PREFIX, DEFAULT_SESSION_DIR, PROMPTS_DIR, MAX_TOOL_OUTPUT_CHARS, DEFAULT_PROVIDER_TIMEOUT_MS, DEFAULT_MAX_RETRIES, DEFAULT_RETRY_DELAY_MS, DEFAULT_CHANGELOG_FILE, } from "./constants.js";
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;+EAE+E;AAC/E,OAAO,EACL,cAAc,EACd,WAAW,EACX,aAAa,EACb,SAAS,EACT,yBAAyB,EACzB,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,EACV,YAAY,EACZ,eAAe,EACf,eAAe,GAChB,MAAM,aAAa,CAAC;AAQrB;;+EAE+E;AAC/E,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAmDxD;;+EAE+E;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAuEnD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAGhD;;+EAE+E;AAC/E,OAAO,EACL,cAAc,EACd,QAAQ,EACR,uBAAuB,EACvB,aAAa,EACb,SAAS,EACT,KAAK,EACL,KAAK,EACL,UAAU,GACX,MAAM,kBAAkB,CAAC;AAG1B;;+EAE+E;AAC/E,OAAO,EACL,OAAO,EACP,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,UAAU,EACV,mBAAmB,EACnB,WAAW,EACX,qBAAqB,EACrB,2BAA2B,EAC3B,mBAAmB,EACnB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,gBAAgB,CAAC"}
|