@journeyrewards/hive-vercel 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +214 -0
- package/dist/index.d.mts +114 -0
- package/dist/index.d.ts +114 -0
- package/dist/index.js +451 -0
- package/dist/index.mjs +429 -0
- package/dist/server.d.mts +38 -0
- package/dist/server.d.ts +38 -0
- package/dist/server.js +168 -0
- package/dist/server.mjs +141 -0
- package/package.json +55 -0
package/README.md
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
# @journeyrewards/hive-vercel
|
|
2
|
+
|
|
3
|
+
Vercel/Next.js SDK for the Journey Hive Agent Orchestration API. Provides React hooks, ready-to-use components, and server-side helpers for building AI-powered applications with Next.js.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @journeyrewards/hive-vercel @journeyrewards/hive-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
### Provider Setup
|
|
14
|
+
|
|
15
|
+
Wrap your application with `JourneyHiveProvider`:
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { JourneyHiveProvider } from '@journeyrewards/hive-vercel';
|
|
19
|
+
|
|
20
|
+
export default function App({ children }) {
|
|
21
|
+
return (
|
|
22
|
+
<JourneyHiveProvider apiKey="jh_live_..." baseUrl="https://your-api.com">
|
|
23
|
+
{children}
|
|
24
|
+
</JourneyHiveProvider>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Streaming Responses with `useResponse`
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
import { useResponse } from '@journeyrewards/hive-vercel';
|
|
33
|
+
|
|
34
|
+
function ChatInput() {
|
|
35
|
+
const { streamedText, isStreaming, isLoading, error, send } = useResponse({
|
|
36
|
+
agent_id: 'your-agent-id',
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<div>
|
|
41
|
+
<button onClick={() => send('Hello, agent!')}>Send</button>
|
|
42
|
+
{isLoading && <p>Loading...</p>}
|
|
43
|
+
{isStreaming && <p>Streaming: {streamedText}</p>}
|
|
44
|
+
{error && <p>Error: {error.message}</p>}
|
|
45
|
+
</div>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Chat Interface with `useConversation`
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
import { useConversation } from '@journeyrewards/hive-vercel';
|
|
54
|
+
|
|
55
|
+
function Chat({ conversationId }) {
|
|
56
|
+
const { messages, isLoading, sendMessage } = useConversation(conversationId);
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<div>
|
|
60
|
+
{messages.map((msg) => (
|
|
61
|
+
<div key={msg.id}>
|
|
62
|
+
<strong>{msg.role}:</strong> {msg.content[0]?.text}
|
|
63
|
+
</div>
|
|
64
|
+
))}
|
|
65
|
+
<button onClick={() => sendMessage('Hello!')}>Send</button>
|
|
66
|
+
</div>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Agent Management
|
|
72
|
+
|
|
73
|
+
```tsx
|
|
74
|
+
import { useAgent, useAgents } from '@journeyrewards/hive-vercel';
|
|
75
|
+
|
|
76
|
+
function AgentList() {
|
|
77
|
+
const { agents, isLoading } = useAgents();
|
|
78
|
+
|
|
79
|
+
if (isLoading) return <p>Loading agents...</p>;
|
|
80
|
+
return agents.map((a) => <div key={a.id}>{a.name}</div>);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function AgentDetail({ id }) {
|
|
84
|
+
const { agent, update } = useAgent(id);
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<div>
|
|
88
|
+
<h1>{agent?.name}</h1>
|
|
89
|
+
<button onClick={() => update({ personality_notes: 'Be friendly' })}>
|
|
90
|
+
Update
|
|
91
|
+
</button>
|
|
92
|
+
</div>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Server-Side Usage
|
|
98
|
+
|
|
99
|
+
### API Route Handler
|
|
100
|
+
|
|
101
|
+
Create a Next.js API route that proxies requests to Journey Hive:
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
// pages/api/journey-hive.ts
|
|
105
|
+
import { createJourneyHiveHandler } from '@journeyrewards/hive-vercel/server';
|
|
106
|
+
|
|
107
|
+
export default createJourneyHiveHandler({
|
|
108
|
+
apiKey: process.env.JOURNEY_HIVE_API_KEY!,
|
|
109
|
+
baseUrl: process.env.JOURNEY_HIVE_BASE_URL,
|
|
110
|
+
allowedAgentIds: ['agent-1', 'agent-2'],
|
|
111
|
+
});
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Server Client
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
import { JourneyHiveServerClient } from '@journeyrewards/hive-vercel/server';
|
|
118
|
+
|
|
119
|
+
const client = new JourneyHiveServerClient({
|
|
120
|
+
apiKey: process.env.JOURNEY_HIVE_API_KEY!,
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// In getServerSideProps or API routes
|
|
124
|
+
const agents = await client.listAgents();
|
|
125
|
+
const response = await client.createResponse({
|
|
126
|
+
agent_id: 'your-agent-id',
|
|
127
|
+
input: 'Hello!',
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### API Key Validation
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
import { verifyApiKey } from '@journeyrewards/hive-vercel/server';
|
|
135
|
+
|
|
136
|
+
if (!verifyApiKey(apiKey)) {
|
|
137
|
+
throw new Error('Invalid API key format');
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Components
|
|
142
|
+
|
|
143
|
+
### ResponseStream
|
|
144
|
+
|
|
145
|
+
Renders streaming text with a typing indicator:
|
|
146
|
+
|
|
147
|
+
```tsx
|
|
148
|
+
import { ResponseStream } from '@journeyrewards/hive-vercel';
|
|
149
|
+
|
|
150
|
+
<ResponseStream
|
|
151
|
+
agentId="your-agent-id"
|
|
152
|
+
input="Tell me a story"
|
|
153
|
+
onComplete={(text) => console.log('Done:', text)}
|
|
154
|
+
className="my-stream"
|
|
155
|
+
/>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### ConversationView
|
|
159
|
+
|
|
160
|
+
Full conversation interface with message history and input:
|
|
161
|
+
|
|
162
|
+
```tsx
|
|
163
|
+
import { ConversationView } from '@journeyrewards/hive-vercel';
|
|
164
|
+
|
|
165
|
+
<ConversationView
|
|
166
|
+
conversationId="conv-123"
|
|
167
|
+
className="my-chat"
|
|
168
|
+
/>
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### MessageBubble
|
|
172
|
+
|
|
173
|
+
Single message display:
|
|
174
|
+
|
|
175
|
+
```tsx
|
|
176
|
+
import { MessageBubble } from '@journeyrewards/hive-vercel';
|
|
177
|
+
|
|
178
|
+
<MessageBubble role="user" content="Hello!" timestamp={1700000000} />
|
|
179
|
+
<MessageBubble role="assistant" content="Hi there!" />
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### AgentStatus
|
|
183
|
+
|
|
184
|
+
Agent status badge:
|
|
185
|
+
|
|
186
|
+
```tsx
|
|
187
|
+
import { AgentStatus } from '@journeyrewards/hive-vercel';
|
|
188
|
+
|
|
189
|
+
<AgentStatus agent={agent} />
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## API Reference
|
|
193
|
+
|
|
194
|
+
### Hooks
|
|
195
|
+
|
|
196
|
+
| Hook | Returns | Description |
|
|
197
|
+
|------|---------|-------------|
|
|
198
|
+
| `useJourneyHive()` | `client` | Access the Journey Hive client instance |
|
|
199
|
+
| `useResponse(params?)` | `{ data, isLoading, isStreaming, streamedText, error, send }` | Send messages with streaming support |
|
|
200
|
+
| `useConversation(id)` | `{ conversation, messages, isLoading, error, sendMessage }` | Manage a conversation |
|
|
201
|
+
| `useAgent(id)` | `{ agent, isLoading, error, update }` | Fetch and update an agent |
|
|
202
|
+
| `useAgents()` | `{ agents, isLoading, error }` | List all available agents |
|
|
203
|
+
|
|
204
|
+
### Server Exports
|
|
205
|
+
|
|
206
|
+
| Export | Description |
|
|
207
|
+
|--------|-------------|
|
|
208
|
+
| `createJourneyHiveHandler(config)` | Creates a Next.js API route handler |
|
|
209
|
+
| `JourneyHiveServerClient` | Server-side API client (no React) |
|
|
210
|
+
| `verifyApiKey(key)` | Validates API key format |
|
|
211
|
+
|
|
212
|
+
## License
|
|
213
|
+
|
|
214
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { JourneyHiveConfig, CreateResponseParams, Response, Conversation, Message, Agent } from '@journeyrewards/hive-sdk';
|
|
4
|
+
|
|
5
|
+
interface JourneyHiveClient {
|
|
6
|
+
config: JourneyHiveConfig;
|
|
7
|
+
responses: {
|
|
8
|
+
create(params: CreateResponseParams): Promise<Response | AsyncIterable<{
|
|
9
|
+
event: string;
|
|
10
|
+
data: any;
|
|
11
|
+
}>>;
|
|
12
|
+
};
|
|
13
|
+
conversations: {
|
|
14
|
+
get(id: string): Promise<Conversation>;
|
|
15
|
+
messages(id: string): Promise<{
|
|
16
|
+
data: Message[];
|
|
17
|
+
}>;
|
|
18
|
+
};
|
|
19
|
+
agents: {
|
|
20
|
+
get(id: string): Promise<Agent>;
|
|
21
|
+
list(): Promise<{
|
|
22
|
+
data: Agent[];
|
|
23
|
+
}>;
|
|
24
|
+
update(id: string, params: any): Promise<Agent>;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
interface JourneyHiveProviderProps {
|
|
28
|
+
apiKey: string;
|
|
29
|
+
baseUrl?: string;
|
|
30
|
+
children: ReactNode;
|
|
31
|
+
}
|
|
32
|
+
declare function JourneyHiveProvider({ apiKey, baseUrl, children }: JourneyHiveProviderProps): react.FunctionComponentElement<react.ProviderProps<JourneyHiveClient | null>>;
|
|
33
|
+
declare function useJourneyHive(): JourneyHiveClient;
|
|
34
|
+
interface UseResponseReturn {
|
|
35
|
+
data: Response | null;
|
|
36
|
+
isLoading: boolean;
|
|
37
|
+
isStreaming: boolean;
|
|
38
|
+
streamedText: string;
|
|
39
|
+
error: Error | null;
|
|
40
|
+
send: (input: string) => Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
declare function useResponse(params?: Partial<CreateResponseParams>): UseResponseReturn;
|
|
43
|
+
interface UseConversationReturn {
|
|
44
|
+
conversation: Conversation | null;
|
|
45
|
+
messages: Message[];
|
|
46
|
+
isLoading: boolean;
|
|
47
|
+
error: Error | null;
|
|
48
|
+
sendMessage: (input: string) => Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
declare function useConversation(conversationId: string): UseConversationReturn;
|
|
51
|
+
interface UseAgentReturn {
|
|
52
|
+
agent: Agent | null;
|
|
53
|
+
isLoading: boolean;
|
|
54
|
+
error: Error | null;
|
|
55
|
+
update: (params: any) => Promise<void>;
|
|
56
|
+
}
|
|
57
|
+
declare function useAgent(agentId: string): UseAgentReturn;
|
|
58
|
+
interface UseAgentsReturn {
|
|
59
|
+
agents: Agent[];
|
|
60
|
+
isLoading: boolean;
|
|
61
|
+
error: Error | null;
|
|
62
|
+
}
|
|
63
|
+
declare function useAgents(): UseAgentsReturn;
|
|
64
|
+
|
|
65
|
+
interface ResponseStreamProps {
|
|
66
|
+
agentId: string;
|
|
67
|
+
input?: string;
|
|
68
|
+
onComplete?: (text: string) => void;
|
|
69
|
+
className?: string;
|
|
70
|
+
}
|
|
71
|
+
declare function ResponseStream({ agentId, input, onComplete, className }: ResponseStreamProps): react.DetailedReactHTMLElement<{
|
|
72
|
+
className: string;
|
|
73
|
+
}, HTMLElement>;
|
|
74
|
+
interface MessageBubbleProps {
|
|
75
|
+
role: string;
|
|
76
|
+
content: string;
|
|
77
|
+
timestamp?: number;
|
|
78
|
+
}
|
|
79
|
+
declare function MessageBubble({ role, content, timestamp }: MessageBubbleProps): react.DetailedReactHTMLElement<{
|
|
80
|
+
className: string;
|
|
81
|
+
style: {
|
|
82
|
+
display: "flex";
|
|
83
|
+
flexDirection: "column";
|
|
84
|
+
alignItems: "flex-end" | "flex-start";
|
|
85
|
+
marginBottom: string;
|
|
86
|
+
};
|
|
87
|
+
}, HTMLElement>;
|
|
88
|
+
interface ConversationViewProps {
|
|
89
|
+
conversationId: string;
|
|
90
|
+
agentId?: string;
|
|
91
|
+
className?: string;
|
|
92
|
+
}
|
|
93
|
+
declare function ConversationView({ conversationId, agentId, className }: ConversationViewProps): react.DetailedReactHTMLElement<{
|
|
94
|
+
className: string;
|
|
95
|
+
}, HTMLElement>;
|
|
96
|
+
interface AgentStatusProps {
|
|
97
|
+
agent: Agent;
|
|
98
|
+
}
|
|
99
|
+
declare function AgentStatus({ agent }: AgentStatusProps): react.DetailedReactHTMLElement<{
|
|
100
|
+
className: string;
|
|
101
|
+
style: {
|
|
102
|
+
display: "inline-flex";
|
|
103
|
+
alignItems: "center";
|
|
104
|
+
gap: string;
|
|
105
|
+
padding: string;
|
|
106
|
+
borderRadius: string;
|
|
107
|
+
fontSize: string;
|
|
108
|
+
fontWeight: number;
|
|
109
|
+
border: string;
|
|
110
|
+
color: string;
|
|
111
|
+
};
|
|
112
|
+
}, HTMLElement>;
|
|
113
|
+
|
|
114
|
+
export { AgentStatus, ConversationView, JourneyHiveProvider, MessageBubble, ResponseStream, useAgent, useAgents, useConversation, useJourneyHive, useResponse };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { JourneyHiveConfig, CreateResponseParams, Response, Conversation, Message, Agent } from '@journeyrewards/hive-sdk';
|
|
4
|
+
|
|
5
|
+
interface JourneyHiveClient {
|
|
6
|
+
config: JourneyHiveConfig;
|
|
7
|
+
responses: {
|
|
8
|
+
create(params: CreateResponseParams): Promise<Response | AsyncIterable<{
|
|
9
|
+
event: string;
|
|
10
|
+
data: any;
|
|
11
|
+
}>>;
|
|
12
|
+
};
|
|
13
|
+
conversations: {
|
|
14
|
+
get(id: string): Promise<Conversation>;
|
|
15
|
+
messages(id: string): Promise<{
|
|
16
|
+
data: Message[];
|
|
17
|
+
}>;
|
|
18
|
+
};
|
|
19
|
+
agents: {
|
|
20
|
+
get(id: string): Promise<Agent>;
|
|
21
|
+
list(): Promise<{
|
|
22
|
+
data: Agent[];
|
|
23
|
+
}>;
|
|
24
|
+
update(id: string, params: any): Promise<Agent>;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
interface JourneyHiveProviderProps {
|
|
28
|
+
apiKey: string;
|
|
29
|
+
baseUrl?: string;
|
|
30
|
+
children: ReactNode;
|
|
31
|
+
}
|
|
32
|
+
declare function JourneyHiveProvider({ apiKey, baseUrl, children }: JourneyHiveProviderProps): react.FunctionComponentElement<react.ProviderProps<JourneyHiveClient | null>>;
|
|
33
|
+
declare function useJourneyHive(): JourneyHiveClient;
|
|
34
|
+
interface UseResponseReturn {
|
|
35
|
+
data: Response | null;
|
|
36
|
+
isLoading: boolean;
|
|
37
|
+
isStreaming: boolean;
|
|
38
|
+
streamedText: string;
|
|
39
|
+
error: Error | null;
|
|
40
|
+
send: (input: string) => Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
declare function useResponse(params?: Partial<CreateResponseParams>): UseResponseReturn;
|
|
43
|
+
interface UseConversationReturn {
|
|
44
|
+
conversation: Conversation | null;
|
|
45
|
+
messages: Message[];
|
|
46
|
+
isLoading: boolean;
|
|
47
|
+
error: Error | null;
|
|
48
|
+
sendMessage: (input: string) => Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
declare function useConversation(conversationId: string): UseConversationReturn;
|
|
51
|
+
interface UseAgentReturn {
|
|
52
|
+
agent: Agent | null;
|
|
53
|
+
isLoading: boolean;
|
|
54
|
+
error: Error | null;
|
|
55
|
+
update: (params: any) => Promise<void>;
|
|
56
|
+
}
|
|
57
|
+
declare function useAgent(agentId: string): UseAgentReturn;
|
|
58
|
+
interface UseAgentsReturn {
|
|
59
|
+
agents: Agent[];
|
|
60
|
+
isLoading: boolean;
|
|
61
|
+
error: Error | null;
|
|
62
|
+
}
|
|
63
|
+
declare function useAgents(): UseAgentsReturn;
|
|
64
|
+
|
|
65
|
+
interface ResponseStreamProps {
|
|
66
|
+
agentId: string;
|
|
67
|
+
input?: string;
|
|
68
|
+
onComplete?: (text: string) => void;
|
|
69
|
+
className?: string;
|
|
70
|
+
}
|
|
71
|
+
declare function ResponseStream({ agentId, input, onComplete, className }: ResponseStreamProps): react.DetailedReactHTMLElement<{
|
|
72
|
+
className: string;
|
|
73
|
+
}, HTMLElement>;
|
|
74
|
+
interface MessageBubbleProps {
|
|
75
|
+
role: string;
|
|
76
|
+
content: string;
|
|
77
|
+
timestamp?: number;
|
|
78
|
+
}
|
|
79
|
+
declare function MessageBubble({ role, content, timestamp }: MessageBubbleProps): react.DetailedReactHTMLElement<{
|
|
80
|
+
className: string;
|
|
81
|
+
style: {
|
|
82
|
+
display: "flex";
|
|
83
|
+
flexDirection: "column";
|
|
84
|
+
alignItems: "flex-end" | "flex-start";
|
|
85
|
+
marginBottom: string;
|
|
86
|
+
};
|
|
87
|
+
}, HTMLElement>;
|
|
88
|
+
interface ConversationViewProps {
|
|
89
|
+
conversationId: string;
|
|
90
|
+
agentId?: string;
|
|
91
|
+
className?: string;
|
|
92
|
+
}
|
|
93
|
+
declare function ConversationView({ conversationId, agentId, className }: ConversationViewProps): react.DetailedReactHTMLElement<{
|
|
94
|
+
className: string;
|
|
95
|
+
}, HTMLElement>;
|
|
96
|
+
interface AgentStatusProps {
|
|
97
|
+
agent: Agent;
|
|
98
|
+
}
|
|
99
|
+
declare function AgentStatus({ agent }: AgentStatusProps): react.DetailedReactHTMLElement<{
|
|
100
|
+
className: string;
|
|
101
|
+
style: {
|
|
102
|
+
display: "inline-flex";
|
|
103
|
+
alignItems: "center";
|
|
104
|
+
gap: string;
|
|
105
|
+
padding: string;
|
|
106
|
+
borderRadius: string;
|
|
107
|
+
fontSize: string;
|
|
108
|
+
fontWeight: number;
|
|
109
|
+
border: string;
|
|
110
|
+
color: string;
|
|
111
|
+
};
|
|
112
|
+
}, HTMLElement>;
|
|
113
|
+
|
|
114
|
+
export { AgentStatus, ConversationView, JourneyHiveProvider, MessageBubble, ResponseStream, useAgent, useAgents, useConversation, useJourneyHive, useResponse };
|