@ramme-io/shared 2.0.0 → 2.0.1

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.
@@ -1,19 +1,20 @@
1
-
2
- > @ramme-io/shared@2.0.0 build /Users/danetroup/ramme/ramme-monorepo/packages/shared
3
- > tsup index.ts --format esm,cjs --dts --clean
4
-
5
- CLI Building entry: index.ts
6
- CLI Using tsconfig: tsconfig.json
7
- CLI tsup v8.5.1
8
- CLI Target: es2020
9
- CLI Cleaning output folder
10
- ESM Build start
11
- CJS Build start
12
- ESM dist/index.js 1.96 KB
13
- ESM ⚡️ Build success in 52ms
14
- CJS dist/index.cjs 3.07 KB
15
- CJS ⚡️ Build success in 52ms
16
- DTS Build start
17
- DTS ⚡️ Build success in 816ms
18
- DTS dist/index.d.ts 3.90 KB
19
- DTS dist/index.d.cts 3.90 KB
1
+
2
+ 
3
+ > @ramme-io/shared@2.0.1 build /Users/ramme/ramme-monorepo/framework/shared
4
+ > tsup index.ts --format esm,cjs --dts --clean
5
+
6
+ CLI Building entry: index.ts
7
+ CLI Using tsconfig: tsconfig.json
8
+ CLI tsup v8.5.1
9
+ CLI Target: es2020
10
+ CLI Cleaning output folder
11
+ ESM Build start
12
+ CJS Build start
13
+ CJS dist/index.cjs 12.64 KB
14
+ CJS ⚡️ Build success in 131ms
15
+ ESM dist/index.js 9.68 KB
16
+ ESM ⚡️ Build success in 131ms
17
+ DTS Build start
18
+ DTS ⚡️ Build success in 902ms
19
+ DTS dist/index.d.ts 51.02 KB
20
+ DTS dist/index.d.cts 51.02 KB
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @ramme-io/shared
2
+
3
+ ## 2.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Initial automated release pipeline configuration via Changesets.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ramme Framework
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/dist/index.cjs CHANGED
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ AI_TOOLS: () => AI_TOOLS,
23
24
  ActionSchema: () => ActionSchema,
24
25
  AppSpecificationSchema: () => AppSpecificationSchema,
25
26
  BlockSchema: () => BlockSchema,
@@ -32,7 +33,10 @@ __export(index_exports, {
32
33
  ResourceSchema: () => ResourceSchema,
33
34
  SignalSchema: () => SignalSchema,
34
35
  TriggerSchema: () => TriggerSchema,
35
- WorkflowSchema: () => WorkflowSchema
36
+ WorkflowSchema: () => WorkflowSchema,
37
+ generateToolSystemPrompt: () => generateToolSystemPrompt,
38
+ stockChartParameters: () => stockChartParameters,
39
+ telemetryGraphParameters: () => telemetryGraphParameters
36
40
  });
37
41
  module.exports = __toCommonJS(index_exports);
38
42
 
@@ -205,8 +209,103 @@ var BodewellCommandSchema = import_zod2.z.object({
205
209
  type: import_zod2.z.enum(["dry", "wet"]),
206
210
  value: import_zod2.z.number()
207
211
  });
