feat(server-protocol): introduce shared protocol types for AIRI server clients and frontends
- Added package.json for @proj-airi/server-protocol with necessary configurations. - Implemented chat event types including WireMessage, SendMessagesRequest, and PullMessagesRequest. - Defined WebSocket event types and structures for better integration with AIRI components. - Updated server-runtime and server-sdk to utilize the new server-protocol package. - Refactored imports across various packages to replace server-shared types with server-protocol types. - Enhanced type definitions and added TypeScript configurations for better development experience.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# @proj-airi/server-shared
|
||||
|
||||
The shared type definitions for all server-side packages of Project AIRI.
|
||||
Server-side shared utilities for AIRI runtimes.
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -12,50 +12,9 @@ npm i @proj-airi/server-shared -D
|
||||
```
|
||||
|
||||
```typescript
|
||||
import type { WebSocketEvents } from '@proj-airi/server-shared'
|
||||
import { parseServerErrorMessage } from '@proj-airi/server-shared'
|
||||
```
|
||||
|
||||
## How to use the events in distributed use cases?
|
||||
|
||||
### Scenarios
|
||||
|
||||
#### Minecraft agent
|
||||
|
||||
##### 1. Urgent combat (witch attack)
|
||||
|
||||
- Minecraft sends `spark:notify` (kind=alarm, urgency=immediate, payload hp/location/gear, destinations=["character"]).
|
||||
- Character `spark:emit` working ("Seen it").
|
||||
- Character issues `spark:command` with interrupt=force and options (retreat vs push).
|
||||
- Minecraft `spark:emit` working ("Pillared up; healing") then done/blocked as it executes.
|
||||
- Optional `context:update` for summary/memory.
|
||||
|
||||
##### 2. Prep plan (Ender Dragon)
|
||||
|
||||
- Discord/user intent triggers character `spark:command` to Minecraft (intent=plan, interrupt=soft, steps gather beds/pots/gear, fallback).
|
||||
- Optional `context:update` with tips (lane='game').
|
||||
- Minecraft streams `spark:emit` progress.
|
||||
- If ambushed, Minecraft raises new `spark:notify` (alarm/immediate) to preempt.
|
||||
- Character revises with another `spark:command`.
|
||||
- Completion via `spark:emit` done + summary note.
|
||||
|
||||
##### 3. Routine nudge
|
||||
|
||||
- Minecraft signals low food via `spark:notify` (kind=reminder, urgency=soon, destinations=["character"]).
|
||||
- Character defers to next tick and sends `spark:command` (interrupt=soft, intent=plan: "gather food nearby").
|
||||
- Minecraft `spark:emit` queued/working then done.
|
||||
|
||||
##### 4. Multi-step command while researching (plan + live control)
|
||||
|
||||
> [!NOTE]
|
||||
> Using `intent=plan` keeps the loop alive even with un-finalized ideas—similar to TODO scaffolding in coding agents—while richer guidance is still being researched.
|
||||
|
||||
- Character receives a user goal (e.g., fortify base) and issues an initial `spark:command` to Minecraft (interrupt=soft, intent=plan, steps to gather materials) so the agent keeps working.
|
||||
- Character simultaneously performs memory/search/design tasks outside the game loop (wiki lookup, prior notes).
|
||||
- As insights arrive, character sends `context:update` (lane='game', hints/ideas) to enrich the sub-agent without preemption.
|
||||
- If an urgent event occurs during prep, Minecraft raises `spark:notify` (alarm) → character responds with a short `spark:emit` working and a `spark:command` (interrupt=force) to handle it (e.g., retreat, block up).
|
||||
- Once design is ready, character sends a refined `spark:command` (`intent=proposal` (or `action`), `interrupt=soft`) with structured options/steps/fallbacks.
|
||||
- Minecraft streams `spark:emit` progress; when complete, character summarizes via `spark:emit` or `context:update` for memory.
|
||||
|
||||
## License
|
||||
|
||||
[MIT](../../LICENSE)
|
||||
|
||||
@@ -18,10 +18,6 @@
|
||||
".": {
|
||||
"types": "./dist/index.d.mts",
|
||||
"default": "./dist/index.mjs"
|
||||
},
|
||||
"./types": {
|
||||
"types": "./dist/types/index.d.mts",
|
||||
"default": "./dist/types/index.mjs"
|
||||
}
|
||||
},
|
||||
"main": "./dist/index.mjs",
|
||||
@@ -36,7 +32,5 @@
|
||||
"build": "tsdown",
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"@proj-airi/plugin-protocol": "workspace:*"
|
||||
}
|
||||
"dependencies": {}
|
||||
}
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
export * from './errors'
|
||||
export * from './types'
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
export * from './websocket'
|
||||
export * from '@proj-airi/plugin-protocol/types'
|
||||
@@ -1,52 +0,0 @@
|
||||
import type { ModuleIdentity, ProtocolEvents, RouteConfig, WebSocketEventSource } from '@proj-airi/plugin-protocol/types'
|
||||
|
||||
export * from '@proj-airi/plugin-protocol/types'
|
||||
|
||||
export interface WebSocketEventBaseMetadata {
|
||||
source?: ModuleIdentity
|
||||
event?: {
|
||||
id?: string
|
||||
parentId?: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface WebSocketBaseEvent<T, D, S extends string = string> {
|
||||
type: T
|
||||
data: D
|
||||
/**
|
||||
* @deprecated Prefer metadata.source.
|
||||
*/
|
||||
source?: WebSocketEventSource | S
|
||||
metadata: {
|
||||
source: ModuleIdentity
|
||||
event: {
|
||||
id: string
|
||||
parentId?: string
|
||||
}
|
||||
}
|
||||
route?: RouteConfig
|
||||
}
|
||||
|
||||
export interface WebSocketEvents<C = undefined> extends ProtocolEvents<C> {}
|
||||
|
||||
export type WebSocketEventDataInputs
|
||||
= | WebSocketEvents['input:text']
|
||||
| WebSocketEvents['input:text:voice']
|
||||
| WebSocketEvents['input:voice']
|
||||
|
||||
export type WebSocketEvent<C = undefined> = {
|
||||
[K in keyof WebSocketEvents<C>]: WebSocketBaseEvent<K, WebSocketEvents<C>[K]>;
|
||||
}[keyof WebSocketEvents<C>]
|
||||
|
||||
export type WebSocketEventOptionalSource<C = undefined> = {
|
||||
[K in keyof WebSocketEvents<C>]: Omit<WebSocketBaseEvent<K, WebSocketEvents<C>[K]>, 'metadata'> & { metadata?: WebSocketEventBaseMetadata };
|
||||
}[keyof WebSocketEvents<C>]
|
||||
|
||||
export type WebSocketEventOf<E, C = undefined> = E extends keyof WebSocketEvents<C>
|
||||
? Omit<WebSocketBaseEvent<E, WebSocketEvents<C>[E]>, 'metadata'> & { metadata?: WebSocketEventBaseMetadata }
|
||||
: never
|
||||
|
||||
export type WebSocketEventInputs
|
||||
= | WebSocketEventOf<'input:text'>
|
||||
| WebSocketEventOf<'input:text:voice'>
|
||||
| WebSocketEventOf<'input:voice'>
|
||||
@@ -1 +0,0 @@
|
||||
export * from './events'
|
||||
@@ -2,8 +2,7 @@ import { defineConfig } from 'tsdown'
|
||||
|
||||
export default defineConfig({
|
||||
entry: {
|
||||
'index': 'src/index.ts',
|
||||
'types/index': 'src/types/index.ts',
|
||||
index: 'src/index.ts',
|
||||
},
|
||||
sourcemap: true,
|
||||
unused: true,
|
||||
|
||||
Reference in New Issue
Block a user