anbaric-services-client 1.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 ADDED
@@ -0,0 +1,57 @@
1
+ # anbaric-services-client
2
+
3
+ Client for the Anbaric **additional-services** agentic API. It exposes
4
+ `AnbaricServicesAgent` — a light `Agent` (an actor) whose LLM output is generated
5
+ by a hosted additional-services instance rather than by calling a model provider
6
+ directly. Use it the same way you would `OpenAIAgent`, when your app should reach
7
+ the model through the shared Anbaric service (the legacy-agent path) instead of
8
+ holding provider credentials itself.
9
+
10
+ The additional-services process is closed-source; **this client is not**. It
11
+ depends only on `anbaric-tsapi`.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ npm install anbaric-services-client
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ Pair the agent with `RemoteLLMAgenticAction`: when the action runs, the agent
22
+ generates the job's property changes against a JSON Schema.
23
+
24
+ ```ts
25
+ import {PropertyDefinition, State, StateMachine, Transition} from "anbaric";
26
+ import {RemoteLLMAgenticAction} from "anbaric-state-machine";
27
+ import {AnbaricServicesAgent} from "anbaric-services-client";
28
+
29
+ // baseUrl / apiKey default from ANBARIC_SERVICES_URL / ANBARIC_SERVICES_API_KEY,
30
+ // which Anbaric Cloud injects into deployed app tasks. Locally they default to
31
+ // http://localhost:8790 with no key.
32
+ const agent = new AnbaricServicesAgent("triager", "assistant");
33
+
34
+ const triage = new RemoteLLMAgenticAction(
35
+ "Triage the ticket",
36
+ agent,
37
+ [{ role: "system", content: "Decide the priority of the support ticket." }],
38
+ {
39
+ type: "object",
40
+ properties: { priority: { type: "string", enum: ["low", "high"] } },
41
+ },
42
+ );
43
+
44
+ const support = new StateMachine("support", [
45
+ new State("open", [triage], [new Transition("prioritised", (job) => job.properties.has("priority"))]),
46
+ new State("prioritised"),
47
+ ], "open", [new PropertyDefinition("priority")]);
48
+ ```
49
+
50
+ ## Configuration
51
+
52
+ | Variable | Purpose | Default |
53
+ | --- | --- | --- |
54
+ | `ANBARIC_SERVICES_URL` | Base URL of the additional-services instance | `http://localhost:8790` |
55
+ | `ANBARIC_SERVICES_API_KEY` | Bearer token for the service (if it requires one) | unset |
56
+
57
+ The constructor's `connection` argument (`{ baseUrl, apiKey }`) overrides both.
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "anbaric-services-client",
3
+ "version": "1.8.0",
4
+ "description": "Client for the Anbaric additional-services agentic API: a light Agent whose property changes are generated by a hosted additional-services instance",
5
+ "license": "MIT",
6
+ "author": "chris@anbaric.ai",
7
+ "type": "module",
8
+ "main": "src/index.ts",
9
+ "types": "src/index.ts",
10
+ "dependencies": {
11
+ "anbaric-tsapi": "^1.8.0"
12
+ },
13
+ "devDependencies": {
14
+ "@types/node": "^26.2.0",
15
+ "typescript": "^7.0.2"
16
+ },
17
+ "files": [
18
+ "src"
19
+ ]
20
+ }
@@ -0,0 +1,66 @@
1
+ import {Agent, AgentRequest} from "anbaric-tsapi";
2
+
3
+ type FetchFn = (url : string, init : RequestInit) => Promise<Response>;
4
+
5
+ type AnbaricServicesConnection = {
6
+ baseUrl? : string,
7
+ apiKey? : string,
8
+ };
9
+
10
+ const DEFAULT_SERVICES_URL = "http://localhost:8790";
11
+
12
+ /* The functional half of a legacy Anbaric agent: hands the request to the
13
+ additional-services agentic API, which runs the completion against the
14
+ JSON Schema and returns the conforming output. The service URL and API key
15
+ default from the environment (ANBARIC_SERVICES_URL, ANBARIC_SERVICES_API_KEY),
16
+ falling back to localhost so an app co-located with the service works with
17
+ no configuration. */
18
+ class AnbaricServicesClient extends Agent.Client {
19
+
20
+ private baseUrl : string;
21
+ private apiKey? : string;
22
+
23
+ constructor(connection : AnbaricServicesConnection = {},
24
+ private fetchFn : FetchFn = (url, init) => fetch(url, init)) {
25
+ super();
26
+ this.baseUrl = connection.baseUrl ?? process.env.ANBARIC_SERVICES_URL ?? DEFAULT_SERVICES_URL;
27
+ this.apiKey = connection.apiKey ?? process.env.ANBARIC_SERVICES_API_KEY;
28
+ }
29
+
30
+ async generate(request : AgentRequest) : Promise<Record<string, any>> {
31
+ const instructions = request.messages.filter(message => message.role === "system")
32
+ .map(message => message.content).join("\n\n") || "Produce output conforming to the schema.";
33
+ const input = request.messages.filter(message => message.role !== "system");
34
+
35
+ const response = await this.fetchFn(`${this.baseUrl}/agentic-actions`, {
36
+ method: "POST",
37
+ headers: {
38
+ "content-type": "application/json",
39
+ ...(this.apiKey ? { authorization: `Bearer ${this.apiKey}` } : {}),
40
+ },
41
+ body: JSON.stringify({ instructions, input, outputSchema: request.outputSchema }),
42
+ });
43
+
44
+ if (!response.ok) {
45
+ const problem = await response.json().catch(() => ({}));
46
+ throw new Error(`The Anbaric agent service failed with status ${response.status}${problem.error ? `: ${problem.error}` : ""}`);
47
+ }
48
+
49
+ return (await response.json()).output;
50
+ }
51
+
52
+ }
53
+
54
+ /* A light agent backed by the legacy Anbaric agents, reached through the
55
+ additional-services API. */
56
+ class AnbaricServicesAgent extends Agent {
57
+
58
+ constructor(id : string, role : string, connection : AnbaricServicesConnection = {},
59
+ fetchFn : FetchFn = (url, init) => fetch(url, init)) {
60
+ super(id, role, new AnbaricServicesClient(connection, fetchFn));
61
+ }
62
+
63
+ }
64
+
65
+ export { AnbaricServicesAgent, AnbaricServicesClient }
66
+ export type { AnbaricServicesConnection }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./AnbaricServicesAgent"