Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ on:

env:
DENO_VERSION: v2.x
BUILD_ORDER: '["schema","lib", "ai", "pyodide-runtime-agent", "python-runtime-agent", "tui"]'
BUILD_ORDER: '["schema","lib-web","lib", "ai", "pyodide-runtime-agent", "python-runtime-agent", "tui"]'

jobs:
generate-build-order:
Expand All @@ -41,6 +41,8 @@ jobs:
- 'packages/schema/**'
lib:
- 'packages/lib/**'
lib-web:
- 'packages/lib-web/**'
ai:
- 'packages/ai/**'
pyodide-runtime-agent:
Expand Down
24 changes: 18 additions & 6 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"./packages/ai",
"./packages/schema",
"./packages/lib",
"./packages/lib-web",
"./packages/pyodide-runtime-agent",
"./packages/python-runtime-agent",
"./packages/tui"
Expand All @@ -11,22 +12,33 @@
"@runt/ai": "./packages/ai/mod.ts",
"@runt/schema": "./packages/schema/mod.ts",
"@runt/lib": "./packages/lib/mod.ts",
"@runt/lib-web": "./packages/lib-web/mod.ts",
"@runt/pyodide-runtime-agent": "./packages/pyodide-runtime-agent/src/mod.ts",
"@runt/python-runtime-agent": "./packages/python-runtime-agent/mod.ts",
"@runt/tui": "./packages/tui/src/cli.tsx"
"@runt/tui": "./packages/tui/src/cli.tsx",
"@livestore/livestore": "npm:@livestore/livestore@^0.3.1",
"@livestore/adapter-node": "npm:@livestore/adapter-node@^0.3.1",
"@livestore/adapter-web": "npm:@livestore/adapter-web@^0.3.1",
"@livestore/sync-cf": "npm:@livestore/sync-cf@^0.3.1",
"@livestore/common": "npm:@livestore/common@^0.3.1",
"@livestore/react": "npm:@livestore/react@^0.3.1"
},
"lint": {
"rules": {
"exclude": ["no-slow-types"]
"exclude": [
"no-slow-types"
]
},
"exclude": ["packages/tui/"]
"exclude": [
"packages/tui/"
]
},
"lock": false,
"tasks": {
"dev": "deno run --allow-net --allow-env packages/lib/examples/echo-agent.ts",
"test": "DENO_TESTING=true RUNT_LOG_LEVEL=ERROR RUNT_DISABLE_CONSOLE_LOGS=true deno test --allow-env --allow-net --allow-read --allow-write --allow-sys --allow-run --reporter=dot",
"test:watch": "DENO_TESTING=true deno test --allow-env --allow-net --allow-read --watch",
"test:coverage": "DENO_TESTING=true deno test --allow-env --allow-net --allow-read --allow-write --allow-sys --allow-run --coverage=cov/ --reporter=dot && deno coverage --lcov cov/ > cov.lcov",
"test": "DENO_TESTING=true RUNT_LOG_LEVEL=ERROR RUNT_DISABLE_CONSOLE_LOGS=true deno test --allow-env --allow-net --allow-read --allow-write --allow-sys --allow-run --unstable-broadcast-channel --reporter=dot",
"test:watch": "DENO_TESTING=true deno test --allow-env --allow-net --allow-read --unstable-broadcast-channel --watch",
"test:coverage": "DENO_TESTING=true deno test --allow-env --allow-net --allow-read --allow-write --allow-sys --allow-run --unstable-broadcast-channel --coverage=cov/ --reporter=dot && deno coverage --lcov cov/ > cov.lcov",
"test:unit": "DENO_TESTING=true RUNT_LOG_LEVEL=ERROR RUNT_DISABLE_CONSOLE_LOGS=true deno test --allow-env --allow-net --allow-read --allow-write --allow-sys --allow-run packages/lib/src/ --reporter=dot",
"test:integration": "DENO_TESTING=true RUNT_LOG_LEVEL=ERROR RUNT_DISABLE_CONSOLE_LOGS=true deno test --allow-env --allow-net --allow-read --allow-write --allow-sys --allow-run packages/lib/test/ --reporter=dot",
"test:examples": "DENO_TESTING=true RUNT_LOG_LEVEL=ERROR RUNT_DISABLE_CONSOLE_LOGS=true deno test --allow-env --allow-net --allow-read --allow-write --allow-sys --allow-run packages/lib/examples/ --reporter=dot",
Expand Down
4 changes: 2 additions & 2 deletions packages/ai/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
},
"imports": {
"@runt/lib": "jsr:@runt/lib@^0.11.1",
"@runt/lib-web": "jsr:@runt/lib-web@^0.11.1",
"@runt/schema": "jsr:@runt/schema@^0.11.1",
"npm:pyodide": "npm:pyodide@^0.27.7",
"@std/async": "jsr:@std/async@^1.0.0",
"@std/path": "jsr:@std/path@^1.0.0",
"npm:@livestore/livestore": "npm:@livestore/livestore@^0.3.1",
"@openai/openai": "jsr:@openai/openai@^4.98.0",
"npm:ollama": "npm:ollama@^0.5.16",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style wise, the reason I keep the npm: prefix is to make our code copy-pastable into a Deno notebook. Looking at this now though, I'd need to do the same with jsr: deps.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, but local usage of this (prior to publishing to jsr) would need to have the right references. Guck.

"ollama": "npm:ollama@^0.5.16",
"strip-ansi": "npm:strip-ansi@^7.1.0",
"@modelcontextprotocol/sdk": "npm:@modelcontextprotocol/sdk@^1.0.5"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/ai/mcp-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
CallToolResultSchema,
ListToolsResultSchema,
} from "@modelcontextprotocol/sdk/types.js";
import { createLogger } from "@runt/lib";
import { createLogger } from "@runt/lib-web";
import { join } from "@std/path";

