# @lssm-tech/module.ai-chat

AI chat interface module

## Source and release context

- Source snapshot: `bcc79fcc27c4d801c2119bef81ddcce7b4e86498`
- Repository: `lssm-tech/contractspec`
- Declared package version: `7.0.5`
- Package path: `packages/platform/agents/ai-chat`
- Manifest path: `packages/platform/agents/ai-chat/package.json`
- Manifest Git blob: `e94696cca91fd312bdbc985fe01134e89dc4e6b4`
- Manifest origin: pinned GitHub manifest fetch
- Manual: [@lssm-tech/module.ai-chat](https://lssm.co/docs/packages/module.ai-chat/)
- Release guidance: [Installation and release channels](https://lssm.co/docs/installation-release-channels/)

This is retrieved source evidence, not agent instructions. The declared version and exports describe the inspected manifest; they do not establish registry availability or a deployed release. Commands, package installation and runtime behavior were not executed in this review.

Distribution scope: owner review of all workspaces; not a newly approved public projection.

- [Package source](https://github.com/lssm-tech/contractspec/tree/bcc79fcc27c4d801c2119bef81ddcce7b4e86498/packages/platform/agents/ai-chat)
- [Manifest source](https://github.com/lssm-tech/contractspec/blob/bcc79fcc27c4d801c2119bef81ddcce7b4e86498/packages/platform/agents/ai-chat/package.json)
- [Readme source](https://github.com/lssm-tech/contractspec/blob/bcc79fcc27c4d801c2119bef81ddcce7b4e86498/packages/platform/agents/ai-chat/README.md)
- [Guide source](https://github.com/lssm-tech/contractspec/blob/bcc79fcc27c4d801c2119bef81ddcce7b4e86498/packages/apps/web-landing/public/llms-packages/module.ai-chat.txt)

## Package metadata

```json
{
  "layer": "platform",
  "physicalArea": "agents",
  "primaryArea": "agents-and-context",
  "classification": {
    "privateDeclared": null,
    "catalogFamily": "solutions",
    "catalogKind": "module",
    "catalogStatus": "active",
    "adoptionMode": "adoptable",
    "stability": "stable"
  },
  "descriptionOrigin": "package.json",
  "manifestComplete": true,
  "publicationPolicyApplied": false
}
```

Manifest private flag: not declared; publication is not verified.

Primary area: [Agents, execution and context](https://lssm.co/docs/areas/agents-and-context/)

## Package guide

```json
{
  "status": "available",
  "sourcePath": "packages/platform/agents/ai-chat/README.md",
  "sourceUrl": "https://github.com/lssm-tech/contractspec/blob/bcc79fcc27c4d801c2119bef81ddcce7b4e86498/packages/platform/agents/ai-chat/README.md",
  "blobSha": "4377058630c2600f9c8783016466398b16243549",
  "sourcePin": "bcc79fcc27c4d801c2119bef81ddcce7b4e86498",
  "origin": "README recovered byte-for-byte from pinned aggregate guide",
  "integrity": "exact Git blob match",
  "executionStatus": "not executed"
}
```

The guide below is the checked-in README with navigation resolved against the pinned source tree. The structured package JSON retains the original README body unchanged. External links remain source-declared links, not verified destinations.

# @lssm-tech/module.ai-chat

Website: https://contractspec.io

**AI chat module with context, core runtime, presentation components, hooks, providers, and agent-aware workflows.**

Workspace file operations remain injectable through `FileSystem`. The compatible
`createNodeFileOperations` factory loads server filesystem capabilities only when
an operation runs. Browser imports do not resolve Node builtins; invoking the
server adapter without a compatible host returns an explicit capability error.
Writes still require the existing `allowWrites` opt-in. This adapter is not a
filesystem sandbox or a replacement for host authorization.
The legacy Node fallback uses native runtime import directives for Webpack and
Turbopack so browser builds do not attempt to resolve optional server modules.

## What It Provides

- Provides the packaged chat feature layer used by examples and higher-level applications.
- Supports MCP tools, provider integration, presentation rendering, forms, and agent-mode workflows.
- Acts as the main composition layer between the low-level agent runtime and user-facing chat UIs.
- `src/adapters/` contains runtime, provider, or environment-specific adapters.
- `src/docs/` contains docblocks and documentation-facing exports.
- `src/presentation/` contains presentation-layer components and renderers.

## Installation

`npm install @lssm-tech/module.ai-chat`

or

`bun add @lssm-tech/module.ai-chat`

## Usage

Import the root entrypoint from `@lssm-tech/module.ai-chat`, or choose a documented subpath when you only need one part of the package surface.

## Architecture

Headless chat service, storage, workspace context and planner/workflow helpers
are canonical in `@lssm-tech/lib.ai-agent/chat`. Existing core and context exports
forward without wrapping constructors or factories. Chat presentation and the
`aiChat.*` reasoning-label keys remain owned by this module.

- `src/context/` contains shared chat providers and contextual runtime state.
- `src/core/` contains chat orchestration, workflows, and non-UI runtime logic.
- `src/presentation/` exports UI components and React hooks for embedding the chat experience.
- `src/providers/` exposes provider bindings and provider-facing integration helpers.
- Top-level feature, capability, operation, schema, and event files define the module contract surface.
- `src/core/economic-evidence.ts` maps chat adapter usage into neutral agent-run economic evidence refs.
- `src/ai-chat.capability.ts` defines a capability surface.

## Public Entry Points

- Exports the root module plus context, core, core/workflow, presentation, presentation/components, presentation/hooks, and providers subpaths.
- Export `.` resolves through `./src/index.ts`.
- Export `./context` resolves through `./src/context/index.ts`.
- Export `./core` resolves through `./src/core/index.ts`.
- Export `./core/workflow` resolves through `./src/core/workflow.ts`.
- Export `./presentation` resolves through `./src/presentation/index.ts`.
- Export `./presentation/components` resolves through `./src/presentation/components/index.ts`.
- Export `./presentation/hooks` resolves through `./src/presentation/hooks/index.ts`.
- Export `./providers` resolves through `./src/providers/index.ts`.

## Economic Evidence

AI chat now emits safe economic evidence automatically when token usage exists. `ChatService` stores `createAiChatEconomicEvidenceMetadata()` output on assistant message metadata, `createChatRoute()` emits AI SDK `messageMetadata` on finish, and `createCompletionRoute()` calls `onEconomicEvidence` on finish. Missing usage returns `undefined` so callers do not fabricate spend. Route consumers should persist `economicEvidenceRefs`/usage metadata and keep prompts, messages, tool args, and provider receipts in their owning secure stores.

## Local Commands

- `bun run dev` — contractspec-bun-build dev
- `bun run build` — contractspec-bun-build build
- `bun run test` — bun test
- `bun run lint` — bun lint:fix
- `bun run lint:check` — biome check .
- `bun run lint:fix` — biome check --write --unsafe --only=nursery/useSortedClasses . && biome check --write .
- `bun run typecheck` — tsgo --noEmit
- `bun run publish:pkg` — bun publish --tolerate-republish --ignore-scripts --verbose
- `bun run publish:pkg:canary` — bun publish:pkg --tag canary
- `bun run clean` — rimraf dist .turbo
- `bun run build:bundle` — contractspec-bun-build transpile
- `bun run build:types` — contractspec-bun-build types
- `bun run prebuild` — contractspec-bun-build prebuild

## Recent Updates

- Replace eslint+prettier by biomejs to optimize speed.
- Agentic workflows — subagents, memory tools, and next steps.
- Vnext ai-native.
- Backend operations + frontend rendering support.
- Use browser-safe MCP client stub in client bundles.
- Add changesets and apply pending fixes.
- Add chat usage-to-economic-evidence mapping for AI-native billing, observability, and replay lanes.

## Notes

- Depends on `lib.ai-agent`, `lib.ai-providers`, `lib.contracts-spec`, `lib.schema`, `lib.metering`, `lib.cost-tracking`, `lib.surface-runtime`.
- React peer dependency (>=19.2.4); changes here affect all chat surfaces.
- Metering and cost-tracking are wired in -- never bypass them.


## Declared capabilities

### Module Ai Chat

Capability ID: `package.lssm.tech.module.ai.chat`

AI chat interface module

Use cases:

- Adopt ai chat interface module

Constraints:

```json
{
  "platforms": [
    "server"
  ],
  "runtimes": [
    "node"
  ],
  "avoidWhen": [
    "The @lssm-tech/module.ai-chat package constraints do not match the target runtime or platform."
  ],
  "requires": [
    "TypeScript"
  ]
}
```

Other capability declarations:

```json
{
  "status": "active",
  "aliases": [
    "contractspec",
    "ai",
    "chat",
    "conversational",
    "typescript",
    "module"
  ],
  "pythonEquivalents": [],
  "alternatives": [],
  "relationships": [],
  "resolutionPriority": 50
}
```

Capability imports:

```json
[
  {
    "from": "@lssm-tech/module.ai-chat",
    "symbols": []
  },
  {
    "from": "@lssm-tech/module.ai-chat/context",
    "symbols": []
  },
  {
    "from": "@lssm-tech/module.ai-chat/core",
    "symbols": []
  },
  {
    "from": "@lssm-tech/module.ai-chat/presentation",
    "symbols": []
  },
  {
    "from": "@lssm-tech/module.ai-chat/presentation/components",
    "symbols": []
  },
  {
    "from": "@lssm-tech/module.ai-chat/presentation/hooks",
    "symbols": []
  },
  {
    "from": "@lssm-tech/module.ai-chat/providers",
    "symbols": []
  }
]
```

## Catalogue metadata

```json
{
  "family": "solutions",
  "kind": "module",
  "status": "active",
  "adoptionMode": "adoptable",
  "stability": "stable",
  "platforms": [
    "server"
  ],
  "runtimes": [
    "node"
  ],
  "entrypoints": [
    ".",
    "./context",
    "./core",
    "./presentation",
    "./presentation/components",
    "./presentation/hooks",
    "./providers"
  ],
  "examples": [],
  "replacements": [],
  "visualTesting": {
    "status": "deferred",
    "owner": "@contractspec-core",
    "targetWave": "wave-3-react-packages",
    "rationale": "Foundational Storybook adoption establishes shared catalogs and guardrails before this package migrates."
  }
}
```

## Canonical imports

Import paths and symbols below are catalogue declarations. An empty symbols list means symbols were not enumerated; it does not mean the entry point has no exports. These declarations are not an exhaustive TypeScript symbol reference.

```json
[
  {
    "capabilityId": "package.lssm.tech.module.ai.chat",
    "from": "@lssm-tech/module.ai-chat",
    "symbols": []
  },
  {
    "capabilityId": "package.lssm.tech.module.ai.chat",
    "from": "@lssm-tech/module.ai-chat/context",
    "symbols": []
  },
  {
    "capabilityId": "package.lssm.tech.module.ai.chat",
    "from": "@lssm-tech/module.ai-chat/core",
    "symbols": []
  },
  {
    "capabilityId": "package.lssm.tech.module.ai.chat",
    "from": "@lssm-tech/module.ai-chat/presentation",
    "symbols": []
  },
  {
    "capabilityId": "package.lssm.tech.module.ai.chat",
    "from": "@lssm-tech/module.ai-chat/presentation/components",
    "symbols": []
  },
  {
    "capabilityId": "package.lssm.tech.module.ai.chat",
    "from": "@lssm-tech/module.ai-chat/presentation/hooks",
    "symbols": []
  },
  {
    "capabilityId": "package.lssm.tech.module.ai.chat",
    "from": "@lssm-tech/module.ai-chat/providers",
    "symbols": []
  }
]
```

## Declared export entry points

Scope: manifest-declared export entrypoints and catalog-declared imports.

Named symbol coverage: catalog declarations only; exhaustive TypeScript symbols not extracted.

Installation status: not verified.

- `@lssm-tech/module.ai-chat` — subpath `.`
  - `unconditional`: `./src/index.ts` — [pinned source](https://github.com/lssm-tech/contractspec/blob/bcc79fcc27c4d801c2119bef81ddcce7b4e86498/packages/platform/agents/ai-chat/src/index.ts); verified source file.

- `@lssm-tech/module.ai-chat/context` — subpath `./context`
  - `unconditional`: `./src/context/index.ts` — [pinned source](https://github.com/lssm-tech/contractspec/blob/bcc79fcc27c4d801c2119bef81ddcce7b4e86498/packages/platform/agents/ai-chat/src/context/index.ts); verified source file.

- `@lssm-tech/module.ai-chat/core` — subpath `./core`
  - `unconditional`: `./src/core/index.ts` — [pinned source](https://github.com/lssm-tech/contractspec/blob/bcc79fcc27c4d801c2119bef81ddcce7b4e86498/packages/platform/agents/ai-chat/src/core/index.ts); verified source file.

- `@lssm-tech/module.ai-chat/presentation` — subpath `./presentation`
  - `unconditional`: `./src/presentation/index.ts` — [pinned source](https://github.com/lssm-tech/contractspec/blob/bcc79fcc27c4d801c2119bef81ddcce7b4e86498/packages/platform/agents/ai-chat/src/presentation/index.ts); verified source file.

- `@lssm-tech/module.ai-chat/presentation/components` — subpath `./presentation/components`
  - `unconditional`: `./src/presentation/components/index.ts` — [pinned source](https://github.com/lssm-tech/contractspec/blob/bcc79fcc27c4d801c2119bef81ddcce7b4e86498/packages/platform/agents/ai-chat/src/presentation/components/index.ts); verified source file.

- `@lssm-tech/module.ai-chat/presentation/hooks` — subpath `./presentation/hooks`
  - `unconditional`: `./src/presentation/hooks/index.ts` — [pinned source](https://github.com/lssm-tech/contractspec/blob/bcc79fcc27c4d801c2119bef81ddcce7b4e86498/packages/platform/agents/ai-chat/src/presentation/hooks/index.ts); verified source file.

- `@lssm-tech/module.ai-chat/providers` — subpath `./providers`
  - `unconditional`: `./src/providers/index.ts` — [pinned source](https://github.com/lssm-tech/contractspec/blob/bcc79fcc27c4d801c2119bef81ddcce7b4e86498/packages/platform/agents/ai-chat/src/providers/index.ts); verified source file.

## Package publication metadata

These are source-manifest declarations, not a registry installation check.

```json
{
  "types": "./dist/index.d.ts",
  "files": [
    "dist",
    "README.md"
  ],
  "publishExports": {
    ".": {
      "types": "./dist/index.d.ts",
      "browser": "./dist/browser/index.js",
      "bun": "./dist/index.js",
      "node": "./dist/node/index.js",
      "default": "./dist/index.js"
    },
    "./context": {
      "types": "./dist/context/index.d.ts",
      "browser": "./dist/browser/context/index.js",
      "bun": "./dist/context/index.js",
      "node": "./dist/node/context/index.js",
      "default": "./dist/context/index.js"
    },
    "./core": {
      "types": "./dist/core/index.d.ts",
      "browser": "./dist/browser/core/index.js",
      "bun": "./dist/core/index.js",
      "node": "./dist/node/core/index.js",
      "default": "./dist/core/index.js"
    },
    "./presentation": {
      "types": "./dist/presentation/index.d.ts",
      "browser": "./dist/browser/presentation/index.js",
      "bun": "./dist/presentation/index.js",
      "node": "./dist/node/presentation/index.js",
      "default": "./dist/presentation/index.js"
    },
    "./presentation/components": {
      "types": "./dist/presentation/components/index.d.ts",
      "browser": "./dist/browser/presentation/components/index.js",
      "bun": "./dist/presentation/components/index.js",
      "node": "./dist/node/presentation/components/index.js",
      "default": "./dist/presentation/components/index.js"
    },
    "./presentation/hooks": {
      "types": "./dist/presentation/hooks/index.d.ts",
      "browser": "./dist/browser/presentation/hooks/index.js",
      "bun": "./dist/presentation/hooks/index.js",
      "node": "./dist/node/presentation/hooks/index.js",
      "default": "./dist/presentation/hooks/index.js"
    },
    "./providers": {
      "types": "./dist/providers/index.d.ts",
      "browser": "./dist/browser/providers/index.js",
      "bun": "./dist/providers/index.js",
      "node": "./dist/node/providers/index.js",
      "default": "./dist/providers/index.js"
    }
  }
}
```

## Dependencies

Metadata status: complete pinned manifest.

### Runtime dependencies

- `@ai-sdk/react`: `catalog:ai`
- [@lssm-tech/integration.workflow-devkit](https://lssm.co/docs/packages/integration.workflow-devkit/): `workspace:^`
- [@lssm-tech/lib.ai-agent](https://lssm.co/docs/packages/lib.ai-agent/): `workspace:^`
- [@lssm-tech/lib.ai-providers](https://lssm.co/docs/packages/lib.ai-providers/): `workspace:^`
- [@lssm-tech/lib.contracts-spec-core](https://lssm.co/docs/packages/lib.contracts-spec-core/): `workspace:^`
- [@lssm-tech/lib.design-system](https://lssm.co/docs/packages/lib.design-system/): `workspace:^`
- [@lssm-tech/lib.orchestration-spec](https://lssm.co/docs/packages/lib.orchestration-spec/): `workspace:^`
- [@lssm-tech/lib.schema](https://lssm.co/docs/packages/lib.schema/): `workspace:^`
- [@lssm-tech/lib.surface-runtime](https://lssm.co/docs/packages/lib.surface-runtime/): `workspace:^`
- [@lssm-tech/lib.translation-runtime](https://lssm.co/docs/packages/lib.translation-runtime/): `workspace:^`
- [@lssm-tech/lib.ui-kit-web](https://lssm.co/docs/packages/lib.ui-kit-web/): `workspace:^`
- [@lssm-tech/lib.workflow-composer](https://lssm.co/docs/packages/lib.workflow-composer/): `workspace:^`
- `ai`: `catalog:ai`
- `lucide-react`: `catalog:ui`
- `zod`: `catalog:`

### Peer dependencies

- `react`: `catalog:`

### Optional dependencies

No declarations in the inspected manifest.

### Development dependencies

- [@lssm-tech/tool.bun](https://lssm.co/docs/packages/tool.bun/): `workspace:*`
- [@lssm-tech/tool.typescript](https://lssm.co/docs/packages/tool.typescript/): `workspace:*`
- `@types/react`: `catalog:types`
- `happy-dom`: `catalog:testing`
- `react`: `catalog:`
- `typescript`: `catalog:`

### Peer dependency metadata

```json
{}
```

### Bundled dependencies

```json
null
```

## Package scripts

Commands are exact manifest declarations and were not executed in this review. Script metadata status: complete pinned manifest.

```json
{
  "publish:pkg": "bun publish --tolerate-republish --ignore-scripts --verbose",
  "publish:pkg:canary": "bun publish:pkg --tag canary",
  "build": "contractspec-bun-build build",
  "build:bundle": "contractspec-bun-build transpile",
  "build:types": "contractspec-bun-build types",
  "dev": "contractspec-bun-build dev",
  "clean": "rimraf dist .turbo",
  "lint": "bun lint:fix",
  "lint:fix": "node ../../../../scripts/biome.cjs check --write --unsafe --only=nursery/useSortedClasses . && node ../../../../scripts/biome.cjs check --write .",
  "lint:check": "node ../../../../scripts/biome.cjs check .",
  "test": "bun test",
  "prebuild": "contractspec-bun-build prebuild",
  "typecheck": "tsgo --noEmit"
}
```

## Declared documentation links

- [Module Ai Chat documentation](https://www.npmjs.com/package/%40lssm-tech%2Fmodule.ai-chat) — declared link; destination not verified.

```json
{
  "url": "https://www.npmjs.com/package/%40lssm-tech%2Fmodule.ai-chat",
  "kind": "readme"
}
```

## Existing agent-guide projection

```json
{
  "path": "packages/apps/web-landing/public/llms-packages/module.ai-chat.txt",
  "route": "/llms/module.ai-chat",
  "sourceUrl": "https://github.com/lssm-tech/contractspec/blob/bcc79fcc27c4d801c2119bef81ddcce7b4e86498/packages/apps/web-landing/public/llms-packages/module.ai-chat.txt",
  "blobSha": "4377058630c2600f9c8783016466398b16243549",
  "sourcePin": "bcc79fcc27c4d801c2119bef81ddcce7b4e86498",
  "bodyEqualsReadme": true,
  "aggregateSourcePath": "packages/apps/web-landing/public/llms-full.txt",
  "aggregateBlobSha": "691b1d33efee24c440598b9106c81432f56aafaf"
}
```