212
+
213
+ // src/ai/tools.ts
214
+ var import_zod3 = require("zod");
215
+ var telemetryGraphParameters = import_zod3.z.object({
216
+ deviceId: import_zod3.z.string().min(1, "Device ID is required"),
217
+ timeRange: import_zod3.z.enum(["1h", "24h", "7d"], {
218
+ errorMap: () => ({ message: "Time range must be 1h, 24h, or 7d" })
219
+ }),
220
+ metrics: import_zod3.z.array(
221
+ import_zod3.z.enum(["temperature", "humidity", "vwc", "ec", "ph", "pressure", "co2"])
222
+ ).min(1, "At least one metric is required").max(4, "Maximum 4 metrics per graph")
223
+ });
224
+ var stockChartParameters = import_zod3.z.object({
225
+ ticker: import_zod3.z.string().min(1).describe("The stock ticker symbol explicitly requested by the user. YOU MUST EXTRACT AND PROVIDE THIS (e.g., 'AAPL', 'MSFT')."),
226
+ timeRange: import_zod3.z.enum(["1D", "1W", "1M", "1Y"], {
227
+ errorMap: () => ({ message: "Time range must be 1D, 1W, 1M, or 1Y" })
228
+ }).describe("The time range for the chart. Choose based on user request or default to '1M'."),
229
+ metrics: import_zod3.z.array(import_zod3.z.enum(["price", "volume", "moving_average"])).min(1, "At least one metric is required").describe("Array of metrics to display. Always include 'price' and 'volume' unless user specifies otherwise.")
230
+ });
231
+ var AI_TOOLS = {
232
+ get_telemetry_graph: {
233
+ name: "get_telemetry_graph",
234
+ description: "Displays an interactive line chart of historical sensor telemetry data. Use this when the user asks to visualize trends, compare metrics over time, or analyze device performance. Supports temperature, humidity, VWC (volumetric water content), EC (electrical conductivity), pH, pressure, and CO2.",
235
+ parameters: telemetryGraphParameters
236
+ },
237
+ get_stock_chart: {
238
+ name: "get_stock_chart",
239
+ description: "Displays an interactive financial chart with price movements, volume, and technical indicators. Use this when the user asks to visualize stock performance, analyze price trends, or compare financial metrics over time. Supports daily (1D), weekly (1W), monthly (1M), and yearly (1Y) time ranges.",
240
+ parameters: stockChartParameters
241
+ }
242
+ };
243
+ function generateToolSystemPrompt(tools) {
244
+ const toolDescriptions = tools.map((tool) => {
245
+ let paramsDesc = "See tool description for parameter details";
246
+ if (tool.name === "get_telemetry_graph") {
247
+ paramsDesc = `{
248
+ "deviceId": "string (required)",
249
+ "timeRange": "enum: '1h' | '24h' | '7d' (required)",
250
+ "metrics": "array of enum: 'temperature' | 'humidity' | 'vwc' | 'ec' | 'ph' | 'pressure' | 'co2' (1-4 items required)"
251
+ }`;
252
+ }
253
+ if (tool.name === "get_stock_chart") {
254
+ paramsDesc = `{
255
+ "ticker": "string (required, e.g., 'AAPL', 'TSLA')",
256
+ "timeRange": "enum: '1D' | '1W' | '1M' | '1Y' (required)",
257
+ "metrics": "array of enum: 'price' | 'volume' | 'moving_average' (1+ items required)"
258
+ }`;
259
+ }
260
+ return `<tool name="${tool.name}">
261
+ <description>${tool.description}</description>
262
+ <parameters>${paramsDesc}</parameters>
263
+ </tool>`;
264
+ }).join("\n\n");
265
+ return `
266
+ You have access to the following tools to enhance your responses with interactive UI components:
267
+
268
+ ${toolDescriptions}
269
+
270
+ When you need to use a tool, output it in this EXACT XML format:
271
+ <tool_call>
272
+ {
273
+ "name": "tool_name",
274
+ "arguments": {
275
+ "param1": "value1",
276
+ "param2": "value2"
277
+ }
278
+ }
279
+ </tool_call>
280
+
281
+ CRITICAL RULES:
282
+ 1. Tool calls MUST be valid JSON wrapped in <tool_call></tool_call> XML tags.
283
+ 2. Do NOT add any text before or after the tool_call tags on the same line.
284
+ 3. You can include explanatory text before or after the tool call in separate paragraphs.
285
+ 4. Only use tools when they directly serve the user's request.
286
+ 5. Validate that all required parameters are present before calling a tool.
287
+
288
+ Example usage:
289
+ User: "Show me temperature trends for device ABC over the last 24 hours"
290
+ You: "I'll visualize the temperature data for device ABC over the past day.
291
+
292
+ <tool_call>
293
+ {
294
+ "name": "get_telemetry_graph",
295
+ "arguments": {
296
+ "deviceId": "ABC",
297
+ "timeRange": "24h",
298
+ "metrics": ["temperature"]
299
+ }
300
+ }
301
+ </tool_call>
302
+
303
+ The graph above shows the temperature fluctuations. Notice the spike around noon, which may indicate..."
304
+ `.trim();
305
+ }
208
306
  // Annotate the CommonJS export names for ESM import in node:
