@kaleabdenbel/llmweb 1.0.3 → 1.0.5
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/README.md +9 -3
- package/dist/adapters/express.d.mts +8 -0
- package/dist/adapters/express.d.ts +8 -0
- package/dist/adapters/express.js +39 -13
- package/dist/adapters/express.mjs +29 -13
- package/dist/adapters/next.d.mts +21 -0
- package/dist/adapters/next.d.ts +21 -0
- package/dist/adapters/next.js +39 -13
- package/dist/adapters/next.mjs +29 -13
- package/dist/adapters/react.d.mts +24 -0
- package/dist/adapters/react.d.ts +24 -0
- package/dist/adapters/react.js +32 -16
- package/dist/adapters/react.mjs +32 -16
- package/dist/adapters/vanilla.d.mts +8 -0
- package/dist/adapters/vanilla.d.ts +8 -0
- package/dist/adapters/vanilla.js +39 -13
- package/dist/adapters/vanilla.mjs +29 -13
- package/dist/cli.js +562 -0
- package/dist/index-B8G8cw7b.d.mts +50 -0
- package/dist/index-B8G8cw7b.d.ts +50 -0
- package/dist/index.browser.d.mts +10 -0
- package/dist/index.browser.d.ts +10 -0
- package/dist/index.browser.js +12 -7
- package/dist/index.browser.mjs +12 -7
- package/dist/index.d.mts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +39 -15
- package/dist/index.mjs +29 -15
- package/dist/injector-CXZdcvik.d.mts +22 -0
- package/dist/injector-D0jrfa25.d.ts +22 -0
- package/package.json +19 -9
package/README.md
CHANGED
|
@@ -11,13 +11,19 @@ The data compiler that transforms messy application state into LLM-readable trut
|
|
|
11
11
|
- **The Engine**: Compiles these into a single, structured JSON object for LLMs.
|
|
12
12
|
- **Framework Adapters**: Utilities for [Next.js](docs/next.md), [React](docs/react.md), [Express](docs/express.md), and [Vanilla JS](docs/vanilla.md).
|
|
13
13
|
|
|
14
|
-
##
|
|
14
|
+
## Quick Start
|
|
15
|
+
|
|
16
|
+
The fastest way to get started is using the CLI:
|
|
15
17
|
|
|
16
18
|
```bash
|
|
17
|
-
|
|
19
|
+
npx llmweb init
|
|
18
20
|
```
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
For a deep dive into the **Bridge Pattern**, **Server Actions**, and **Advanced Mapping**, check out our [Definitive Guide](docs/guide.md).
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Integration (Next.js)
|
|
21
27
|
|
|
22
28
|
### 1. Define your Truth
|
|
23
29
|
|
package/dist/adapters/express.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/adapters/express.ts
|
|
@@ -105,18 +115,23 @@ function merge(staticData, dynamicResults) {
|
|
|
105
115
|
|
|
106
116
|
// src/core/compiler.ts
|
|
107
117
|
async function compileLLM(config, loader, options = {}) {
|
|
108
|
-
|
|
109
|
-
|
|
118
|
+
const { static: staticRef, dynamic, ...topLevelMetadata } = config;
|
|
119
|
+
let staticTruth = { ...topLevelMetadata };
|
|
120
|
+
if (staticRef) {
|
|
110
121
|
try {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
122
|
+
if (typeof staticRef === "object") {
|
|
123
|
+
staticTruth = { ...staticTruth, ...staticRef };
|
|
124
|
+
} else {
|
|
125
|
+
const content = await loader(staticRef);
|
|
126
|
+
if (content) {
|
|
127
|
+
staticTruth = { ...staticTruth, ...JSON.parse(content) };
|
|
128
|
+
}
|
|
114
129
|
}
|
|
115
130
|
} catch (error) {
|
|
116
131
|
if (options.failLoudly) {
|
|
117
|
-
throw new Error(`[llmweb] Static Truth Error: Failed to load/parse JSON at ${
|
|
132
|
+
throw new Error(`[llmweb] Static Truth Error: Failed to load/parse JSON at ${staticRef}. ${error}`);
|
|
118
133
|
}
|
|
119
|
-
console.warn(`[llmweb] Warning: Could not load static JSON at ${
|
|
134
|
+
console.warn(`[llmweb] Warning: Could not load static JSON at ${staticRef}. Proceeding with dynamic data only.`);
|
|
120
135
|
}
|
|
121
136
|
}
|
|
122
137
|
const dynamicTruth = {};
|
|
@@ -146,13 +161,24 @@ async function compileLLM(config, loader, options = {}) {
|
|
|
146
161
|
}
|
|
147
162
|
|
|
148
163
|
// src/index.ts
|
|
149
|
-
var import_node_fs = require("fs");
|
|
150
|
-
var import_node_path = require("path");
|
|
151
|
-
var nodeLoader = async (path) => {
|
|
152
|
-
const fullPath = path.startsWith("/") ? path : (0, import_node_path.join)(process.cwd(), path);
|
|
153
|
-
return (0, import_node_fs.readFileSync)(fullPath, "utf-8");
|
|
154
|
-
};
|
|
155
164
|
async function createLLMSource(config, options = {}) {
|
|
165
|
+
const nodeLoader = async (path) => {
|
|
166
|
+
try {
|
|
167
|
+
const fs = await import(
|
|
168
|
+
/* webpackIgnore: true */
|
|
169
|
+
"fs"
|
|
170
|
+
);
|
|
171
|
+
const nodePath = await import(
|
|
172
|
+
/* webpackIgnore: true */
|
|
173
|
+
"path"
|
|
174
|
+
);
|
|
175
|
+
const fullPath = path.startsWith("/") ? path : nodePath.join(process.cwd(), path);
|
|
176
|
+
return fs.readFileSync(fullPath, "utf-8");
|
|
177
|
+
} catch (error) {
|
|
178
|
+
console.warn(`[llmweb] Warning: 'node:fs' not available. Skipping static file load: ${path}`);
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
};
|
|
156
182
|
return compileLLM(config, nodeLoader, options);
|
|
157
183
|
}
|
|
158
184
|
|
|
@@ -79,18 +79,23 @@ function merge(staticData, dynamicResults) {
|
|
|
79
79
|
|
|
80
80
|
// src/core/compiler.ts
|
|
81
81
|
async function compileLLM(config, loader, options = {}) {
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
const { static: staticRef, dynamic, ...topLevelMetadata } = config;
|
|
83
|
+
let staticTruth = { ...topLevelMetadata };
|
|
84
|
+
if (staticRef) {
|
|
84
85
|
try {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
if (typeof staticRef === "object") {
|
|
87
|
+
staticTruth = { ...staticTruth, ...staticRef };
|
|
88
|
+
} else {
|
|
89
|
+
const content = await loader(staticRef);
|
|
90
|
+
if (content) {
|
|
91
|
+
staticTruth = { ...staticTruth, ...JSON.parse(content) };
|
|
92
|
+
}
|
|
88
93
|
}
|
|
89
94
|
} catch (error) {
|
|
90
95
|
if (options.failLoudly) {
|
|
91
|
-
throw new Error(`[llmweb] Static Truth Error: Failed to load/parse JSON at ${
|
|
96
|
+
throw new Error(`[llmweb] Static Truth Error: Failed to load/parse JSON at ${staticRef}. ${error}`);
|
|
92
97
|
}
|
|
93
|
-
console.warn(`[llmweb] Warning: Could not load static JSON at ${
|
|
98
|
+
console.warn(`[llmweb] Warning: Could not load static JSON at ${staticRef}. Proceeding with dynamic data only.`);
|
|
94
99
|
}
|
|
95
100
|
}
|
|
96
101
|
const dynamicTruth = {};
|
|
@@ -120,13 +125,24 @@ async function compileLLM(config, loader, options = {}) {
|
|
|
120
125
|
}
|
|
121
126
|
|
|
122
127
|
// src/index.ts
|
|
123
|
-
import { readFileSync } from "fs";
|
|
124
|
-
import { join } from "path";
|
|
125
|
-
var nodeLoader = async (path) => {
|
|
126
|
-
const fullPath = path.startsWith("/") ? path : join(process.cwd(), path);
|
|
127
|
-
return readFileSync(fullPath, "utf-8");
|
|
128
|
-
};
|
|
129
128
|
async function createLLMSource(config, options = {}) {
|
|
129
|
+
const nodeLoader = async (path) => {
|
|
130
|
+
try {
|
|
131
|
+
const fs = await import(
|
|
132
|
+
/* webpackIgnore: true */
|
|
133
|
+
"fs"
|
|
134
|
+
);
|
|
135
|
+
const nodePath = await import(
|
|
136
|
+
/* webpackIgnore: true */
|
|
137
|
+
"path"
|
|
138
|
+
);
|
|
139
|
+
const fullPath = path.startsWith("/") ? path : nodePath.join(process.cwd(), path);
|
|
140
|
+
return fs.readFileSync(fullPath, "utf-8");
|
|
141
|
+
} catch (error) {
|
|
142
|
+
console.warn(`[llmweb] Warning: 'node:fs' not available. Skipping static file load: ${path}`);
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
};
|
|
130
146
|
return compileLLM(config, nodeLoader, options);
|
|
131
147
|
}
|
|
132
148
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { L as LLMConfig } from '../index-B8G8cw7b.mjs';
|
|
3
|
+
|
|
4
|
+
interface LLMJsonProps {
|
|
5
|
+
config: LLMConfig;
|
|
6
|
+
/**
|
|
7
|
+
* Optional custom styling for the rendered JSON if viewing in a browser.
|
|
8
|
+
*/
|
|
9
|
+
className?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A Next.js Server Component that resolves the LLM truth and renders it.
|
|
13
|
+
* By default, it renders a <pre> tag with the JSON string.
|
|
14
|
+
*/
|
|
15
|
+
declare function LLMJson({ config, className }: LLMJsonProps): Promise<react_jsx_runtime.JSX.Element>;
|
|
16
|
+
/**
|
|
17
|
+
* A helper for Next.js App Router Route Handlers (route.ts).
|
|
18
|
+
*/
|
|
19
|
+
declare function createLLMHandler(config: LLMConfig): () => Promise<Response>;
|
|
20
|
+
|
|
21
|
+
export { LLMJson, createLLMHandler };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { L as LLMConfig } from '../index-B8G8cw7b.js';
|
|
3
|
+
|
|
4
|
+
interface LLMJsonProps {
|
|
5
|
+
config: LLMConfig;
|
|
6
|
+
/**
|
|
7
|
+
* Optional custom styling for the rendered JSON if viewing in a browser.
|
|
8
|
+
*/
|
|
9
|
+
className?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A Next.js Server Component that resolves the LLM truth and renders it.
|
|
13
|
+
* By default, it renders a <pre> tag with the JSON string.
|
|
14
|
+
*/
|
|
15
|
+
declare function LLMJson({ config, className }: LLMJsonProps): Promise<react_jsx_runtime.JSX.Element>;
|
|
16
|
+
/**
|
|
17
|
+
* A helper for Next.js App Router Route Handlers (route.ts).
|
|
18
|
+
*/
|
|
19
|
+
declare function createLLMHandler(config: LLMConfig): () => Promise<Response>;
|
|
20
|
+
|
|
21
|
+
export { LLMJson, createLLMHandler };
|
package/dist/adapters/next.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/adapters/next.tsx
|
|
@@ -106,18 +116,23 @@ function merge(staticData, dynamicResults) {
|
|
|
106
116
|
|
|
107
117
|
// src/core/compiler.ts
|
|
108
118
|
async function compileLLM(config, loader, options = {}) {
|
|
109
|
-
|
|
110
|
-
|
|
119
|
+
const { static: staticRef, dynamic, ...topLevelMetadata } = config;
|
|
120
|
+
let staticTruth = { ...topLevelMetadata };
|
|
121
|
+
if (staticRef) {
|
|
111
122
|
try {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
123
|
+
if (typeof staticRef === "object") {
|
|
124
|
+
staticTruth = { ...staticTruth, ...staticRef };
|
|
125
|
+
} else {
|
|
126
|
+
const content = await loader(staticRef);
|
|
127
|
+
if (content) {
|
|
128
|
+
staticTruth = { ...staticTruth, ...JSON.parse(content) };
|
|
129
|
+
}
|
|
115
130
|
}
|
|
116
131
|
} catch (error) {
|
|
117
132
|
if (options.failLoudly) {
|
|
118
|
-
throw new Error(`[llmweb] Static Truth Error: Failed to load/parse JSON at ${
|
|
133
|
+
throw new Error(`[llmweb] Static Truth Error: Failed to load/parse JSON at ${staticRef}. ${error}`);
|
|
119
134
|
}
|
|
120
|
-
console.warn(`[llmweb] Warning: Could not load static JSON at ${
|
|
135
|
+
console.warn(`[llmweb] Warning: Could not load static JSON at ${staticRef}. Proceeding with dynamic data only.`);
|
|
121
136
|
}
|
|
122
137
|
}
|
|
123
138
|
const dynamicTruth = {};
|
|
@@ -147,13 +162,24 @@ async function compileLLM(config, loader, options = {}) {
|
|
|
147
162
|
}
|
|
148
163
|
|
|
149
164
|
// src/index.ts
|
|
150
|
-
var import_node_fs = require("fs");
|
|
151
|
-
var import_node_path = require("path");
|
|
152
|
-
var nodeLoader = async (path) => {
|
|
153
|
-
const fullPath = path.startsWith("/") ? path : (0, import_node_path.join)(process.cwd(), path);
|
|
154
|
-
return (0, import_node_fs.readFileSync)(fullPath, "utf-8");
|
|
155
|
-
};
|
|
156
165
|
async function createLLMSource(config, options = {}) {
|
|
166
|
+
const nodeLoader = async (path) => {
|
|
167
|
+
try {
|
|
168
|
+
const fs = await import(
|
|
169
|
+
/* webpackIgnore: true */
|
|
170
|
+
"fs"
|
|
171
|
+
);
|
|
172
|
+
const nodePath = await import(
|
|
173
|
+
/* webpackIgnore: true */
|
|
174
|
+
"path"
|
|
175
|
+
);
|
|
176
|
+
const fullPath = path.startsWith("/") ? path : nodePath.join(process.cwd(), path);
|
|
177
|
+
return fs.readFileSync(fullPath, "utf-8");
|
|
178
|
+
} catch (error) {
|
|
179
|
+
console.warn(`[llmweb] Warning: 'node:fs' not available. Skipping static file load: ${path}`);
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
};
|
|
157
183
|
return compileLLM(config, nodeLoader, options);
|
|
158
184
|
}
|
|
159
185
|
|
package/dist/adapters/next.mjs
CHANGED
|
@@ -79,18 +79,23 @@ function merge(staticData, dynamicResults) {
|
|
|
79
79
|
|
|
80
80
|
// src/core/compiler.ts
|
|
81
81
|
async function compileLLM(config, loader, options = {}) {
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
const { static: staticRef, dynamic, ...topLevelMetadata } = config;
|
|
83
|
+
let staticTruth = { ...topLevelMetadata };
|
|
84
|
+
if (staticRef) {
|
|
84
85
|
try {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
if (typeof staticRef === "object") {
|
|
87
|
+
staticTruth = { ...staticTruth, ...staticRef };
|
|
88
|
+
} else {
|
|
89
|
+
const content = await loader(staticRef);
|
|
90
|
+
if (content) {
|
|
91
|
+
staticTruth = { ...staticTruth, ...JSON.parse(content) };
|
|
92
|
+
}
|
|
88
93
|
}
|
|
89
94
|
} catch (error) {
|
|
90
95
|
if (options.failLoudly) {
|
|
91
|
-
throw new Error(`[llmweb] Static Truth Error: Failed to load/parse JSON at ${
|
|
96
|
+
throw new Error(`[llmweb] Static Truth Error: Failed to load/parse JSON at ${staticRef}. ${error}`);
|
|
92
97
|
}
|
|
93
|
-
console.warn(`[llmweb] Warning: Could not load static JSON at ${
|
|
98
|
+
console.warn(`[llmweb] Warning: Could not load static JSON at ${staticRef}. Proceeding with dynamic data only.`);
|
|
94
99
|
}
|
|
95
100
|
}
|
|
96
101
|
const dynamicTruth = {};
|
|
@@ -120,13 +125,24 @@ async function compileLLM(config, loader, options = {}) {
|
|
|
120
125
|
}
|
|
121
126
|
|
|
122
127
|
// src/index.ts
|
|
123
|
-
import { readFileSync } from "fs";
|
|
124
|
-
import { join } from "path";
|
|
125
|
-
var nodeLoader = async (path) => {
|
|
126
|
-
const fullPath = path.startsWith("/") ? path : join(process.cwd(), path);
|
|
127
|
-
return readFileSync(fullPath, "utf-8");
|
|
128
|
-
};
|
|
129
128
|
async function createLLMSource(config, options = {}) {
|
|
129
|
+
const nodeLoader = async (path) => {
|
|
130
|
+
try {
|
|
131
|
+
const fs = await import(
|
|
132
|
+
/* webpackIgnore: true */
|
|
133
|
+
"fs"
|
|
134
|
+
);
|
|
135
|
+
const nodePath = await import(
|
|
136
|
+
/* webpackIgnore: true */
|
|
137
|
+
"path"
|
|
138
|
+
);
|
|
139
|
+
const fullPath = path.startsWith("/") ? path : nodePath.join(process.cwd(), path);
|
|
140
|
+
return fs.readFileSync(fullPath, "utf-8");
|
|
141
|
+
} catch (error) {
|
|
142
|
+
console.warn(`[llmweb] Warning: 'node:fs' not available. Skipping static file load: ${path}`);
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
};
|
|
130
146
|
return compileLLM(config, nodeLoader, options);
|
|
131
147
|
}
|
|
132
148
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { L as LLMConfig } from '../index-B8G8cw7b.mjs';
|
|
3
|
+
|
|
4
|
+
interface LLMJsonProps {
|
|
5
|
+
config: LLMConfig;
|
|
6
|
+
mode?: "script" | "window" | "pre";
|
|
7
|
+
targetKey?: string;
|
|
8
|
+
className?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Universal LLMJson component for React environments.
|
|
12
|
+
* Handles server-side resolution in Next.js or client-side resolution (if needed).
|
|
13
|
+
*
|
|
14
|
+
* NOTE: When used in Next.js Server Components, this will be async.
|
|
15
|
+
* In standard Client Components, it expects an async resolution pattern or pre-resolved data.
|
|
16
|
+
*/
|
|
17
|
+
declare function LLMJson({ config, mode, targetKey, className, }: LLMJsonProps): Promise<react_jsx_runtime.JSX.Element>;
|
|
18
|
+
/**
|
|
19
|
+
* Client-side component for injecting LLM truth.
|
|
20
|
+
* Uses useEffect to resolve data, suitable for standard React apps (CRA/Vite).
|
|
21
|
+
*/
|
|
22
|
+
declare function LLMInjector({ config, mode, targetKey, className, }: LLMJsonProps): react_jsx_runtime.JSX.Element | null;
|
|
23
|
+
|
|
24
|
+
export { LLMInjector, LLMJson, type LLMJsonProps };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { L as LLMConfig } from '../index-B8G8cw7b.js';
|
|
3
|
+
|
|
4
|
+
interface LLMJsonProps {
|
|
5
|
+
config: LLMConfig;
|
|
6
|
+
mode?: "script" | "window" | "pre";
|
|
7
|
+
targetKey?: string;
|
|
8
|
+
className?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Universal LLMJson component for React environments.
|
|
12
|
+
* Handles server-side resolution in Next.js or client-side resolution (if needed).
|
|
13
|
+
*
|
|
14
|
+
* NOTE: When used in Next.js Server Components, this will be async.
|
|
15
|
+
* In standard Client Components, it expects an async resolution pattern or pre-resolved data.
|
|
16
|
+
*/
|
|
17
|
+
declare function LLMJson({ config, mode, targetKey, className, }: LLMJsonProps): Promise<react_jsx_runtime.JSX.Element>;
|
|
18
|
+
/**
|
|
19
|
+
* Client-side component for injecting LLM truth.
|
|
20
|
+
* Uses useEffect to resolve data, suitable for standard React apps (CRA/Vite).
|
|
21
|
+
*/
|
|
22
|
+
declare function LLMInjector({ config, mode, targetKey, className, }: LLMJsonProps): react_jsx_runtime.JSX.Element | null;
|
|
23
|
+
|
|
24
|
+
export { LLMInjector, LLMJson, type LLMJsonProps };
|
package/dist/adapters/react.js
CHANGED
|
@@ -117,18 +117,23 @@ function merge(staticData, dynamicResults) {
|
|
|
117
117
|
|
|
118
118
|
// src/core/compiler.ts
|
|
119
119
|
async function compileLLM(config, loader, options = {}) {
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
const { static: staticRef, dynamic, ...topLevelMetadata } = config;
|
|
121
|
+
let staticTruth = { ...topLevelMetadata };
|
|
122
|
+
if (staticRef) {
|
|
122
123
|
try {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
124
|
+
if (typeof staticRef === "object") {
|
|
125
|
+
staticTruth = { ...staticTruth, ...staticRef };
|
|
126
|
+
} else {
|
|
127
|
+
const content = await loader(staticRef);
|
|
128
|
+
if (content) {
|
|
129
|
+
staticTruth = { ...staticTruth, ...JSON.parse(content) };
|
|
130
|
+
}
|
|
126
131
|
}
|
|
127
132
|
} catch (error) {
|
|
128
133
|
if (options.failLoudly) {
|
|
129
|
-
throw new Error(`[llmweb] Static Truth Error: Failed to load/parse JSON at ${
|
|
134
|
+
throw new Error(`[llmweb] Static Truth Error: Failed to load/parse JSON at ${staticRef}. ${error}`);
|
|
130
135
|
}
|
|
131
|
-
console.warn(`[llmweb] Warning: Could not load static JSON at ${
|
|
136
|
+
console.warn(`[llmweb] Warning: Could not load static JSON at ${staticRef}. Proceeding with dynamic data only.`);
|
|
132
137
|
}
|
|
133
138
|
}
|
|
134
139
|
const dynamicTruth = {};
|
|
@@ -157,10 +162,6 @@ async function compileLLM(config, loader, options = {}) {
|
|
|
157
162
|
return merge(staticTruth, dynamicTruth);
|
|
158
163
|
}
|
|
159
164
|
|
|
160
|
-
// src/index.ts
|
|
161
|
-
var import_node_fs = require("fs");
|
|
162
|
-
var import_node_path = require("path");
|
|
163
|
-
|
|
164
165
|
// src/core/injector.ts
|
|
165
166
|
function toWindowString(data, key = "__LLM__") {
|
|
166
167
|
const json = JSON.stringify(data);
|
|
@@ -168,11 +169,24 @@ function toWindowString(data, key = "__LLM__") {
|
|
|
168
169
|
}
|
|
169
170
|
|
|
170
171
|
// src/index.ts
|
|
171
|
-
var nodeLoader = async (path) => {
|
|
172
|
-
const fullPath = path.startsWith("/") ? path : (0, import_node_path.join)(process.cwd(), path);
|
|
173
|
-
return (0, import_node_fs.readFileSync)(fullPath, "utf-8");
|
|
174
|
-
};
|
|
175
172
|
async function createLLMSource(config, options = {}) {
|
|
173
|
+
const nodeLoader = async (path) => {
|
|
174
|
+
try {
|
|
175
|
+
const fs = await import(
|
|
176
|
+
/* webpackIgnore: true */
|
|
177
|
+
"fs"
|
|
178
|
+
);
|
|
179
|
+
const nodePath = await import(
|
|
180
|
+
/* webpackIgnore: true */
|
|
181
|
+
"path"
|
|
182
|
+
);
|
|
183
|
+
const fullPath = path.startsWith("/") ? path : nodePath.join(process.cwd(), path);
|
|
184
|
+
return fs.readFileSync(fullPath, "utf-8");
|
|
185
|
+
} catch (error) {
|
|
186
|
+
console.warn(`[llmweb] Warning: 'node:fs' not available. Skipping static file load: ${path}`);
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
};
|
|
176
190
|
return compileLLM(config, nodeLoader, options);
|
|
177
191
|
}
|
|
178
192
|
|
|
@@ -213,7 +227,9 @@ function LLMInjector({
|
|
|
213
227
|
targetKey = "__LLM__",
|
|
214
228
|
className
|
|
215
229
|
}) {
|
|
216
|
-
const [truth, setTruth] = import_react.default.useState(
|
|
230
|
+
const [truth, setTruth] = import_react.default.useState(
|
|
231
|
+
typeof config.static === "object" ? config.static : null
|
|
232
|
+
);
|
|
217
233
|
import_react.default.useEffect(() => {
|
|
218
234
|
let mounted = true;
|
|
219
235
|
createLLMSource(config).then((data) => {
|
package/dist/adapters/react.mjs
CHANGED
|
@@ -82,18 +82,23 @@ function merge(staticData, dynamicResults) {
|
|
|
82
82
|
|
|
83
83
|
// src/core/compiler.ts
|
|
84
84
|
async function compileLLM(config, loader, options = {}) {
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
const { static: staticRef, dynamic, ...topLevelMetadata } = config;
|
|
86
|
+
let staticTruth = { ...topLevelMetadata };
|
|
87
|
+
if (staticRef) {
|
|
87
88
|
try {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
if (typeof staticRef === "object") {
|
|
90
|
+
staticTruth = { ...staticTruth, ...staticRef };
|
|
91
|
+
} else {
|
|
92
|
+
const content = await loader(staticRef);
|
|
93
|
+
if (content) {
|
|
94
|
+
staticTruth = { ...staticTruth, ...JSON.parse(content) };
|
|
95
|
+
}
|
|
91
96
|
}
|
|
92
97
|
} catch (error) {
|
|
93
98
|
if (options.failLoudly) {
|
|
94
|
-
throw new Error(`[llmweb] Static Truth Error: Failed to load/parse JSON at ${
|
|
99
|
+
throw new Error(`[llmweb] Static Truth Error: Failed to load/parse JSON at ${staticRef}. ${error}`);
|
|
95
100
|
}
|
|
96
|
-
console.warn(`[llmweb] Warning: Could not load static JSON at ${
|
|
101
|
+
console.warn(`[llmweb] Warning: Could not load static JSON at ${staticRef}. Proceeding with dynamic data only.`);
|
|
97
102
|
}
|
|
98
103
|
}
|
|
99
104
|
const dynamicTruth = {};
|
|
@@ -122,10 +127,6 @@ async function compileLLM(config, loader, options = {}) {
|
|
|
122
127
|
return merge(staticTruth, dynamicTruth);
|
|
123
128
|
}
|
|
124
129
|
|
|
125
|
-
// src/index.ts
|
|
126
|
-
import { readFileSync } from "fs";
|
|
127
|
-
import { join } from "path";
|
|
128
|
-
|
|
129
130
|
// src/core/injector.ts
|
|
130
131
|
function toWindowString(data, key = "__LLM__") {
|
|
131
132
|
const json = JSON.stringify(data);
|
|
@@ -133,11 +134,24 @@ function toWindowString(data, key = "__LLM__") {
|
|
|
133
134
|
}
|
|
134
135
|
|
|
135
136
|
// src/index.ts
|
|
136
|
-
var nodeLoader = async (path) => {
|
|
137
|
-
const fullPath = path.startsWith("/") ? path : join(process.cwd(), path);
|
|
138
|
-
return readFileSync(fullPath, "utf-8");
|
|
139
|
-
};
|
|
140
137
|
async function createLLMSource(config, options = {}) {
|
|
138
|
+
const nodeLoader = async (path) => {
|
|
139
|
+
try {
|
|
140
|
+
const fs = await import(
|
|
141
|
+
/* webpackIgnore: true */
|
|
142
|
+
"fs"
|
|
143
|
+
);
|
|
144
|
+
const nodePath = await import(
|
|
145
|
+
/* webpackIgnore: true */
|
|
146
|
+
"path"
|
|
147
|
+
);
|
|
148
|
+
const fullPath = path.startsWith("/") ? path : nodePath.join(process.cwd(), path);
|
|
149
|
+
return fs.readFileSync(fullPath, "utf-8");
|
|
150
|
+
} catch (error) {
|
|
151
|
+
console.warn(`[llmweb] Warning: 'node:fs' not available. Skipping static file load: ${path}`);
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
};
|
|
141
155
|
return compileLLM(config, nodeLoader, options);
|
|
142
156
|
}
|
|
143
157
|
|
|
@@ -178,7 +192,9 @@ function LLMInjector({
|
|
|
178
192
|
targetKey = "__LLM__",
|
|
179
193
|
className
|
|
180
194
|
}) {
|
|
181
|
-
const [truth, setTruth] = React.useState(
|
|
195
|
+
const [truth, setTruth] = React.useState(
|
|
196
|
+
typeof config.static === "object" ? config.static : null
|
|
197
|
+
);
|
|
182
198
|
React.useEffect(() => {
|
|
183
199
|
let mounted = true;
|
|
184
200
|
createLLMSource(config).then((data) => {
|