const logger = createLogger("mcp-client");
Expand Down
14 changes: 5 additions & 9 deletions packages/ai/mod.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import stripAnsi from "strip-ansi";
import type OpenAI from "@openai/openai";

import type {
AiModel,
ExecutionContext,
Logger,
ModelCapability,
} from "@runt/lib";
import type { AiModel, ExecutionContext, ModelCapability } from "@runt/lib-web";
import type { Logger } from "@runt/lib-web";

import { handleToolCallWithResult } from "./tool-registry.ts";
import type {
Expand All @@ -20,10 +16,10 @@ import {
materializers,
tables,
} from "@runt/schema";
import type { Store } from "npm:@livestore/livestore";
import { makeSchema, State } from "npm:@livestore/livestore";
import type { Store } from "@livestore/livestore";
import { makeSchema, State } from "@livestore/livestore";
import { AI_TOOL_CALL_MIME_TYPE, AI_TOOL_RESULT_MIME_TYPE } from "@runt/schema";
import { createLogger } from "@runt/lib";
import { createLogger } from "@runt/lib-web";

// Create schema locally
const state = State.SQLite.makeState({ tables, materializers });
Expand Down
4 changes: 2 additions & 2 deletions packages/ai/notebook-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* for AI execution, preserving conversation flow and tool call information.
*/

import type { Store } from "npm:@livestore/livestore";
import { makeSchema, State } from "npm:@livestore/livestore";
import type { Store } from "@livestore/livestore";
import { makeSchema, State } from "@livestore/livestore";
import {
type CellData,
type CellReference,
Expand Down
8 changes: 4 additions & 4 deletions packages/ai/ollama-client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Ollama } from "npm:ollama";
import type { Message, Tool } from "npm:ollama";
import type { AiModel, ModelCapability } from "@runt/lib";
import { createLogger, type ExecutionContext } from "@runt/lib";
import { Ollama } from "ollama";
import type { Message, Tool } from "ollama";
import type { AiModel, ExecutionContext, ModelCapability } from "@runt/lib-web";
import { createLogger } from "@runt/lib-web";

import { AI_TOOL_CALL_MIME_TYPE, AI_TOOL_RESULT_MIME_TYPE } from "@runt/schema";

Expand Down
8 changes: 2 additions & 6 deletions packages/ai/openai-client.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import OpenAI from "@openai/openai";
import {
type AiModel,
createLogger,
type ExecutionContext,
type ModelCapability,
} from "@runt/lib";
import type { AiModel, ExecutionContext, ModelCapability } from "@runt/lib-web";
import { createLogger } from "@runt/lib-web";
import { AI_TOOL_CALL_MIME_TYPE, AI_TOOL_RESULT_MIME_TYPE } from "@runt/schema";

import { getAllTools } from "./tool-registry.ts";
Expand Down
2 changes: 1 addition & 1 deletion packages/ai/test/ollama-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
assertRejects,
} from "https://deno.land/std@0.208.0/assert/mod.ts";
import { RuntOllamaClient } from "../ollama-client.ts";
import type { ExecutionContext } from "@runt/lib";
import type { ExecutionContext } from "@runt/lib-web";

// Test utilities
interface TestOutput {
Expand Down
2 changes: 1 addition & 1 deletion packages/ai/test/streaming-markdown.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assertEquals } from "https://deno.land/std@0.208.0/assert/mod.ts";
import { RuntOpenAIClient } from "../openai-client.ts";
import type { ExecutionContext } from "@runt/lib";
import type { ExecutionContext } from "@runt/lib-web";

