@younndai/lyt-llm 0.9.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.
@@ -0,0 +1,93 @@
1
+ export type LlmSource = "ai-relay" | "ollama" | "harness" | "byok";
2
+ export type LlmCapability = "grunt" | "reasoning" | "embed" | "structured";
3
+ export interface HardConstraint {
4
+ kind: string;
5
+ args?: Record<string, unknown>;
6
+ }
7
+ export interface CostBudget {
8
+ perRunUsd: number;
9
+ monthlyUsd?: number;
10
+ }
11
+ export interface MemscopeContext {
12
+ defaultView?: "private" | "group" | "public";
13
+ redactPiiV3?: boolean;
14
+ }
15
+ export interface GenerateRequest {
16
+ prompt: string;
17
+ system?: string;
18
+ capability?: LlmCapability;
19
+ sourcePreference?: LlmSource[];
20
+ hardConstraints?: HardConstraint[];
21
+ memscope?: MemscopeContext;
22
+ model?: string;
23
+ maxTokens?: number;
24
+ temperature?: number;
25
+ }
26
+ export interface GenerateResult {
27
+ text: string;
28
+ sourceUsed: LlmSource;
29
+ modelUsed: string;
30
+ tokensIn: number;
31
+ tokensOut: number;
32
+ costUsd: number;
33
+ }
34
+ export interface EmbedRequest {
35
+ texts: string[];
36
+ sourcePreference?: LlmSource[];
37
+ hardConstraints?: HardConstraint[];
38
+ memscope?: MemscopeContext;
39
+ model?: string;
40
+ }
41
+ export interface EmbedResult {
42
+ vectors: number[][];
43
+ sourceUsed: LlmSource;
44
+ modelUsed: string;
45
+ tokensIn: number;
46
+ costUsd: number;
47
+ }
48
+ export interface LlmAdapter {
49
+ readonly source: LlmSource;
50
+ supports(mode: "generate" | "embed"): boolean;
51
+ generate(req: GenerateRequest): Promise<GenerateResult>;
52
+ embed(req: EmbedRequest): Promise<EmbedResult>;
53
+ }
54
+ export interface LlmGatewayConfig {
55
+ preference?: LlmSource[];
56
+ costBudget?: CostBudget;
57
+ adapters?: Partial<Record<LlmSource, LlmAdapter>>;
58
+ }
59
+ export interface LlmGateway {
60
+ generate(req: GenerateRequest): Promise<GenerateResult>;
61
+ embed(req: EmbedRequest): Promise<EmbedResult>;
62
+ totalCostUsd(): number;
63
+ totalCalls(): number;
64
+ resetCostTracker(): void;
65
+ registeredSources(): LlmSource[];
66
+ }
67
+ export declare class NoEligibleAdapterError extends Error {
68
+ readonly mode: "generate" | "embed";
69
+ readonly preference: LlmSource[];
70
+ readonly reason: string;
71
+ readonly name = "NoEligibleAdapterError";
72
+ constructor(mode: "generate" | "embed", preference: LlmSource[], reason: string);
73
+ }
74
+ export declare class CostBudgetExceededError extends Error {
75
+ readonly budgetUsd: number;
76
+ readonly accumulatedUsd: number;
77
+ readonly attemptedUsd: number;
78
+ readonly name = "CostBudgetExceededError";
79
+ constructor(budgetUsd: number, accumulatedUsd: number, attemptedUsd: number);
80
+ }
81
+ export declare class HardConstraintViolationError extends Error {
82
+ readonly constraintKind: string;
83
+ readonly source: LlmSource;
84
+ readonly detail: string;
85
+ readonly name = "HardConstraintViolationError";
86
+ constructor(constraintKind: string, source: LlmSource, detail: string);
87
+ }
88
+ export declare class UnknownHardConstraintError extends Error {
89
+ readonly constraintKind: string;
90
+ readonly name = "UnknownHardConstraintError";
91
+ constructor(constraintKind: string);
92
+ }
93
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AA8BA,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,CAAC;AAEnE,MAAM,MAAM,aAAa,GACrB,OAAO,GACP,WAAW,GACX,OAAO,GACP,YAAY,CAAC;AAejB,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,UAAU;IAIzB,SAAS,EAAE,MAAM,CAAC;IAIlB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB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,MAAM,EAAE,SAAS;aACjB,MAAM,EAAE,MAAM;IAJhC,SAAkB,IAAI,kCAAkC;gBAEtC,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,MAAM;CAIjC;AAED,qBAAa,0BAA2B,SAAQ,KAAK;aAEvB,cAAc,EAAE,MAAM;IADlD,SAAkB,IAAI,gCAAgC;gBAC1B,cAAc,EAAE,MAAM;CAKnD"}
package/dist/types.js ADDED
@@ -0,0 +1,63 @@
1
+ /*
2
+ * Copyright 2026 MARLINK TRADING SRL (YounndAI)
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ // Errors surfaced at the gateway boundary. Each carries enough context for
17
+ // the lyt-runner pre-write hook (block-B Commit 5) to write a structured
18
+ // automator_run_events row.
19
+ export class NoEligibleAdapterError extends Error {
20
+ mode;
21
+ preference;
22
+ reason;
23
+ name = "NoEligibleAdapterError";
24
+ constructor(mode, preference, reason) {
25
+ super(`No eligible LLM adapter for mode=${mode} after applying preference=[${preference.join(",")}]: ${reason}`);
26
+ this.mode = mode;
27
+ this.preference = preference;
28
+ this.reason = reason;
29
+ }
30
+ }
31
+ export class CostBudgetExceededError extends Error {
32
+ budgetUsd;
33
+ accumulatedUsd;
34
+ attemptedUsd;
35
+ name = "CostBudgetExceededError";
36
+ constructor(budgetUsd, accumulatedUsd, attemptedUsd) {
37
+ super(`Cost budget exceeded: budget=${budgetUsd.toFixed(4)}, accumulated=${accumulatedUsd.toFixed(4)}, this-call=${attemptedUsd.toFixed(4)}`);
38
+ this.budgetUsd = budgetUsd;
39
+ this.accumulatedUsd = accumulatedUsd;
40
+ this.attemptedUsd = attemptedUsd;
41
+ }
42
+ }
43
+ export class HardConstraintViolationError extends Error {
44
+ constraintKind;
45
+ source;
46
+ detail;
47
+ name = "HardConstraintViolationError";
48
+ constructor(constraintKind, source, detail) {
49
+ super(`Hard constraint '${constraintKind}' rejects source '${source}': ${detail}`);
50
+ this.constraintKind = constraintKind;
51
+ this.source = source;
52
+ this.detail = detail;
53
+ }
54
+ }
55
+ export class UnknownHardConstraintError extends Error {
56
+ constraintKind;
57
+ name = "UnknownHardConstraintError";
58
+ constructor(constraintKind) {
59
+ super(`Unknown hard constraint kind '${constraintKind}'. Known kinds: local_only, never_external_when_private_memscope, max_cost_per_run_usd, provider`);
60
+ this.constraintKind = constraintKind;
61
+ }
62
+ }
63
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAoJH,2EAA2E;AAC3E,yEAAyE;AACzE,4BAA4B;AAE5B,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAG7B;IACA;IACA;IAJA,IAAI,GAAG,wBAAwB,CAAC;IAClD,YACkB,IAA0B,EAC1B,UAAuB,EACvB,MAAc;QAE9B,KAAK,CACH,oCAAoC,IAAI,+BAA+B,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,MAAM,EAAE,CAC1G,CAAC;QANc,SAAI,GAAJ,IAAI,CAAsB;QAC1B,eAAU,GAAV,UAAU,CAAa;QACvB,WAAM,GAAN,MAAM,CAAQ;IAKhC,CAAC;CACF;AAED,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAG9B;IACA;IACA;IAJA,IAAI,GAAG,yBAAyB,CAAC;IACnD,YACkB,SAAiB,EACjB,cAAsB,EACtB,YAAoB;QAEpC,KAAK,CACH,gCAAgC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,iBAAiB,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CACvI,CAAC;QANc,cAAS,GAAT,SAAS,CAAQ;QACjB,mBAAc,GAAd,cAAc,CAAQ;QACtB,iBAAY,GAAZ,YAAY,CAAQ;IAKtC,CAAC;CACF;AAED,MAAM,OAAO,4BAA6B,SAAQ,KAAK;IAGnC;IACA;IACA;IAJA,IAAI,GAAG,8BAA8B,CAAC;IACxD,YACkB,cAAsB,EACtB,MAAiB,EACjB,MAAc;QAE9B,KAAK,CAAC,oBAAoB,cAAc,qBAAqB,MAAM,MAAM,MAAM,EAAE,CAAC,CAAC;QAJnE,mBAAc,GAAd,cAAc,CAAQ;QACtB,WAAM,GAAN,MAAM,CAAW;QACjB,WAAM,GAAN,MAAM,CAAQ;IAGhC,CAAC;CACF;AAED,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IAEvB;IADV,IAAI,GAAG,4BAA4B,CAAC;IACtD,YAA4B,cAAsB;QAChD,KAAK,CACH,iCAAiC,cAAc,kGAAkG,CAClJ,CAAC;QAHwB,mBAAc,GAAd,cAAc,CAAQ;IAIlD,CAAC;CACF"}
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@younndai/lyt-llm",
3
+ "version": "0.9.0",
4
+ "description": "Lyt LLM gateway — multi-source LLM routing for AI-assisted vault operations. Composes 4 adapters (ai-relay external / Ollama local / Claude Code-Codex harness / BYOK) behind a single createLlmGateway() surface, with per-automator source preferences, hard constraints, and a per-run cost-budget hard-stop. Registers std:llm.* ops with @younndai/lyt-runner.",
5
+ "homepage": "https://linkyourthink.com",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/younndai/lyt",
9
+ "directory": "packages/lyt-llm"
10
+ },
11
+ "author": {
12
+ "name": "MARLINK TRADING SRL (YounndAI)",
13
+ "url": "https://younndai.com"
14
+ },
15
+ "contributors": [
16
+ {
17
+ "name": "Alexandru Mareș",
18
+ "url": "https://allemaar.com"
19
+ }
20
+ ],
21
+ "license": "Apache-2.0",
22
+ "engines": {
23
+ "node": ">=20.9",
24
+ "npm": ">=10"
25
+ },
26
+ "type": "module",
27
+ "main": "./dist/index.js",
28
+ "types": "./dist/index.d.ts",
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/index.d.ts",
32
+ "import": "./dist/index.js"
33
+ }
34
+ },
35
+ "files": [
36
+ "dist",
37
+ "README.md",
38
+ "LICENSE",
39
+ "NOTICE"
40
+ ],
41
+ "scripts": {
42
+ "build": "tsc",
43
+ "typecheck": "tsc --noEmit",
44
+ "test": "vitest run",
45
+ "test:watch": "vitest",
46
+ "clean": "rimraf --glob dist .turbo *.tsbuildinfo",
47
+ "prepack": "npm run clean && npm run build",
48
+ "prepublishOnly": "node ../../scripts/check-no-vendored-deps.mjs --root ../.."
49
+ },
50
+ "dependencies": {
51
+ "@younndai/ai-relay": "^3.0.0"
52
+ },
53
+ "devDependencies": {
54
+ "@lyt/typescript-config": "*",
55
+ "@types/node": "^22.10.5",
56
+ "rimraf": "*",
57
+ "typescript": "*",
58
+ "vitest": "*"
59
+ },
60
+ "publishConfig": {
61
+ "access": "public"
62
+ },
63
+ "keywords": [
64
+ "lyt",
65
+ "llm",
66
+ "ai",
67
+ "ollama",
68
+ "byok",
69
+ "younndai"
70
+ ]
71
+ }