@brownandroot/api 0.7.0 → 0.8.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 +16 -3
- package/dist/index.d.ts +22 -0
- package/dist/index.js +16 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @brownandroot/api
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
TypeScript client for the Brown & Root APIHub data service. Provides read-only access to company data and an LLM chat endpoint powered by Azure AI Foundry.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -61,10 +61,21 @@ const orders = await client.getWorkorders()
|
|
|
61
61
|
const order = await client.getWorkorder('WO001')
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
-
### LLM
|
|
64
|
+
### LLM
|
|
65
65
|
|
|
66
66
|
```typescript
|
|
67
|
+
// List logs
|
|
67
68
|
const logs = await client.getLlmLogs()
|
|
69
|
+
|
|
70
|
+
// Chat completion
|
|
71
|
+
const result = await client.chat({
|
|
72
|
+
messages: [{ role: 'user', content: 'Summarize this document...' }],
|
|
73
|
+
source: 'my-app',
|
|
74
|
+
user: 'jane.doe',
|
|
75
|
+
function: 'summarize',
|
|
76
|
+
})
|
|
77
|
+
console.log(result.message.content)
|
|
78
|
+
console.log(result.usage) // { tokensIn, tokensOut, totalTokens }
|
|
68
79
|
```
|
|
69
80
|
|
|
70
81
|
## Types
|
|
@@ -77,9 +88,11 @@ import type {
|
|
|
77
88
|
BusinessUnit,
|
|
78
89
|
Costcode,
|
|
79
90
|
Paytype,
|
|
80
|
-
Shift,
|
|
81
91
|
Workorder,
|
|
82
92
|
LlmLog,
|
|
93
|
+
ChatMessage,
|
|
94
|
+
ChatRequest,
|
|
95
|
+
ChatResponse,
|
|
83
96
|
ApiHubClientOptions,
|
|
84
97
|
} from '@brownandroot/api'
|
|
85
98
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -58,6 +58,26 @@ export interface LlmLog {
|
|
|
58
58
|
totalTokens: number | null;
|
|
59
59
|
createdAt: string | null;
|
|
60
60
|
}
|
|
61
|
+
export interface ChatMessage {
|
|
62
|
+
role: 'system' | 'user' | 'assistant';
|
|
63
|
+
content: string;
|
|
64
|
+
}
|
|
65
|
+
export interface ChatRequest {
|
|
66
|
+
messages: ChatMessage[];
|
|
67
|
+
source: string;
|
|
68
|
+
user: string;
|
|
69
|
+
function?: string;
|
|
70
|
+
temperature?: number;
|
|
71
|
+
maxTokens?: number;
|
|
72
|
+
}
|
|
73
|
+
export interface ChatResponse {
|
|
74
|
+
message: ChatMessage;
|
|
75
|
+
usage: {
|
|
76
|
+
tokensIn: number | null;
|
|
77
|
+
tokensOut: number | null;
|
|
78
|
+
totalTokens: number | null;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
61
81
|
export interface BusinessUnit {
|
|
62
82
|
id: string;
|
|
63
83
|
companyId: string;
|
|
@@ -145,6 +165,8 @@ export declare class ApiHubClient {
|
|
|
145
165
|
}>;
|
|
146
166
|
/** List all LLM log entries (newest first) */
|
|
147
167
|
getLlmLogs(): Promise<LlmLog[]>;
|
|
168
|
+
/** Send a chat completion request to the LLM */
|
|
169
|
+
chat(request: ChatRequest): Promise<ChatResponse>;
|
|
148
170
|
getBusinessUnits(): Promise<BusinessUnit[]>;
|
|
149
171
|
getBusinessUnitsDropdown(): Promise<DropdownOption[]>;
|
|
150
172
|
getBusinessUnit(id: string): Promise<BusinessUnit>;
|
package/dist/index.js
CHANGED
|
@@ -54,6 +54,22 @@ export class ApiHubClient {
|
|
|
54
54
|
async getLlmLogs() {
|
|
55
55
|
return this.request('/llm-logs');
|
|
56
56
|
}
|
|
57
|
+
/** Send a chat completion request to the LLM */
|
|
58
|
+
async chat(request) {
|
|
59
|
+
const res = await fetch(`${this.baseUrl}/llm/chat`, {
|
|
60
|
+
method: 'POST',
|
|
61
|
+
headers: {
|
|
62
|
+
'x-api-key': this.apiKey,
|
|
63
|
+
'Content-Type': 'application/json',
|
|
64
|
+
},
|
|
65
|
+
body: JSON.stringify(request),
|
|
66
|
+
});
|
|
67
|
+
if (!res.ok) {
|
|
68
|
+
const body = await res.json().catch(() => ({}));
|
|
69
|
+
throw new Error(body.error ?? `Request failed: ${res.status}`);
|
|
70
|
+
}
|
|
71
|
+
return res.json();
|
|
72
|
+
}
|
|
57
73
|
// -----------------------------------------------------------------------
|
|
58
74
|
// Business Units
|
|
59
75
|
// -----------------------------------------------------------------------
|