@nola-lang/core 0.1.0-alpha.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Evgen Mykhailenko
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,7 @@
1
+ Part of [Nola](https://github.com/nola-lang/nola), a TypeScript superset (`.tsi`) where `infer` functions and `ask` extractors turn prompts into typed values.
2
+
3
+ **Internal package** — you probably want [`nola-lang`](https://www.npmjs.com/package/nola-lang) (the dev tool) or [`@nola-lang/runtime`](https://www.npmjs.com/package/@nola-lang/runtime) (the app dependency).
4
+
5
+ This package holds the dependency-free core: public `Intent`/`Askable` types, provider/config contracts, the error family, redaction, and ask fingerprinting.
6
+
7
+ Versioned in lockstep with the whole toolchain; internal APIs may change in any release.
@@ -0,0 +1,60 @@
1
+ import type { InvocationTrace, Site } from "./index.js";
2
+ export declare class NolaConfigError extends Error {
3
+ readonly code?: string | undefined;
4
+ name: string;
5
+ constructor(message: string, code?: string | undefined);
6
+ }
7
+ export interface ResolutionDetails {
8
+ prompt: string;
9
+ raw: string;
10
+ site: Site;
11
+ }
12
+ export declare class NolaResolutionError extends Error {
13
+ readonly details: ResolutionDetails;
14
+ name: string;
15
+ /** execution trace of the failing invocation, stamped by the innermost frame */
16
+ trace?: InvocationTrace;
17
+ constructor(message: string, details: ResolutionDetails, options?: {
18
+ cause?: unknown;
19
+ });
20
+ }
21
+ /** An intent that carries no construction scope (extract/call) was resolved
22
+ * outside `ask` — nothing can supply its frame. Definitive. */
23
+ export declare class NolaIntentError extends Error {
24
+ readonly code: string;
25
+ name: string;
26
+ constructor(message: string, code: string);
27
+ }
28
+ /** A type that could not be derived reached an ask (companion `unsupported`). Definitive. */
29
+ export declare class NolaSchemaError extends Error {
30
+ readonly code: string;
31
+ name: string;
32
+ constructor(message: string, code: string);
33
+ }
34
+ export interface ProviderErrorOptions {
35
+ status?: number;
36
+ definitive?: boolean;
37
+ /** provider-requested wait before retrying (Retry-After), in ms */
38
+ retryAfterMs?: number;
39
+ cause?: unknown;
40
+ }
41
+ export declare class NolaProviderError extends Error {
42
+ name: string;
43
+ readonly status?: number;
44
+ readonly definitive?: boolean;
45
+ readonly retryAfterMs?: number;
46
+ constructor(message: string, options?: ProviderErrorOptions);
47
+ }
48
+ export interface VersionDetails {
49
+ expected: number;
50
+ actual: number;
51
+ direction?: "rebuild" | "update-runtime";
52
+ urls?: [string, string];
53
+ }
54
+ export declare class NolaVersionError extends Error {
55
+ readonly code: string;
56
+ readonly details: VersionDetails;
57
+ name: string;
58
+ constructor(message: string, code: string, details: VersionDetails);
59
+ }
60
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,K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AQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;gBACnB,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB;CAMhE;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,SAAS,GAAG,gBAAgB,CAAC;IACzC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACzB;AAED,qBAAa,gBAAiB,SAAQ,KAAK;IAIvC,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,QAAQ,CAAC,OAAO,EAAE,cAAc;IAJzB,IAAI,SAAsB;gBAEjC,OAAO,EAAE,MAAM,EACN,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,cAAc;CAInC"}
package/dist/errors.js ADDED
@@ -0,0 +1,60 @@
1
+ export class NolaConfigError extends Error {
2
+ code;
3
+ name = "NolaConfigError";
4
+ constructor(message, code) {
5
+ super(message);
6
+ this.code = code;
7
+ }
8
+ }
9
+ export class NolaResolutionError extends Error {
10
+ details;
11
+ name = "NolaResolutionError";
12
+ /** execution trace of the failing invocation, stamped by the innermost frame */
13
+ trace;
14
+ constructor(message, details, options) {
15
+ super(message, options);
16
+ this.details = details;
17
+ }
18
+ }
19
+ /** An intent that carries no construction scope (extract/call) was resolved
20
+ * outside `ask` — nothing can supply its frame. Definitive. */
21
+ export class NolaIntentError extends Error {
22
+ code;
23
+ name = "NolaIntentError";
24
+ constructor(message, code) {
25
+ super(message);
26
+ this.code = code;
27
+ }
28
+ }
29
+ /** A type that could not be derived reached an ask (companion `unsupported`). Definitive. */
30
+ export class NolaSchemaError extends Error {
31
+ code;
32
+ name = "NolaSchemaError";
33
+ constructor(message, code) {
34
+ super(message);
35
+ this.code = code;
36
+ }
37
+ }
38
+ export class NolaProviderError extends Error {
39
+ name = "NolaProviderError";
40
+ status;
41
+ definitive;
42
+ retryAfterMs;
43
+ constructor(message, options = {}) {
44
+ super(message, options.cause !== undefined ? { cause: options.cause } : undefined);
45
+ this.status = options.status;
46
+ this.definitive = options.definitive;
47
+ this.retryAfterMs = options.retryAfterMs;
48
+ }
49
+ }
50
+ export class NolaVersionError extends Error {
51
+ code;
52
+ details;
53
+ name = "NolaVersionError";
54
+ constructor(message, code, details) {
55
+ super(message);
56
+ this.code = code;
57
+ this.details = details;
58
+ }
59
+ }
60
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAI7B;IAHF,IAAI,GAAG,iBAAiB,CAAC;IAClC,YACE,OAAe,EACN,IAAa;QAEtB,KAAK,CAAC,OAAO,CAAC,CAAC;QAFN,SAAI,GAAJ,IAAI,CAAS;IAGxB,CAAC;CACF;AAQD,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAMjC;IALF,IAAI,GAAG,qBAAqB,CAAC;IACtC,gFAAgF;IAChF,KAAK,CAAmB;IACxB,YACE,OAAe,EACN,OAA0B,EACnC,OAA6B;QAE7B,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAHf,YAAO,GAAP,OAAO,CAAmB;IAIrC,CAAC;CACF;AAED;+DAC+D;AAC/D,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAI7B;IAHF,IAAI,GAAG,iBAAiB,CAAC;IAClC,YACE,OAAe,EACN,IAAY;QAErB,KAAK,CAAC,OAAO,CAAC,CAAC;QAFN,SAAI,GAAJ,IAAI,CAAQ;IAGvB,CAAC;CACF;AAED,6FAA6F;AAC7F,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAI7B;IAHF,IAAI,GAAG,iBAAiB,CAAC;IAClC,YACE,OAAe,EACN,IAAY;QAErB,KAAK,CAAC,OAAO,CAAC,CAAC;QAFN,SAAI,GAAJ,IAAI,CAAQ;IAGvB,CAAC;CACF;AAUD,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IACjC,IAAI,GAAG,mBAAmB,CAAC;IAC3B,MAAM,CAAU;IAChB,UAAU,CAAW;IACrB,YAAY,CAAU;IAC/B,YAAY,OAAe,EAAE,UAAgC,EAAE;QAC7D,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,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAC3C,CAAC;CACF;AASD,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAI9B;IACA;IAJF,IAAI,GAAG,kBAAkB,CAAC;IACnC,YACE,OAAe,EACN,IAAY,EACZ,OAAuB;QAEhC,KAAK,CAAC,OAAO,CAAC,CAAC;QAHN,SAAI,GAAJ,IAAI,CAAQ;QACZ,YAAO,GAAP,OAAO,CAAgB;IAGlC,CAAC;CACF"}
@@ -0,0 +1,37 @@
1
+ import type { HistoryRecord, JsonSchema, Message, ProviderOutput, ProviderParams } from "./index.js";
2
+ /**
3
+ * Version baked into every ask fingerprint. Bump when the canonical
4
+ * serialization changes shape — old caches/ledgers must not silently match.
5
+ * v3: fingerprintRequest hashes the full ProviderOutput (was bare schema) and
6
+ * ProviderParams.
7
+ */
8
+ export declare const FINGERPRINT_VERSION = 3;
9
+ /** Deterministic JSON: recursively sorted object keys, arrays in order. */
10
+ export declare function canonicalize(value: unknown): string;
11
+ export declare function sha256Hex(text: string): string;
12
+ export interface AskFingerprintInput {
13
+ lineage: ReadonlyArray<Readonly<Record<string, unknown>>>;
14
+ history: ReadonlyArray<HistoryRecord>;
15
+ prompt: string;
16
+ schema: JsonSchema;
17
+ provider: string;
18
+ preamble: string;
19
+ }
20
+ /**
21
+ * Everything that determines a provider exchange, nothing volatile (no askId,
22
+ * no timestamps, no invocationId). History is hashed as the prompt sees it.
23
+ */
24
+ export declare function fingerprintAsk(input: AskFingerprintInput): string;
25
+ /**
26
+ * Fingerprint of exactly what crosses the NolaProvider.complete seam: the
27
+ * system text plus what composeInferParams returned (messages + output
28
+ * contract). Extra properties on `req` (e.g. a full ProviderRequest with its
29
+ * signal) are ignored — only the three named fields are hashed.
30
+ */
31
+ export declare function fingerprintRequest(req: {
32
+ system: string;
33
+ messages: ReadonlyArray<Message>;
34
+ output: ProviderOutput;
35
+ params?: ProviderParams;
36
+ }): string;
37
+ //# sourceMappingURL=fingerprint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fingerprint.d.ts","sourceRoot":"","sources":["../src/fingerprint.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAErG;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAYrC,2EAA2E;AAC3E,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEnD;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAC1D,OAAO,EAAE,aAAa,CAAC,aAAa,CAAC,CAAC;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,UAAU,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,GAAG,MAAM,CAcjE;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;IACjC,MAAM,EAAE,cAAc,CAAC;IACvB,MAAM,CAAC,EAAE,cAAc,CAAC;CACzB,GAAG,MAAM,CAUT"}
@@ -0,0 +1,61 @@
1
+ import { createHash } from "node:crypto";
2
+ /**
3
+ * Version baked into every ask fingerprint. Bump when the canonical
4
+ * serialization changes shape — old caches/ledgers must not silently match.
5
+ * v3: fingerprintRequest hashes the full ProviderOutput (was bare schema) and
6
+ * ProviderParams.
7
+ */
8
+ export const FINGERPRINT_VERSION = 3;
9
+ function sortValue(v) {
10
+ if (Array.isArray(v))
11
+ return v.map(sortValue);
12
+ if (v !== null && typeof v === "object") {
13
+ const out = {};
14
+ for (const k of Object.keys(v).sort())
15
+ out[k] = sortValue(v[k]);
16
+ return out;
17
+ }
18
+ return v;
19
+ }
20
+ /** Deterministic JSON: recursively sorted object keys, arrays in order. */
21
+ export function canonicalize(value) {
22
+ return JSON.stringify(sortValue(value));
23
+ }
24
+ export function sha256Hex(text) {
25
+ return createHash("sha256").update(text, "utf8").digest("hex");
26
+ }
27
+ /**
28
+ * Everything that determines a provider exchange, nothing volatile (no askId,
29
+ * no timestamps, no invocationId). History is hashed as the prompt sees it.
30
+ */
31
+ export function fingerprintAsk(input) {
32
+ const payload = {
33
+ v: FINGERPRINT_VERSION,
34
+ lineage: input.lineage,
35
+ history: input.history.map((h) => ({
36
+ prompt: h.prompt,
37
+ value: h.promptValue !== undefined ? h.promptValue : h.value,
38
+ })),
39
+ prompt: input.prompt,
40
+ schema: input.schema,
41
+ provider: input.provider,
42
+ preamble: input.preamble,
43
+ };
44
+ return sha256Hex(canonicalize(payload));
45
+ }
46
+ /**
47
+ * Fingerprint of exactly what crosses the NolaProvider.complete seam: the
48
+ * system text plus what composeInferParams returned (messages + output
49
+ * contract). Extra properties on `req` (e.g. a full ProviderRequest with its
50
+ * signal) are ignored — only the three named fields are hashed.
51
+ */
52
+ export function fingerprintRequest(req) {
53
+ return sha256Hex(canonicalize({
54
+ v: FINGERPRINT_VERSION,
55
+ system: req.system,
56
+ messages: req.messages,
57
+ output: req.output,
58
+ params: req.params ?? null,
59
+ }));
60
+ }
61
+ //# sourceMappingURL=fingerprint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fingerprint.js","sourceRoot":"","sources":["../src/fingerprint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAErC,SAAS,SAAS,CAAC,CAAU;IAC3B,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QAAE,OAAO,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAC9C,IAAI,CAAC,KAAK,IAAI,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;QACxC,MAAM,GAAG,GAA4B,EAAE,CAAC;QACxC,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAW,CAAC,CAAC,IAAI,EAAE;YAAE,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,CAAE,CAA6B,CAAC,CAAC,CAAC,CAAC,CAAC;QACvG,OAAO,GAAG,CAAC;IACb,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,OAAO,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACjE,CAAC;AAWD;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,KAA0B;IACvD,MAAM,OAAO,GAAG;QACd,CAAC,EAAE,mBAAmB;QACtB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACjC,MAAM,EAAE,CAAC,CAAC,MAAM;YAChB,KAAK,EAAE,CAAC,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK;SAC7D,CAAC,CAAC;QACH,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,QAAQ,EAAE,KAAK,CAAC,QAAQ;KACzB,CAAC;IACF,OAAO,SAAS,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;AAC1C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAKlC;IACC,OAAO,SAAS,CACd,YAAY,CAAC;QACX,CAAC,EAAE,mBAAmB;QACtB,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,MAAM,EAAE,GAAG,CAAC,MAAM,IAAI,IAAI;KAC3B,CAAC,CACH,CAAC;AACJ,CAAC"}
@@ -0,0 +1,375 @@
1
+ export type JsonSchema = {
2
+ type: "string";
3
+ enum?: string[];
4
+ /** wire convention for revived types (e.g. Date); validator enforces parseability */
5
+ format?: "date-time";
6
+ description?: string;
7
+ $defs?: Record<string, JsonSchema>;
8
+ } | {
9
+ type: "number" | "boolean";
10
+ description?: string;
11
+ $defs?: Record<string, JsonSchema>;
12
+ } | {
13
+ type: "array";
14
+ items: JsonSchema;
15
+ description?: string;
16
+ $defs?: Record<string, JsonSchema>;
17
+ } | {
18
+ type: "object";
19
+ properties: Record<string, JsonSchema>;
20
+ required: string[];
21
+ additionalProperties: false;
22
+ description?: string;
23
+ $defs?: Record<string, JsonSchema>;
24
+ } | {
25
+ $ref: string;
26
+ description?: string;
27
+ $defs?: Record<string, JsonSchema>;
28
+ };
29
+ export declare const INTENT_BRAND: "nola.intent";
30
+ /**
31
+ * The site of an ask: project-relative display file + "line:col"
32
+ * (both 1-based; "?" when the site is unknown). The human-facing form is
33
+ * `file:line:col`. Frozen and JSON-serializable ({ file, loc }).
34
+ */
35
+ export declare class Site {
36
+ readonly file: string;
37
+ readonly loc: string;
38
+ constructor(file: string, loc: string);
39
+ toString(): string;
40
+ /**
41
+ * Strict inverse of toString(). loc is matched from the right ("line:col"
42
+ * or "?"), so a file path containing ":" cannot confuse it. Throws on
43
+ * anything else — parse failures are programmer errors, not NOLA codes.
44
+ */
45
+ static parse(text: string): Site;
46
+ }
47
+ /**
48
+ * The emit contract between compiler output and the `__nola` runtime
49
+ * namespace. Bump ONLY when the lowered-code ↔ runtime contract changes
50
+ * shape or semantics (new/renamed factory or helper, changed argument
51
+ * meaning, changed context protocol). Routine releases leave it alone.
52
+ * The surface-snapshot test in packages/runtime/test/emit-surface.test.ts
53
+ * fails when the surface changes without a bump.
54
+ * Emit 5: ask-site schemas are `__nola.types` combinator expressions
55
+ * (InferType carrier) with per-file `__nola_type_<Name>` accessors in the
56
+ * EOF appendix; recursion is legal via named refs ($defs/$ref).
57
+ * Emit 6: `__nola.types.unsupported` (companion modules for cross-file types).
58
+ * Emit 7: ExtractIntent's init renames — the InferType expression moves under
59
+ * `type` (was `schema` — a misnomer since the emit-5 carrier switch) and the
60
+ * backtick text under `instruction` (was `message`), unifying the name for
61
+ * authored backtick text across intents and the infer-function scope.
62
+ * Emit 8: function scopes come from `__nola_file_ctx().func({ fn, instruction,
63
+ * args })` with harvested params; the file accessor moves under
64
+ * `__nola.context.file`.
65
+ * Emit 9: `__nola.types.date` — `Date` lowers to a string schema carrying
66
+ * format: "date-time"; the intent revives the wire string to a Date.
67
+ */
68
+ export declare const NOLA_EMIT = 10;
69
+ /**
70
+ * The narrow public tier: an intent resolvable ONLY through `ask` — what a
71
+ * raw `..` extractor or call intent is. Not thenable (bare await/run on one
72
+ * throws NOLA3010 at runtime, so the type does not offer it) and no
73
+ * root-only knobs (timeout/detached act when an intent roots an invocation,
74
+ * which these never do). The fluent methods clone.
75
+ *
76
+ * T is deliberately phantom — it appears only in the fluent returns, so
77
+ * differently-parameterized Askables collapse structurally. Any member that
78
+ * used T (even symbol-keyed) would surface in editor completion, and a clean
79
+ * completion list IS this interface's purpose; `ask` still infers T from the
80
+ * type reference (or, for class-typed operands, through the class's `then`).
81
+ */
82
+ export interface Askable<T = unknown> {
83
+ /** extra whole-ask attempts, flat (no backoff) — unrelated to the provider-level `withRetry` combinator */
84
+ withRetry(retries: number): Askable<T>;
85
+ withProvider(provider: ProviderRef): Askable<T>;
86
+ /** wire-tuning knobs, shallow-merged over any params already on the intent */
87
+ withParams(params: ProviderParams): Askable<T>;
88
+ }
89
+ /**
90
+ * A lazy, thenable intent (the async/await analogy) — what calling an infer
91
+ * function returns. `ask`/`await` resolves it to `T`; the fluent methods
92
+ * clone. Implemented as a class in `@nola-lang/runtime` (the class carries
93
+ * the runtime `__nolaBrand`; the public type deliberately does not); not
94
+ * JSON-serializable (it holds an executor closure).
95
+ */
96
+ export interface Intent<T = unknown> extends Askable<T>, PromiseLike<T> {
97
+ /** extra whole-ask attempts, flat (no backoff) — unrelated to the provider-level `withRetry` combinator */
98
+ withRetry(retries: number): Intent<T>;
99
+ withProvider(provider: ProviderRef): Intent<T>;
100
+ /** per-invocation timeout in ms when this intent roots the invocation; 0 disables */
101
+ withTimeout(timeout: number): Intent<T>;
102
+ /** wire-tuning knobs, shallow-merged over any params already on the intent */
103
+ withParams(params: ProviderParams): Intent<T>;
104
+ /** resolve without inheriting the caller frame's context (stack-frame opt-out) */
105
+ detached(): Intent<T>;
106
+ }
107
+ export type Message = {
108
+ role: "user" | "assistant";
109
+ content: string;
110
+ };
111
+ export type JsonProviderOutput = {
112
+ /** wire syntax of the expected reply text */
113
+ syntax: "json";
114
+ /** contract for the parsed value; absent = any value / free text */
115
+ schema?: JsonSchema;
116
+ };
117
+ export type CodeProviderOutput = {
118
+ syntax: "code";
119
+ /** syntax "code" only: fence language hint ("ts", "sql", …) */
120
+ language?: string;
121
+ };
122
+ export type ProviderOutput = JsonProviderOutput | CodeProviderOutput;
123
+ /**
124
+ * Wire-tuning knobs an intent can set (.withParams). Absent fields mean
125
+ * "provider default". Part of the ask fingerprint — two asks differing only
126
+ * in params never share a cache/replay entry.
127
+ */
128
+ export interface ProviderParams {
129
+ temperature?: number;
130
+ maxOutputTokens?: number;
131
+ /**
132
+ * Opaque provider-specific knobs (reasoning budget, top_p, penalties, …) —
133
+ * passed through to NolaProvider.complete untouched. Merged per key like
134
+ * the typed fields; must be JSON-serializable (it joins the fingerprint).
135
+ */
136
+ providerOptions?: Record<string, unknown>;
137
+ }
138
+ /**
139
+ * The one merge rule for ProviderParams: patch fields win per field, and
140
+ * providerOptions merges per key rather than being replaced wholesale. Used
141
+ * by .withParams() chaining and by frame-chain resolution.
142
+ */
143
+ export declare function mergeProviderParams(base?: ProviderParams, patch?: ProviderParams): ProviderParams | undefined;
144
+ export interface ProviderRequest {
145
+ system: string;
146
+ messages: Message[];
147
+ output: ProviderOutput;
148
+ params?: ProviderParams;
149
+ signal?: AbortSignal;
150
+ }
151
+ export type ProviderResponse = {
152
+ text: string;
153
+ durationMs?: number;
154
+ };
155
+ export interface NolaProvider {
156
+ name: string;
157
+ complete(req: ProviderRequest): Promise<ProviderResponse>;
158
+ }
159
+ export type ProviderRef = NolaProvider | string;
160
+ export type NolaLogLevel = "silent" | "error" | "warn" | "info" | "debug";
161
+ export interface AskReceipt {
162
+ askId: string;
163
+ site: Site;
164
+ /** the composed conversation as first composed for this ask */
165
+ originalPrompt: string;
166
+ /** as last sent to the provider — diverges on a correction retry (and future middleware rewrites) */
167
+ effectivePrompt: string;
168
+ schema: JsonSchema;
169
+ /** provider name, or a middleware label such as "cache" on a short-circuit */
170
+ servedBy: string;
171
+ /** provider round trips actually performed (0 on a short-circuit) */
172
+ attempts: number;
173
+ outcome: {
174
+ ok: true;
175
+ value: unknown;
176
+ } | {
177
+ ok: false;
178
+ error: string;
179
+ };
180
+ usage?: {
181
+ inputTokens?: number;
182
+ outputTokens?: number;
183
+ };
184
+ durationMs: number;
185
+ meta: Record<string, unknown>;
186
+ /** invocation this ask belongs to (absent only for legacy synthesized receipts) */
187
+ invocationId?: string;
188
+ /** invocationIds from root frame to owning frame */
189
+ spanPath?: readonly string[];
190
+ /** canonical ask fingerprint (absent when a middleware short-circuited before the terminal) */
191
+ fingerprint?: string;
192
+ }
193
+ export interface AttemptRecord {
194
+ attempt: number;
195
+ provider: string;
196
+ durationMs: number;
197
+ validationError?: string;
198
+ }
199
+ export interface AskSpanTrace {
200
+ kind: "ask";
201
+ askId: string;
202
+ site: Site;
203
+ originalPrompt: string;
204
+ effectivePrompt: string;
205
+ schema: JsonSchema;
206
+ attempts: AttemptRecord[];
207
+ servedBy: string;
208
+ outcome: {
209
+ ok: true;
210
+ value: unknown;
211
+ } | {
212
+ ok: false;
213
+ error: string;
214
+ };
215
+ durationMs: number;
216
+ fingerprint?: string;
217
+ }
218
+ export interface InvocationTrace {
219
+ kind: "invocation";
220
+ invocationId: string;
221
+ fn: string;
222
+ file: string;
223
+ spans: Array<AskSpanTrace | InvocationTrace>;
224
+ }
225
+ export interface AskStartEvent {
226
+ readonly askId: string;
227
+ readonly site: Site;
228
+ readonly provider: string;
229
+ }
230
+ export interface ProviderRequestEvent {
231
+ readonly askId: string;
232
+ readonly attempt: number;
233
+ readonly provider: string;
234
+ readonly messages: ReadonlyArray<{
235
+ role: "user" | "assistant";
236
+ content: string;
237
+ }>;
238
+ }
239
+ export interface ProviderResponseEvent {
240
+ readonly askId: string;
241
+ readonly attempt: number;
242
+ readonly provider: string;
243
+ readonly text: string;
244
+ readonly durationMs: number;
245
+ }
246
+ export interface ValidationFailedEvent {
247
+ readonly askId: string;
248
+ readonly attempt: number;
249
+ readonly error: string;
250
+ readonly site: Site;
251
+ }
252
+ export interface RetryEvent {
253
+ readonly askId: string;
254
+ readonly attempt: number;
255
+ readonly reason: string;
256
+ readonly site: Site;
257
+ }
258
+ export interface AskEndEvent {
259
+ readonly askId: string;
260
+ readonly receipt: AskReceipt;
261
+ }
262
+ export interface InvocationEndEvent {
263
+ readonly invocationId: string;
264
+ readonly trace: InvocationTrace;
265
+ }
266
+ /**
267
+ * Observers. Fed from fixed points OUTSIDE the middleware pipeline, so middleware
268
+ * cannot suppress them. Hooks may not mutate payloads or short-circuit; a throwing
269
+ * hook is swallowed with one warning.
270
+ */
271
+ export interface NolaHook {
272
+ name?: string;
273
+ onAskStart?(event: AskStartEvent): void;
274
+ onProviderRequest?(event: ProviderRequestEvent): void;
275
+ onProviderResponse?(event: ProviderResponseEvent): void;
276
+ onValidationFailed?(event: ValidationFailedEvent): void;
277
+ onRetry?(event: RetryEvent): void;
278
+ onAskEnd?(event: AskEndEvent): void;
279
+ onInvocationEnd?(event: InvocationEndEvent): void;
280
+ }
281
+ /**
282
+ * The mutable state of one ask as it travels the middleware pipeline.
283
+ * Runtime-owned fields are readonly at the type level and frozen at runtime:
284
+ * assigning to them is a compile error AND a TypeError.
285
+ */
286
+ export interface AskContext {
287
+ readonly askId: string;
288
+ readonly site: Site;
289
+ readonly abortSignal: AbortSignal;
290
+ /** effective prompt; starts equal to originalPrompt */
291
+ /** re-route before the wire; ignored when config.forceProvider is set */
292
+ provider?: ProviderRef;
293
+ /** cross-stage scratch; lands in the receipt */
294
+ meta: Record<string, unknown>;
295
+ }
296
+ export interface AskResult {
297
+ /** must validate against ctx.schema, including on a short-circuit */
298
+ value: unknown;
299
+ /** provider name, or a middleware label such as "cache" */
300
+ servedBy: string;
301
+ }
302
+ /** In the call path: may mutate, short-circuit (return without calling next), or throw. */
303
+ export type NolaMiddleware = (ctx: AskContext, next: (ctx: AskContext) => Promise<AskResult>) => Promise<AskResult>;
304
+ /** Fingerprint-keyed cache. get() returning undefined means miss (values are JSON, never undefined). */
305
+ export interface NolaCacheStore {
306
+ get(fingerprint: string): unknown | Promise<unknown>;
307
+ set(fingerprint: string, value: unknown): void | Promise<void>;
308
+ }
309
+ /**
310
+ * What the lowering does when a `..`-contextual parameter's type cannot be
311
+ * derived into an intent schema: fail the compile, drop just the underivable
312
+ * members (keeping the rest of the type), or drop the whole type silently.
313
+ */
314
+ export type UnderivableContextTypeMode = "error" | "prune" | "omit";
315
+ /** Compile-time behavior. Read by `nola build`/`check` and the loader; the runtime ignores it. */
316
+ export interface NolaCompilerConfig {
317
+ /** Policy for underivable `..`-contextual parameter types. Default: "error". */
318
+ underivableContextType?: UnderivableContextTypeMode;
319
+ }
320
+ export interface NolaConfig {
321
+ /** Named providers. `default` is required; other names are user-chosen. */
322
+ providers: {
323
+ default: NolaProvider;
324
+ } & Record<string, NolaProvider>;
325
+ /**
326
+ * Hermetic force-all override: when set, EVERY ask resolves through this
327
+ * provider, including intents pinned with .withProvider(). Must name a key
328
+ * of `providers`. Drive it from env: `process.env.CI ? "mock" : undefined`.
329
+ */
330
+ forceProvider?: string;
331
+ observability?: {
332
+ logLevel?: NolaLogLevel;
333
+ };
334
+ /** Ordered pipeline around every resolution; the first entry is outermost. */
335
+ middleware?: NolaMiddleware[];
336
+ /** Observers; all hooks receive all events. Order is not meaningful. */
337
+ hooks?: NolaHook[];
338
+ /** Opt-in ask cache keyed by canonical fingerprint. Omit `store` for in-memory. */
339
+ cache?: {
340
+ store?: NolaCacheStore;
341
+ };
342
+ /** Extra system-prompt text, composed after the Nola protocol preamble on every ask. */
343
+ system?: {
344
+ message?: string;
345
+ };
346
+ /**
347
+ * Ask-path knobs. timeoutMs is the default per-invocation timeout in
348
+ * milliseconds — the root frame's abort signal fires when it elapses; every
349
+ * provider call receives that signal. 0 disables. Intents override it with
350
+ * .withTimeout(ms).
351
+ */
352
+ ask?: {
353
+ timeoutMs?: number;
354
+ };
355
+ /** Compile-time behavior; validated here, consumed by build/check/loader — never by the runtime. */
356
+ compiler?: NolaCompilerConfig;
357
+ /** Reserved for a future Nola version. Rejected at load. */
358
+ plugins?: never;
359
+ }
360
+ /**
361
+ * One completed ask as later prompts may see it. Lives in core (not the
362
+ * runtime's Frame) because fingerprinting hashes history and providers
363
+ * (record/replay) consume fingerprints — neither may depend on the runtime.
364
+ */
365
+ export interface HistoryRecord {
366
+ prompt: string;
367
+ /** what the program received */
368
+ value: unknown;
369
+ /** what subsequent prompts see; reserved — no user API sets it in Phase 1 */
370
+ promptValue?: unknown;
371
+ }
372
+ export { NolaConfigError, NolaIntentError, NolaProviderError, NolaResolutionError, NolaSchemaError, NolaVersionError, type ProviderErrorOptions, type ResolutionDetails, type VersionDetails, } from "./errors.js";
373
+ export { type AskFingerprintInput, canonicalize, FINGERPRINT_VERSION, fingerprintAsk, fingerprintRequest, sha256Hex, } from "./fingerprint.js";
374
+ export { redactError, redactSecrets } from "./redact.js";
375
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAClB;IACA,IAAI,EAAE,QAAQ,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,qFAAqF;IACrF,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;CACpC,GACC;IAAE,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;CAAE,GACxF;IAAE,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AAE,MAAM,CAAC;IACf,gCAAgC;IAChC,KAAK,EAAE,OAAO,CAAC;IACf,6EAA6E;IAC7E,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,OAAO,EACL,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACtB,KAAK,cAAc,GACpB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,mBAAmB,EACxB,YAAY,EACZ,mBAAmB,EACnB,cAAc,EACd,kBAAkB,EAClB,SAAS,GACV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,69 @@
1
+ export const INTENT_BRAND = "nola.intent";
2
+ /**
3
+ * The site of an ask: project-relative display file + "line:col"
4
+ * (both 1-based; "?" when the site is unknown). The human-facing form is
5
+ * `file:line:col`. Frozen and JSON-serializable ({ file, loc }).
6
+ */
7
+ export class Site {
8
+ file;
9
+ loc;
10
+ constructor(file, loc) {
11
+ this.file = file;
12
+ this.loc = loc;
13
+ Object.freeze(this);
14
+ }
15
+ toString() {
16
+ return `${this.file}:${this.loc}`;
17
+ }
18
+ /**
19
+ * Strict inverse of toString(). loc is matched from the right ("line:col"
20
+ * or "?"), so a file path containing ":" cannot confuse it. Throws on
21
+ * anything else — parse failures are programmer errors, not NOLA codes.
22
+ */
23
+ static parse(text) {
24
+ const m = /^([\s\S]+):(\d+:\d+|\?)$/.exec(text);
25
+ if (!m)
26
+ throw new Error(`not a source location: ${text}`);
27
+ return new Site(m[1], m[2]);
28
+ }
29
+ }
30
+ /**
31
+ * The emit contract between compiler output and the `__nola` runtime
32
+ * namespace. Bump ONLY when the lowered-code ↔ runtime contract changes
33
+ * shape or semantics (new/renamed factory or helper, changed argument
34
+ * meaning, changed context protocol). Routine releases leave it alone.
35
+ * The surface-snapshot test in packages/runtime/test/emit-surface.test.ts
36
+ * fails when the surface changes without a bump.
37
+ * Emit 5: ask-site schemas are `__nola.types` combinator expressions
38
+ * (InferType carrier) with per-file `__nola_type_<Name>` accessors in the
39
+ * EOF appendix; recursion is legal via named refs ($defs/$ref).
40
+ * Emit 6: `__nola.types.unsupported` (companion modules for cross-file types).
41
+ * Emit 7: ExtractIntent's init renames — the InferType expression moves under
42
+ * `type` (was `schema` — a misnomer since the emit-5 carrier switch) and the
43
+ * backtick text under `instruction` (was `message`), unifying the name for
44
+ * authored backtick text across intents and the infer-function scope.
45
+ * Emit 8: function scopes come from `__nola_file_ctx().func({ fn, instruction,
46
+ * args })` with harvested params; the file accessor moves under
47
+ * `__nola.context.file`.
48
+ * Emit 9: `__nola.types.date` — `Date` lowers to a string schema carrying
49
+ * format: "date-time"; the intent revives the wire string to a Date.
50
+ */
51
+ export const NOLA_EMIT = 10;
52
+ /**
53
+ * The one merge rule for ProviderParams: patch fields win per field, and
54
+ * providerOptions merges per key rather than being replaced wholesale. Used
55
+ * by .withParams() chaining and by frame-chain resolution.
56
+ */
57
+ export function mergeProviderParams(base, patch) {
58
+ if (!base || !patch)
59
+ return patch ?? base;
60
+ const merged = { ...base, ...patch };
61
+ if (base.providerOptions && patch.providerOptions) {
62
+ merged.providerOptions = { ...base.providerOptions, ...patch.providerOptions };
63
+ }
64
+ return merged;
65
+ }
66
+ export { NolaConfigError, NolaIntentError, NolaProviderError, NolaResolutionError, NolaSchemaError, NolaVersionError, } from "./errors.js";
67
+ export { canonicalize, FINGERPRINT_VERSION, fingerprintAsk, fingerprintRequest, sha256Hex, } from "./fingerprint.js";
68
+ export { redactError, redactSecrets } from "./redact.js";
69
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAqBA,MAAM,CAAC,MAAM,YAAY,GAAG,aAAsB,CAAC;AAEnD;;;;GAIG;AACH,MAAM,OAAO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EAEL,YAAY,EACZ,mBAAmB,EACnB,cAAc,EACd,kBAAkB,EAClB,SAAS,GACV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,5 @@
1
+ /** Replace anything that looks like a credential with `[redacted]`. */
2
+ export declare function redactSecrets(text: string): string;
3
+ /** Render any thrown value as a redacted single-line string. */
4
+ export declare function redactError(error: unknown): string;
5
+ //# sourceMappingURL=redact.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redact.d.ts","sourceRoot":"","sources":["../src/redact.ts"],"names":[],"mappings":"AAUA,uEAAuE;AACvE,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAUlD;AAED,gEAAgE;AAChE,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAElD"}
package/dist/redact.js ADDED
@@ -0,0 +1,25 @@
1
+ // Dependency-free leaf module: provider error bodies echo key fingerprints, and the
2
+ // runtime re-throws them into user stacks and persists them into receipts.
3
+ const PATTERNS = [
4
+ /\b(?:sk|rk|pk)-[A-Za-z0-9_-]{8,}/g, // OpenAI-family keys
5
+ /\bAIza[0-9A-Za-z_-]{10,}/g, // Google API keys
6
+ /\b(?:Bearer|Basic)\s+[A-Za-z0-9._~+/=-]{8,}/gi, // Authorization values
7
+ /\b[0-9a-f]{32,}\b/gi, // long hex blobs (key fingerprints)
8
+ ];
9
+ /** Replace anything that looks like a credential with `[redacted]`. */
10
+ export function redactSecrets(text) {
11
+ let out = text;
12
+ for (const pattern of PATTERNS) {
13
+ out = out.replace(pattern, (match) => {
14
+ const space = match.indexOf(" ");
15
+ // keep the scheme word ("Bearer"/"Basic"), redact only the value
16
+ return space === -1 ? "[redacted]" : `${match.slice(0, space)} [redacted]`;
17
+ });
18
+ }
19
+ return out;
20
+ }
21
+ /** Render any thrown value as a redacted single-line string. */
22
+ export function redactError(error) {
23
+ return redactSecrets(error instanceof Error ? error.message : String(error));
24
+ }
25
+ //# sourceMappingURL=redact.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redact.js","sourceRoot":"","sources":["../src/redact.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,2EAA2E;AAE3E,MAAM,QAAQ,GAAsB;IAClC,mCAAmC,EAAE,qBAAqB;IAC1D,2BAA2B,EAAE,kBAAkB;IAC/C,+CAA+C,EAAE,uBAAuB;IACxE,qBAAqB,EAAE,oCAAoC;CAC5D,CAAC;AAEF,uEAAuE;AACvE,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,IAAI,GAAG,GAAG,IAAI,CAAC;IACf,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YACnC,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YACjC,iEAAiE;YACjE,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;QAC7E,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,OAAO,aAAa,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAC/E,CAAC"}
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@nola-lang/core",
3
+ "version": "0.1.0-alpha.0",
4
+ "description": "Core types and shared utilities for the Nola toolchain (internal)",
5
+ "keywords": [
6
+ "nola"
7
+ ],
8
+ "license": "MIT",
9
+ "author": "Evgen Mykhailenko",
10
+ "homepage": "https://github.com/nola-lang/nola#readme",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/nola-lang/nola.git",
14
+ "directory": "packages/core"
15
+ },
16
+ "bugs": {
17
+ "url": "https://github.com/nola-lang/nola/issues"
18
+ },
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "type": "module",
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/index.d.ts",
26
+ "default": "./dist/index.js"
27
+ }
28
+ },
29
+ "files": [
30
+ "dist"
31
+ ],
32
+ "engines": {
33
+ "node": ">=22"
34
+ }
35
+ }