-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update docs and standardization of methods in ApiClient (#75)
Co-authored-by: Ariel Gentile <[email protected]>
- Loading branch information
1 parent
c570ca4
commit e8d858d
Showing
7 changed files
with
343 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
`@2060.io/service-agent-client` | ||
|
||
# Service Agent Client | ||
**Service Agent Client** is a TypeScript library designed to simplify the interaction with **Service Agent** (`@2060.io/service-agent-main`). It provides an abstraction layer for communicating with the agent, handling messaging, credential management, and event handling efficiently. | ||
|
||
This package ensures that the client stays updated with the latest API versioning of the **Service Agent** to maintain compatibility with evolving endpoints. | ||
|
||
## Features | ||
- **Simplified API interaction:** Provides an easy-to-use client to interact with the Service Agent. | ||
- **Event handling:** Includes an ExpressEventHandler for quick integration into Express-based applications. | ||
- **Service-based structure:** Dedicated services for messaging, credentials, invitations, and revocation registries. | ||
- **Versioning support:** Supports API versioning to maintain compatibility with different Service Agent versions. | ||
|
||
## Repository | ||
Find the public repository here: [2060 Service Agent](../../README.md) | ||
|
||
## How to work | ||
```plantuml | ||
@startuml | ||
package "2060 Ecosystem" { | ||
package "Service Agent (SA)" { | ||
class ServiceAgent { | ||
+ Handles DIDComm communication | ||
+ Manages agent wallet and credentials | ||
+ Exposes API for client interactions | ||
} | ||
} | ||
package "Libraries" { | ||
class NestJSClient { | ||
+ Plug-and-play integration | ||
+ Selectable modules for various services | ||
+ Modules: | ||
-- MessageEventOptions: Configures message event handling | ||
-- ConnectionEventOptions: Configures connection event handling | ||
-- CredentialOptions: Configures credential management | ||
} | ||
class Client ##red { | ||
+ Directly manages requests to SA | ||
+ Facilitates reception of requests from modules | ||
+ Provides an abstraction for service communication | ||
+ Interfaces: | ||
-- messages | ||
-- credentialTypes | ||
-- revocationRegistries | ||
-- invitations | ||
} | ||
class ModelLibrary { | ||
+ Defines required data models | ||
+ Ensures type safety across services | ||
} | ||
} | ||
} | ||
NestJSClient --> ServiceAgent : Uses | ||
Client --> ServiceAgent : Sends requests | ||
Client --> ServiceAgent : Receives requests | ||
Client --> ModelLibrary : Uses models | ||
ModelLibrary --> ServiceAgent : Provides data models | ||
NestJSClient --> ModelLibrary : Uses models | ||
@enduml | ||
``` | ||
|
||
## Installation | ||
```sh | ||
npm install @2060.io/service-agent-client | ||
``` | ||
or | ||
```sh | ||
yarn add @2060.io/service-agent-client | ||
``` | ||
## `ApiClient.ts` | ||
`ApiClient` class provides a simple interface for interacting with the Service Agent. It abstracts API calls and offers dedicated service methods for messaging, credential types, invitations, and revocation registries. | ||
|
||
### Example Usage | ||
```ts | ||
import { ApiClient, ApiVersion } from '@2060.io/service-agent-client' | ||
|
||
const apiClient = new ApiClient('http://localhost:3000', ApiVersion.V1) | ||
|
||
// Sending a message | ||
const messageId = await apiClient.messages.send( | ||
new TextMessage({ | ||
connectionId: 'connectionId', | ||
content: 'Hello, world!', | ||
}) | ||
) | ||
|
||
console.log(`Message sent with ID: ${messageId}`) | ||
``` | ||
|
||
### Services | ||
- `messages:` Handles message sending and receiving. | ||
- `credentialTypes:` Manages credential types. | ||
- `revocationRegistries:` Manages revocation registries. | ||
- `invitations:` Handles connection invitations. | ||
|
||
## `ExpressEventHandler.ts` | ||
The `ExpressEventHandler` simplifies event handling for Express applications, mapping API endpoints to event handlers. | ||
### Example Usage | ||
```ts | ||
import express from 'express' | ||
import { ExpressEventHandler } from '@2060.io/service-agent-client' | ||
|
||
const app = express() | ||
const eventHandler = new ExpressEventHandler(app) | ||
|
||
expressHandler.messageStateUpdated(async (req, res) => { | ||
const obj = req.body | ||
logger.info(`message state updated: ${JSON.stringify(obj)}`) | ||
res.json({ message: 'ok' }) | ||
}) | ||
|
||
app.listen(3000, () => console.log('Server running on port 3000')) | ||
``` | ||
### Available Event Handlers | ||
- `connectionStateUpdated` (`POST /connection-state-updated`) | ||
- `messageStateUpdated` (`POST /message-state-updated`) | ||
- `messageReceived` (`POST /message-received`) | ||
|
||
## Contributing | ||
This library evolves alongside the Service Agent. Contributions are welcome! | ||
- Fork the repository. | ||
- Create a feature branch. | ||
- Commit changes. | ||
- Open a pull request. | ||
|
||
For more details, visit the [official repository](https://github.com/2060-io/2060-service-agent). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
`@2060.io/service-agent-model` | ||
# Service Agent Model | ||
|
||
This package provides the data models used by **Service Agent** and its related services and libraries within the `@2060.io` ecosystem. These models are essential for chatbot development and facilitate integration with the broader system. | ||
|
||
## Packages Using This Library | ||
|
||
The models in this package are used by the following services and libraries: | ||
|
||
- **[@2060.io/service-agent-main](../../README.md)** – The core Service Agent. | ||
- **[@2060.io/service-agent-nestjs-client](../nestjs-client/README.md)** – A NestJS client for interacting with the Service Agent. | ||
- **[@2060.io/service-agent-client](../client/README.md)** – A general-purpose api client for the Service Agent. | ||
|
||
|
||
## Usage | ||
|
||
This package defines essential models that support structured communication and event handling within the Service Agent ecosystem. It is designed to be used by chatbot services and other integrations that rely on a standardized message format. | ||
|
||
## How to work | ||
```plantuml | ||
@startuml | ||
package "2060 Ecosystem" { | ||
package "Service Agent (SA)" { | ||
class ServiceAgent { | ||
+ Handles DIDComm communication | ||
+ Manages agent wallet and credentials | ||
+ Exposes API for client interactions | ||
} | ||
} | ||
package "Libraries" { | ||
class NestJSClient { | ||
+ Plug-and-play integration | ||
+ Selectable modules for various services | ||
+ Modules: | ||
-- MessageEventOptions: Configures message event handling | ||
-- ConnectionEventOptions: Configures connection event handling | ||
-- CredentialOptions: Configures credential management | ||
} | ||
class Client { | ||
+ Directly manages requests to SA | ||
+ Facilitates reception of requests from modules | ||
+ Provides an abstraction for service communication | ||
+ Interfaces: | ||
-- messages | ||
-- credentialTypes | ||
-- revocationRegistries | ||
-- invitations | ||
} | ||
class ModelLibrary ##red { | ||
+ Defines required data models | ||
+ Ensures type safety across services | ||
} | ||
} | ||
} | ||
NestJSClient --> ServiceAgent : Uses | ||
Client --> ServiceAgent : Sends requests | ||
Client --> ServiceAgent : Receives requests | ||
Client --> ModelLibrary : Uses models | ||
ModelLibrary --> ServiceAgent : Provides data models | ||
NestJSClient --> ModelLibrary : Uses models | ||
@enduml | ||
``` | ||
|
||
### Installation | ||
|
||
```sh | ||
npm install @2060.io/service-agent-model | ||
``` | ||
or | ||
```sh | ||
yarn add @2060.io/service-agent-model | ||
``` | ||
|
||
## Example | ||
|
||
Importing and using a message model: | ||
|
||
```typescript | ||
import { CallOfferRequestMessage } from '@2060.io/service-agent-model'; | ||
|
||
const callOffer = new CallOfferRequestMessage({ | ||
connectionId: 'connectionId', | ||
description: 'Start call', | ||
parameters: { wsUrl, roomId, peerId }, | ||
}); | ||
|
||
console.log(callOffer); | ||
``` |
Oops, something went wrong.