209
307
  0 && (module.exports = {
308
+ AI_TOOLS,
210
309
  ActionSchema,
211
310
  AppSpecificationSchema,
212
311
  BlockSchema,
@@ -219,5 +318,8 @@ var BodewellCommandSchema = import_zod2.z.object({
219
318
  ResourceSchema,
220
319
  SignalSchema,
221
320
  TriggerSchema,
222
- WorkflowSchema
321
+ WorkflowSchema,
322
+ generateToolSystemPrompt,
323
+ stockChartParameters,
324
+ telemetryGraphParameters
223
325
  });
package/dist/index.d.cts CHANGED
@@ -1337,4 +1337,81 @@ declare namespace schema {
1337
1337
  export { type schema_BodewellCommand as BodewellCommand, schema_BodewellCommandSchema as BodewellCommandSchema, schema_BodewellDeviceID as BodewellDeviceID, type schema_BodewellTelemetry as BodewellTelemetry, schema_BodewellTelemetrySchema as BodewellTelemetrySchema };
1338
1338
  }
1339
1339
 
1340
- export { type ActionDefinition, ActionSchema, type AppSpecification, AppSpecificationSchema, type Block, BlockSchema, schema as Bodewell, type EntityDefinition, EntitySchema, type FieldDefinition, FieldSchema, type FloraTelemetry, FloraTelemetrySchema, type PageDefinition, PageSchema, type PageSection, PageSectionSchema, type ResourceDefinition, ResourceSchema, type SignalDefinition, SignalSchema, TriggerSchema, type WorkflowDefinition, WorkflowSchema };
1340
+ /**
1341
+ * @file tools.ts
1342
+ * @package @ramme-io/shared
1343
+ * @description AI Tool Definitions & Schemas
1344
+ *
1345
+ * ARCHITECTURAL ROLE:
1346
+ * Defines the contract between the LLM and our UI components for Generative UI.
1347
+ * All tool schemas use Zod for runtime validation. This ensures type-safe tool
1348
+ * calling across any LLM provider (Anthropic, OpenAI, Ollama, etc.).
1349
+ */
1350
+
1351
+ /**
1352
+ * Telemetry Graph Tool
1353
+ * Allows the LLM to render an interactive time-series chart of sensor data.
1354
+ */
1355
+ declare const telemetryGraphParameters: z.ZodObject<{
1356
+ deviceId: z.ZodString;
1357
+ timeRange: z.ZodEnum<["1h", "24h", "7d"]>;
1358
+ metrics: z.ZodArray<z.ZodEnum<["temperature", "humidity", "vwc", "ec", "ph", "pressure", "co2"]>, "many">;
1359
+ }, "strip", z.ZodTypeAny, {
1360
+ deviceId: string;
1361
+ timeRange: "1h" | "24h" | "7d";
1362
+ metrics: ("temperature" | "humidity" | "pressure" | "vwc" | "ec" | "ph" | "co2")[];
1363
+ }, {
1364
+ deviceId: string;
1365
+ timeRange: "1h" | "24h" | "7d";
1366
+ metrics: ("temperature" | "humidity" | "pressure" | "vwc" | "ec" | "ph" | "co2")[];
1367
+ }>;
1368
+ type TelemetryGraphParams = z.infer<typeof telemetryGraphParameters>;
1369
+ /**
1370
+ * Stock Chart Tool
1371
+ * Allows the LLM to render an interactive financial chart with price, volume, and technical indicators.
1372
+ */
1373
+ declare const stockChartParameters: z.ZodObject<{
1374
+ ticker: z.ZodString;
1375
+ timeRange: z.ZodEnum<["1D", "1W", "1M", "1Y"]>;
1376
+ metrics: z.ZodArray<z.ZodEnum<["price", "volume", "moving_average"]>, "many">;
1377
+ }, "strip", z.ZodTypeAny, {
1378
+ timeRange: "1D" | "1W" | "1M" | "1Y";
1379
+ metrics: ("price" | "volume" | "moving_average")[];
1380
+ ticker: string;
1381
+ }, {
1382
+ timeRange: "1D" | "1W" | "1M" | "1Y";
1383
+ metrics: ("price" | "volume" | "moving_average")[];
1384
+ ticker: string;
1385
+ }>;
1386
+ type StockChartParams = z.infer<typeof stockChartParameters>;
1387
+ /**
1388
+ * Generic tool definition structure.
1389
+ * Each tool must have a unique name, description, and Zod parameter schema.
1390
+ */
1391
+ interface ToolDefinition<T extends z.ZodSchema = z.ZodSchema> {
1392
+ name: string;
1393
+ description: string;
1394
+ parameters: T;
1395
+ }
1396
+ /**
1397
+ * Tool call object extracted from LLM streaming response.
1398
+ * This is what gets attached to the ChatMessage when a tool is invoked.
1399
+ */
1400
+ interface ToolCall {
1401
+ name: string;
1402
+ arguments: Record<string, any>;
1403
+ id?: string;
1404
+ }
1405
+ /**
1406
+ * Registry of all available AI tools.
1407
+ * Add new tools here to make them available to the LLM.
1408
+ */
1409
+ declare const AI_TOOLS: Record<string, ToolDefinition>;
1410
+ /**
1411
+ * Generates the system instruction fragment for tool calling.
1412
+ * This is appended to the system prompt when tools are enabled.
1413
+ * The LLM is instructed to output tool calls in a strict XML format.
1414
+ */
1415
+ declare function generateToolSystemPrompt(tools: ToolDefinition[]): string;
1416
+
1417
+ export { AI_TOOLS, type ActionDefinition, ActionSchema, type AppSpecification, AppSpecificationSchema, type Block, BlockSchema, schema as Bodewell, type EntityDefinition, EntitySchema, type FieldDefinition, FieldSchema, type FloraTelemetry, FloraTelemetrySchema, type PageDefinition, PageSchema, type PageSection, PageSectionSchema, type ResourceDefinition, ResourceSchema, type SignalDefinition, SignalSchema, type StockChartParams, type TelemetryGraphParams, type ToolCall, type ToolDefinition, TriggerSchema, type WorkflowDefinition, WorkflowSchema, generateToolSystemPrompt, stockChartParameters, telemetryGraphParameters };
package/dist/index.d.ts CHANGED
@@ -1337,4 +1337,81 @@ declare namespace schema {
1337
1337
  export { type schema_BodewellCommand as BodewellCommand, schema_BodewellCommandSchema as BodewellCommandSchema, schema_BodewellDeviceID as BodewellDeviceID, type schema_BodewellTelemetry as BodewellTelemetry, schema_BodewellTelemetrySchema as BodewellTelemetrySchema };
1338
1338
  }
1339
1339
 
1340
- export { type ActionDefinition, ActionSchema, type AppSpecification, AppSpecificationSchema, type Block, BlockSchema, schema as Bodewell, type EntityDefinition, EntitySchema, type FieldDefinition, FieldSchema, type FloraTelemetry, FloraTelemetrySchema, type PageDefinition, PageSchema, type PageSection, PageSectionSchema, type ResourceDefinition, ResourceSchema, type SignalDefinition, SignalSchema, TriggerSchema, type WorkflowDefinition, WorkflowSchema };
1340
+ /**
1341
+ * @file tools.ts
1342
+ * @package @ramme-io/shared
1343
+ * @description AI Tool Definitions & Schemas
1344
+ *
1345
+ * ARCHITECTURAL ROLE:
1346
+ * Defines the contract between the LLM and our UI components for Generative UI.
1347
+ * All tool schemas use Zod for runtime validation. This ensures type-safe tool
1348
+ * calling across any LLM provider (Anthropic, OpenAI, Ollama, etc.).
1349
+ */
1350
+
1351
+ /**
1352
+ * Telemetry Graph Tool
1353
+ * Allows the LLM to render an interactive time-series chart of sensor data.
1354
+ */
1355
+ declare const telemetryGraphParameters: z.ZodObject<{
1356
+ deviceId: z.ZodString;
1357
+ timeRange: z.ZodEnum<["1h", "24h", "7d"]>;
1358
+ metrics: z.ZodArray<z.ZodEnum<["temperature", "humidity", "vwc", "ec", "ph", "pressure", "co2"]>, "many">;
1359
+ }, "strip", z.ZodTypeAny, {
1360
+ deviceId: string;
1361
+ timeRange: "1h" | "24h" | "7d";
1362
+ metrics: ("temperature" | "humidity" | "pressure" | "vwc" | "ec" | "ph" | "co2")[];
1363
+ }, {
1364
+ deviceId: string;
1365
+ timeRange: "1h" | "24h" | "7d";
1366
+ metrics: ("temperature" | "humidity" | "pressure" | "vwc" | "ec" | "ph" | "co2")[];
1367
+ }>;
1368
+ type TelemetryGraphParams = z.infer<typeof telemetryGraphParameters>;
1369
+ /**
1370
+ * Stock Chart Tool
1371
+ * Allows the LLM to render an interactive financial chart with price, volume, and technical indicators.
1372
+ */
1373
+ declare const stockChartParameters: z.ZodObject<{
1374
+ ticker: z.ZodString;
1375
+ timeRange: z.ZodEnum<["1D", "1W", "1M", "1Y"]>;
1376
+ metrics: z.ZodArray<z.ZodEnum<["price", "volume", "moving_average"]>, "many">;
1377
+ }, "strip", z.ZodTypeAny, {
1378
+ timeRange: "1D" | "1W" | "1M" | "1Y";
1379
+ metrics: ("price" | "volume" | "moving_average")[];
1380
+ ticker: string;
1381
+ }, {
1382
+ timeRange: "1D" | "1W" | "1M" | "1Y";
1383
+ metrics: ("price" | "volume" | "moving_average")[];
1384
+ ticker: string;
1385
+ }>;
1386
+ type StockChartParams = z.infer<typeof stockChartParameters>;
1387
+ /**
1388
+ * Generic tool definition structure.
1389
+ * Each tool must have a unique name, description, and Zod parameter schema.
1390
+ */
1391
+ interface ToolDefinition<T extends z.ZodSchema = z.ZodSchema> {
1392
+ name: string;
1393
+ description: string;
1394
+ parameters: T;
1395
+ }
1396
+ /**
1397
+ * Tool call object extracted from LLM streaming response.
1398
+ * This is what gets attached to the ChatMessage when a tool is invoked.
1399
+ */
1400
+ interface ToolCall {
1401
+ name: string;
1402
+ arguments: Record<string, any>;
1403
+ id?: string;
1404
+ }
1405
+ /**
1406
+ * Registry of all available AI tools.
1407
+ * Add new tools here to make them available to the LLM.
1408
+ */
1409
+ declare const AI_TOOLS: Record<string, ToolDefinition>;
1410
+ /**
1411
+ * Generates the system instruction fragment for tool calling.
1412
+ * This is appended to the system prompt when tools are enabled.
1413
+ * The LLM is instructed to output tool calls in a strict XML format.
1414
+ */
1415
+ declare function generateToolSystemPrompt(tools: ToolDefinition[]): string;
1416
+
1417
+ export { AI_TOOLS, type ActionDefinition, ActionSchema, type AppSpecification, AppSpecificationSchema, type Block, BlockSchema, schema as Bodewell, type EntityDefinition, EntitySchema, type FieldDefinition, FieldSchema, type FloraTelemetry, FloraTelemetrySchema, type PageDefinition, PageSchema, type PageSection, PageSectionSchema, type ResourceDefinition, ResourceSchema, type SignalDefinition, SignalSchema, type StockChartParams, type TelemetryGraphParams, type ToolCall, type ToolDefinition, TriggerSchema, type WorkflowDefinition, WorkflowSchema, generateToolSystemPrompt, stockChartParameters, telemetryGraphParameters };
package/dist/index.js CHANGED
@@ -173,7 +173,102 @@ var BodewellCommandSchema = z2.object({
173
173
  type: z2.enum(["dry", "wet"]),
174
174
  value: z2.number()
175
175
  });
176
+
177
+ // src/ai/tools.ts
178
+ import { z as z3 } from "zod";
179
+ var telemetryGraphParameters = z3.object({
180
+ deviceId: z3.string().min(1, "Device ID is required"),
181
+ timeRange: z3.enum(["1h", "24h", "7d"], {
182
+ errorMap: () => ({ message: "Time range must be 1h, 24h, or 7d" })
183
+ }),
184
+ metrics: z3.array(
185
+ z3.enum(["temperature", "humidity", "vwc", "ec", "ph", "pressure", "co2"])
186
+ ).min(1, "At least one metric is required").max(4, "Maximum 4 metrics per graph")
187
+ });
188
+ var stockChartParameters = z3.object({
189
+ ticker: z3.string().min(1).describe("The stock ticker symbol explicitly requested by the user. YOU MUST EXTRACT AND PROVIDE THIS (e.g., 'AAPL', 'MSFT')."),
190
+ timeRange: z3.enum(["1D", "1W", "1M", "1Y"], {
191
+ errorMap: () => ({ message: "Time range must be 1D, 1W, 1M, or 1Y" })
192
+ }).describe("The time range for the chart. Choose based on user request or default to '1M'."),
193
+ metrics: z3.array(z3.enum(["price", "volume", "moving_average"])).min(1, "At least one metric is required").describe("Array of metrics to display. Always include 'price' and 'volume' unless user specifies otherwise.")
194
+ });
195
+ var AI_TOOLS = {
196
+ get_telemetry_graph: {
197
+ name: "get_telemetry_graph",
198
+ description: "Displays an interactive line chart of historical sensor telemetry data. Use this when the user asks to visualize trends, compare metrics over time, or analyze device performance. Supports temperature, humidity, VWC (volumetric water content), EC (electrical conductivity), pH, pressure, and CO2.",
199
+ parameters: telemetryGraphParameters
200
+ },
201
+ get_stock_chart: {
202
+ name: "get_stock_chart",
203
+ description: "Displays an interactive financial chart with price movements, volume, and technical indicators. Use this when the user asks to visualize stock performance, analyze price trends, or compare financial metrics over time. Supports daily (1D), weekly (1W), monthly (1M), and yearly (1Y) time ranges.",
204
+ parameters: stockChartParameters
205
+ }
206
+ };
207
+ function generateToolSystemPrompt(tools) {
208
+ const toolDescriptions = tools.map((tool) => {
209
+ let paramsDesc = "See tool description for parameter details";
210
+ if (tool.name === "get_telemetry_graph") {
211
+ paramsDesc = `{
212
+ "deviceId": "string (required)",
213
+ "timeRange": "enum: '1h' | '24h' | '7d' (required)",
214
+ "metrics": "array of enum: 'temperature' | 'humidity' | 'vwc' | 'ec' | 'ph' | 'pressure' | 'co2' (1-4 items required)"
215
+ }`;
216
+ }
217
+ if (tool.name === "get_stock_chart") {
218
+ paramsDesc = `{
219
+ "ticker": "string (required, e.g., 'AAPL', 'TSLA')",
220
+ "timeRange": "enum: '1D' | '1W' | '1M' | '1Y' (required)",
221
+ "metrics": "array of enum: 'price' | 'volume' | 'moving_average' (1+ items required)"
222
+ }`;
223
+ }
224
+ return `<tool name="${tool.name}">
225
+ <description>${tool.description}</description>
226
+ <parameters>${paramsDesc}</parameters>
227
+ </tool>`;
228
+ }).join("\n\n");
229
+ return `
230
+ You have access to the following tools to enhance your responses with interactive UI components:
231
+
232
+ ${toolDescriptions}
233
+
234
+ When you need to use a tool, output it in this EXACT XML format:
235
+ <tool_call>
236
+ {
237
+ "name": "tool_name",
238
+ "arguments": {
239
+ "param1": "value1",
240
+ "param2": "value2"
241
+ }
242
+ }
243
+ </tool_call>
244
+
245
+ CRITICAL RULES:
246
+ 1. Tool calls MUST be valid JSON wrapped in <tool_call></tool_call> XML tags.
247
+ 2. Do NOT add any text before or after the tool_call tags on the same line.
248
+ 3. You can include explanatory text before or after the tool call in separate paragraphs.
249
+ 4. Only use tools when they directly serve the user's request.
250
+ 5. Validate that all required parameters are present before calling a tool.
251
+
252
+ Example usage:
253
+ User: "Show me temperature trends for device ABC over the last 24 hours"
254
+ You: "I'll visualize the temperature data for device ABC over the past day.
255
+
256
+ <tool_call>
257
+ {
258
+ "name": "get_telemetry_graph",
259
+ "arguments": {
260
+ "deviceId": "ABC",
261
+ "timeRange": "24h",
262
+ "metrics": ["temperature"]
263
+ }
264
+ }
265
+ </tool_call>
266
+
267
+ The graph above shows the temperature fluctuations. Notice the spike around noon, which may indicate..."
268
+ `.trim();
269
+ }
176
270
  export {
271
+ AI_TOOLS,
177
272
  ActionSchema,
178
273
  AppSpecificationSchema,
179
274
  BlockSchema,
@@ -186,5 +281,8 @@ export {
186
281
  ResourceSchema,
187
282
  SignalSchema,
188
283
  TriggerSchema,
189
- WorkflowSchema
284
+ WorkflowSchema,
285
+ generateToolSystemPrompt,
286
+ stockChartParameters,
287
+ telemetryGraphParameters
190
288
  };
package/index.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  export * from './src/schema';
2
2
 
3
3
  // NEW: Bodewell Tenant Exports
4
- export * as Bodewell from './src/bodewell/schema';
4
+ export * as Bodewell from './src/bodewell/schema';
5
+
6
+ // AI Tools Exports
7
+ export * from './src/ai/tools';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramme-io/shared",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -13,13 +13,16 @@
13
13
  "require": "./dist/index.cjs"
14
14
  }
15
15
  },
16
- "scripts": {
17
- "build": "tsup index.ts --format esm,cjs --dts --clean"
16
+ "publishConfig": {
17
+ "access": "public"
18
18
  },
19
19
  "dependencies": {
20
20
  "zod": "^3.23.8"
21
21
  },
22
22
  "devDependencies": {
23
23
  "tsup": "^8.5.1"
24
+ },
25
+ "scripts": {
26
+ "build": "tsup index.ts --format esm,cjs --dts --clean"
24
27
  }
25
- }
28
+ }
@@ -0,0 +1,178 @@
1
+ /**
2
+ * @file tools.ts
3
+ * @package @ramme-io/shared
4
+ * @description AI Tool Definitions & Schemas
5
+ *
6
+ * ARCHITECTURAL ROLE:
7
+ * Defines the contract between the LLM and our UI components for Generative UI.
8
+ * All tool schemas use Zod for runtime validation. This ensures type-safe tool
9
+ * calling across any LLM provider (Anthropic, OpenAI, Ollama, etc.).
10
+ */
11
+
12
+ import { z } from 'zod';
13
+
14
+ // ─────────────────────────────────────────────────────────────────────
15
+ // Tool Parameter Schemas
16
+ // ─────────────────────────────────────────────────────────────────────
17
+
18
+ /**
19
+ * Telemetry Graph Tool
20
+ * Allows the LLM to render an interactive time-series chart of sensor data.
21
+ */
22
+ export const telemetryGraphParameters = z.object({
23
+ deviceId: z.string().min(1, 'Device ID is required'),
24
+ timeRange: z.enum(['1h', '24h', '7d'], {
25
+ errorMap: () => ({ message: 'Time range must be 1h, 24h, or 7d' }),
26
+ }),
27
+ metrics: z
28
+ .array(
29
+ z.enum(['temperature', 'humidity', 'vwc', 'ec', 'ph', 'pressure', 'co2'])
30
+ )
31
+ .min(1, 'At least one metric is required')
32
+ .max(4, 'Maximum 4 metrics per graph'),
33
+ });
34
+
35
+ export type TelemetryGraphParams = z.infer<typeof telemetryGraphParameters>;
36
+
37
+ /**
38
+ * Stock Chart Tool
39
+ * Allows the LLM to render an interactive financial chart with price, volume, and technical indicators.
40
+ */
41
+ export const stockChartParameters = z.object({
42
+ ticker: z.string().min(1).describe("The stock ticker symbol explicitly requested by the user. YOU MUST EXTRACT AND PROVIDE THIS (e.g., 'AAPL', 'MSFT')."),
43
+ timeRange: z.enum(['1D', '1W', '1M', '1Y'], {
44
+ errorMap: () => ({ message: 'Time range must be 1D, 1W, 1M, or 1Y' }),
45
+ }).describe("The time range for the chart. Choose based on user request or default to '1M'."),
46
+ metrics: z
47
+ .array(z.enum(['price', 'volume', 'moving_average']))
48
+ .min(1, 'At least one metric is required')
49
+ .describe("Array of metrics to display. Always include 'price' and 'volume' unless user specifies otherwise."),
50
+ });
51
+
52
+ export type StockChartParams = z.infer<typeof stockChartParameters>;
53
+
54
+ // ─────────────────────────────────────────────────────────────────────
55
+ // Tool Definition Interface
56
+ // ─────────────────────────────────────────────────────────────────────
57
+
58
+ /**
59
+ * Generic tool definition structure.
60
+ * Each tool must have a unique name, description, and Zod parameter schema.
61
+ */
62
+ export interface ToolDefinition<T extends z.ZodSchema = z.ZodSchema> {
63
+ name: string;
64
+ description: string;
65
+ parameters: T;
66
+ }
67
+
68
+ /**
69
+ * Tool call object extracted from LLM streaming response.
70
+ * This is what gets attached to the ChatMessage when a tool is invoked.
71
+ */
72
+ export interface ToolCall {
73
+ name: string;
74
+ arguments: Record<string, any>;
75
+ id?: string; // Optional unique identifier for the tool call
76
+ }
77
+
78
+ // ─────────────────────────────────────────────────────────────────────
79
+ // Tool Registry
80
+ // ─────────────────────────────────────────────────────────────────────
81
+
82
+ /**
83
+ * Registry of all available AI tools.
84
+ * Add new tools here to make them available to the LLM.
85
+ */
86
+ export const AI_TOOLS: Record<string, ToolDefinition> = {
87
+ get_telemetry_graph: {
88
+ name: 'get_telemetry_graph',
89
+ description:
90
+ 'Displays an interactive line chart of historical sensor telemetry data. Use this when the user asks to visualize trends, compare metrics over time, or analyze device performance. Supports temperature, humidity, VWC (volumetric water content), EC (electrical conductivity), pH, pressure, and CO2.',
91
+ parameters: telemetryGraphParameters,
92
+ },
93
+ get_stock_chart: {
94
+ name: 'get_stock_chart',
95
+ description:
96
+ 'Displays an interactive financial chart with price movements, volume, and technical indicators. Use this when the user asks to visualize stock performance, analyze price trends, or compare financial metrics over time. Supports daily (1D), weekly (1W), monthly (1M), and yearly (1Y) time ranges.',
97
+ parameters: stockChartParameters,
98
+ },
99
+ };
100
+
101
+ /**
102
+ * Generates the system instruction fragment for tool calling.
103
+ * This is appended to the system prompt when tools are enabled.
104
+ * The LLM is instructed to output tool calls in a strict XML format.
105
+ */
106
+ export function generateToolSystemPrompt(tools: ToolDefinition[]): string {
107
+ const toolDescriptions = tools
108
+ .map((tool) => {
109
+ // For the LLM, we describe the parameters in a readable format
110
+ // rather than serializing the full Zod schema
111
+ let paramsDesc = 'See tool description for parameter details';
112
+
113
+ // If we need to provide schema info, we can parse it from the Zod object
114
+ // For now, keeping it simple since the description already explains usage
115
+ if (tool.name === 'get_telemetry_graph') {
116
+ paramsDesc = `{
117
+ "deviceId": "string (required)",
118
+ "timeRange": "enum: '1h' | '24h' | '7d' (required)",
119
+ "metrics": "array of enum: 'temperature' | 'humidity' | 'vwc' | 'ec' | 'ph' | 'pressure' | 'co2' (1-4 items required)"
120
+ }`;
121
+ }
122
+
123
+ if (tool.name === 'get_stock_chart') {
124
+ paramsDesc = `{
125
+ "ticker": "string (required, e.g., 'AAPL', 'TSLA')",
126
+ "timeRange": "enum: '1D' | '1W' | '1M' | '1Y' (required)",
127
+ "metrics": "array of enum: 'price' | 'volume' | 'moving_average' (1+ items required)"
128
+ }`;
129
+ }
130
+
131
+ return `<tool name="${tool.name}">
132
+ <description>${tool.description}</description>
133
+ <parameters>${paramsDesc}</parameters>
134
+ </tool>`;
135
+ })
136
+ .join('\n\n');
137
+
138
+ return `
139
+ You have access to the following tools to enhance your responses with interactive UI components:
140
+
141
+ ${toolDescriptions}
142
+
143
+ When you need to use a tool, output it in this EXACT XML format:
144
+ <tool_call>
145
+ {
146
+ "name": "tool_name",
147
+ "arguments": {
148
+ "param1": "value1",
149
+ "param2": "value2"
150
+ }
151
+ }
152
+ </tool_call>
153
+
154
+ CRITICAL RULES:
155
+ 1. Tool calls MUST be valid JSON wrapped in <tool_call></tool_call> XML tags.
156
+ 2. Do NOT add any text before or after the tool_call tags on the same line.
157
+ 3. You can include explanatory text before or after the tool call in separate paragraphs.
158
+ 4. Only use tools when they directly serve the user's request.
159
+ 5. Validate that all required parameters are present before calling a tool.
160
+
161
+ Example usage:
162
+ User: "Show me temperature trends for device ABC over the last 24 hours"
163
+ You: "I'll visualize the temperature data for device ABC over the past day.
164
+
165
+ <tool_call>
166
+ {
167
+ "name": "get_telemetry_graph",
168
+ "arguments": {
169
+ "deviceId": "ABC",
170
+ "timeRange": "24h",
171
+ "metrics": ["temperature"]
172
+ }
173
+ }
174
+ </tool_call>
175
+
176
+ The graph above shows the temperature fluctuations. Notice the spike around noon, which may indicate..."
177
+ `.trim();
178
+ }