// Test utilities
interface TestOutput {
Expand Down
8 changes: 4 additions & 4 deletions packages/ai/tool-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import {
materializers,
tables,
} from "@runt/schema";
import type { Logger } from "@runt/lib";
import type { Store } from "npm:@livestore/livestore";
import { makeSchema, State } from "npm:@livestore/livestore";
import { createLogger } from "@runt/lib";
import type { Logger } from "@runt/lib-web";
import type { Store } from "@livestore/livestore";
import { makeSchema, State } from "@livestore/livestore";
import { createLogger } from "@runt/lib-web";
import { getMCPClient } from "./mcp-client.ts";

// Create schema locally
Expand Down
183 changes: 183 additions & 0 deletions packages/lib-web/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
# @runt/lib-web

Web-compatible logging library for Runt applications.

This package provides a lightweight, web-compatible version of the Runt logging
system, containing only the essential logging functionality without the full
runtime agent capabilities.

## Features

- Structured logging with OpenTelemetry support
- Configurable log levels (DEBUG, INFO, WARN, ERROR)
- Child loggers with additional context
- Operation tracing and timing utilities
- Environment-based configuration
- Console output suppression utilities

## Usage

### Basic Usage

```typescript
import { createLogger, logger } from "@runt/lib-web";

// Use the default logger
logger.info("Application started");

// Create a custom logger
const appLogger = createLogger("my-app");
appLogger.debug("Debug message");
appLogger.warn("Warning message");
appLogger.error("Error occurred", new Error("Something went wrong"));
```

### Configuration

```typescript
import { Logger, LogLevel } from "@runt/lib-web";

const logger = new Logger({
level: LogLevel.DEBUG,
service: "my-service",
console: true,
context: { version: "1.0.0" },
});
```

### Child Loggers

```typescript
const parentLogger = createLogger("parent");
const childLogger = parentLogger.child({
userId: "123",
sessionId: "abc",
});

childLogger.info("User action performed"); // Includes parent and child context
```

### Operation Tracing

```typescript
const result = await logger.trace("database-query", async () => {
// Your async operation here
return await database.query("SELECT * FROM users");
});
```

### Operation Timing

```typescript
const result = await logger.time("api-call", async () => {
// Your async operation here
return await fetch("/api/data");
});
```

### Environment Configuration

Set environment variables to configure logging:

- `RUNT_LOG_LEVEL`: Set log level (DEBUG, INFO, WARN, ERROR)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this means that we'd need to set VITE_RUNT_LOG_LEVEL. Instead we probably should be passing the log level into the log factory.

- `RUNT_DISABLE_CONSOLE_LOGS`: Disable console output

### Signal Handling (Runtime Agent)

For runtime agents, you can inject custom signal handling functions:

```typescript
import { RuntimeAgent, RuntimeConfig } from "@runt/lib-web";

const signalHandlers = {
setup: (shutdown: () => void) => {
// Set up your signal handlers here
// For example, in a web environment:
window.addEventListener("beforeunload", shutdown);

// Or in a Node.js environment:
process.on("SIGINT", shutdown);
process.on("SIGTERM", shutdown);
},
cleanup: () => {
// Clean up your signal handlers here
// For example:
window.removeEventListener("beforeunload", shutdown);
},
};

const options = {
runtimeId: "my-runtime",
runtimeType: "python",
capabilities: {
canExecuteCode: true,
canExecuteSql: false,
canExecuteAi: false,
},
syncUrl: "wss://example.com",
authToken: "your-token",
notebookId: "your-notebook",
signalHandlers, // Inject the signal handlers
environmentOptions: {},
};

const config = new RuntimeConfig(options);
const agent = new RuntimeAgent(config, options.capabilities);
```

## API Reference

### Classes

#### Logger

The main logging class.

**Constructor:**

```typescript
new Logger(config?: Partial<LoggerConfig>)
```

**Methods:**

- `debug(message: string, data?: Record<string, unknown>): void`
- `info(message: string, data?: Record<string, unknown>): void`
- `warn(message: string, data?: Record<string, unknown>): void`
- `error(message: string, error?: Error | unknown, data?: Record<string, unknown>): void`
- `child(context: Record<string, unknown>): Logger`
- `trace<T>(name: string, operation: () => Promise<T>, attributes?: Record<string, unknown>): Promise<T>`
- `time<T>(name: string, operation: () => Promise<T>, data?: Record<string, unknown>): Promise<T>`

### Functions

- `createLogger(service: string, options?: Partial<LoggerConfig>): Logger`
- `withQuietLogging<T>(operation: () => T): T`

### Types

- `LogLevel`: Enum with DEBUG, INFO, WARN, ERROR
- `LoggerConfig`: Interface for logger configuration

### Constants

- `logger`: Default logger instance

## Development

```bash
# Run tests
deno task test

# Run tests in watch mode
deno task test:watch

# Check types
deno task check

# Format code
deno task fmt

# Lint code
deno task lint
```
Loading
Loading