# @agentteam/shared

AgentTeam shared types and pure utilities consumed by the Web frontend (`web/`) and the WeChat Mini Program (`miniapp/`).

## What lives here

This package is **environment-agnostic**: no `window`, `document`, `fetch`, or `wx` dependencies are allowed. Anything that touches a runtime belongs in the consumer.

- `src/types.ts` — wire types matching the AgentTeam backend API (Message, Channel, AuthorProfile, WorkspaceIMEvent, …)
- `src/api-paths.ts` — workspace API path builders shared by clients
- `src/conversations.ts` — pure conversation sorting, kind-filter, patch, upsert/remove, unread, and payload guards
- `src/realtime.ts` — pure realtime payload selectors for shared message/thread patch handling
- `src/reply-thread-participants.ts` — canonical pure reply-thread participant normalization, merge, and prune helpers
- `src/workspace-link.ts` — pure Web-to-MiniApp workspace QR payload builder/parser and token masking helper
- `src/index.ts` — re-exports everything

## Consume

Web and Mini Program both import via the package name:

```typescript
import type { Channel, Message, WorkspaceIMEvent } from "@agentteam/shared"
```

Resolution:

- **Web** (`web/`): via TypeScript/Vite path aliases to `../shared/src`.
- **Mini Program** (`miniapp/`): package imports remain type-only and are erased.
  With `packNpmManually=false`, runtime value helpers do not depend on
  `miniprogram_npm`; canonical runtime helpers are deterministically
  materialized as checked-in artifacts under `miniapp/utils/` and
  `miniapp/runtime/`.

## Develop

```bash
cd shared

# install dev tooling (typescript)
bun install   # or npm install

# type check
bun run typecheck

# run smoke tests
bun test
```

After changing a shared module consumed by MiniApp at runtime, regenerate and
verify the MiniApp runtime artifacts:

```bash
cd ../miniapp
bun run generate:shared-realtime
bun run check:shared-realtime
```

## Why a shared package

Both the Web (React + TypeScript) and the WeChat Mini Program (native TypeScript via `useCompilerPlugins: ['typescript']`) speak the same backend wire format. Centralizing the types here avoids drift and copy-paste.
