@caltra/client 0.1.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/LICENSE +21 -0
- package/README.md +28 -0
- package/dist/client.d.ts +27 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +107 -0
- package/dist/client.js.map +1 -0
- package/dist/error.d.ts +12 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +39 -0
- package/dist/error.js.map +1 -0
- package/dist/event_connection.d.ts +19 -0
- package/dist/event_connection.d.ts.map +1 -0
- package/dist/event_connection.js +101 -0
- package/dist/event_connection.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +76 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Caltra
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# `@caltra/client`
|
|
2
|
+
|
|
3
|
+
Framework-neutral TypeScript client for durable Caltra agent sessions in browser applications.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @caltra/client
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Use
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { CaltraClient } from "@caltra/client";
|
|
15
|
+
|
|
16
|
+
const client = new CaltraClient({
|
|
17
|
+
apiUrl: "https://api.caltra.dev",
|
|
18
|
+
tokenProvider: async () => getShortLivedClientToken(),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const agents = await client.listAgents();
|
|
22
|
+
const session = await client.createSession({ agentId: agents.data[0].id });
|
|
23
|
+
const events = await client.openSessionEvents(session.id);
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The token provider must return a short-lived Caltra client token. Do not embed a server API key in a browser bundle.
|
|
27
|
+
|
|
28
|
+
The package is ESM-only. See the [Caltra SDK repository](https://github.com/caltra-dev/caltra-sdk) for development and integration-app instructions.
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CaltraSessionEventConnection } from "./event_connection.js";
|
|
2
|
+
import type { CaltraAgent, CaltraClientOptions, CaltraMessageSubmission, CaltraPage, CaltraPageInput, CaltraSession, CaltraSessionMessage } from "./types.js";
|
|
3
|
+
/** Calls the versioned Caltra Client API without coupling applications to a React runtime. */
|
|
4
|
+
export declare class CaltraClient {
|
|
5
|
+
private readonly options;
|
|
6
|
+
private readonly apiUrl;
|
|
7
|
+
private readonly fetchImplementation;
|
|
8
|
+
constructor(options: CaltraClientOptions);
|
|
9
|
+
listAgents(input?: CaltraPageInput): Promise<CaltraPage<CaltraAgent>>;
|
|
10
|
+
listSessions(input?: CaltraPageInput): Promise<CaltraPage<CaltraSession>>;
|
|
11
|
+
createSession(input: {
|
|
12
|
+
agentId: string;
|
|
13
|
+
}): Promise<CaltraSession>;
|
|
14
|
+
listSessionMessages(sessionId: string, input?: CaltraPageInput): Promise<CaltraPage<CaltraSessionMessage>>;
|
|
15
|
+
openSessionEvents(sessionId: string, options?: {
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
}): Promise<CaltraSessionEventConnection>;
|
|
18
|
+
sendMessage(sessionId: string, input: {
|
|
19
|
+
text: string;
|
|
20
|
+
}): Promise<CaltraMessageSubmission>;
|
|
21
|
+
invalidateToken(): Promise<void>;
|
|
22
|
+
private getPage;
|
|
23
|
+
private request;
|
|
24
|
+
private headers;
|
|
25
|
+
private url;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,KAAK,EACV,WAAW,EACX,mBAAmB,EACnB,uBAAuB,EACvB,UAAU,EACV,eAAe,EACf,aAAa,EACb,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAmCpB,8FAA8F;AAC9F,qBAAa,YAAY;IAIX,OAAO,CAAC,QAAQ,CAAC,OAAO;IAHpC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAe;gBAEtB,OAAO,EAAE,mBAAmB;IAKnD,UAAU,CAAC,KAAK,GAAE,eAAoB,GAAG,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;IAIzE,YAAY,CAAC,KAAK,GAAE,eAAoB,GAAG,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;IAI7E,aAAa,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,aAAa,CAAC;IAQjE,mBAAmB,CACvB,SAAS,EAAE,MAAM,EACjB,KAAK,GAAE,eAAoB,GAC1B,OAAO,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAC;IAQtC,iBAAiB,CACrB,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAO,GACrC,OAAO,CAAC,4BAA4B,CAAC;IAelC,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,uBAAuB,CAAC;IAYzF,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;YAIxB,OAAO;YAWP,OAAO;YAgBP,OAAO;IAMrB,OAAO,CAAC,GAAG;CAGZ"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { CaltraApiError } from "./error.js";
|
|
3
|
+
import { CaltraSessionEventConnection } from "./event_connection.js";
|
|
4
|
+
const PageSchema = (item) => z.object({
|
|
5
|
+
data: z.array(item),
|
|
6
|
+
next_cursor: z.string().nullable(),
|
|
7
|
+
}).strict();
|
|
8
|
+
const AgentSchema = z.object({
|
|
9
|
+
created_at: z.string(),
|
|
10
|
+
description: z.string().nullable(),
|
|
11
|
+
id: z.string(),
|
|
12
|
+
name: z.string(),
|
|
13
|
+
}).strict();
|
|
14
|
+
const SessionSchema = z.object({
|
|
15
|
+
agent: z.object({ id: z.string().uuid(), name: z.string() }).strict(),
|
|
16
|
+
created_at: z.string(),
|
|
17
|
+
id: z.string().uuid(),
|
|
18
|
+
status: z.enum(["active", "closed"]),
|
|
19
|
+
updated_at: z.string(),
|
|
20
|
+
}).strict();
|
|
21
|
+
const MessageSchema = z.object({
|
|
22
|
+
created_at: z.string(),
|
|
23
|
+
id: z.string().uuid(),
|
|
24
|
+
role: z.enum(["user", "assistant"]),
|
|
25
|
+
status: z.enum(["streaming", "completed", "failed", "cancelled"]),
|
|
26
|
+
text: z.string(),
|
|
27
|
+
}).strict();
|
|
28
|
+
const SubmissionSchema = z.object({
|
|
29
|
+
message_id: z.string().uuid(),
|
|
30
|
+
turn_id: z.string().uuid(),
|
|
31
|
+
}).strict();
|
|
32
|
+
/** Calls the versioned Caltra Client API without coupling applications to a React runtime. */
|
|
33
|
+
export class CaltraClient {
|
|
34
|
+
options;
|
|
35
|
+
apiUrl;
|
|
36
|
+
fetchImplementation;
|
|
37
|
+
constructor(options) {
|
|
38
|
+
this.options = options;
|
|
39
|
+
this.apiUrl = options.apiUrl.replace(/\/+$/, "");
|
|
40
|
+
this.fetchImplementation = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
41
|
+
}
|
|
42
|
+
async listAgents(input = {}) {
|
|
43
|
+
return await this.getPage("/agents", input, PageSchema(AgentSchema));
|
|
44
|
+
}
|
|
45
|
+
async listSessions(input = {}) {
|
|
46
|
+
return await this.getPage("/sessions", input, PageSchema(SessionSchema));
|
|
47
|
+
}
|
|
48
|
+
async createSession(input) {
|
|
49
|
+
return await this.request("/sessions", SessionSchema, {
|
|
50
|
+
body: JSON.stringify({ agent_id: input.agentId }),
|
|
51
|
+
headers: { "content-type": "application/json" },
|
|
52
|
+
method: "POST",
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
async listSessionMessages(sessionId, input = {}) {
|
|
56
|
+
return await this.getPage(`/sessions/${encodeURIComponent(sessionId)}/messages`, input, PageSchema(MessageSchema));
|
|
57
|
+
}
|
|
58
|
+
async openSessionEvents(sessionId, options = {}) {
|
|
59
|
+
const response = await this.fetchImplementation(this.url(`/sessions/${encodeURIComponent(sessionId)}/events`), {
|
|
60
|
+
headers: await this.headers({ accept: "text/event-stream" }),
|
|
61
|
+
method: "GET",
|
|
62
|
+
signal: options.signal,
|
|
63
|
+
});
|
|
64
|
+
if (!response.ok)
|
|
65
|
+
throw await CaltraApiError.fromResponse(response);
|
|
66
|
+
if (!response.headers.get("content-type")?.includes("text/event-stream")) {
|
|
67
|
+
throw new Error("Caltra did not return an event stream.");
|
|
68
|
+
}
|
|
69
|
+
return new CaltraSessionEventConnection(response);
|
|
70
|
+
}
|
|
71
|
+
async sendMessage(sessionId, input) {
|
|
72
|
+
return await this.request(`/sessions/${encodeURIComponent(sessionId)}/messages`, SubmissionSchema, {
|
|
73
|
+
body: JSON.stringify({ text: input.text }),
|
|
74
|
+
headers: { "content-type": "application/json" },
|
|
75
|
+
method: "POST",
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
async invalidateToken() {
|
|
79
|
+
await this.options.tokenInvalidator?.();
|
|
80
|
+
}
|
|
81
|
+
async getPage(path, input, schema) {
|
|
82
|
+
const url = this.url(path);
|
|
83
|
+
if (input.limit !== undefined)
|
|
84
|
+
url.searchParams.set("limit", String(input.limit));
|
|
85
|
+
if (input.cursor !== undefined)
|
|
86
|
+
url.searchParams.set("cursor", input.cursor);
|
|
87
|
+
return await this.request(url, schema);
|
|
88
|
+
}
|
|
89
|
+
async request(path, schema, init = {}) {
|
|
90
|
+
const response = await this.fetchImplementation(typeof path === "string" ? this.url(path) : path, {
|
|
91
|
+
...init,
|
|
92
|
+
headers: await this.headers(init.headers),
|
|
93
|
+
});
|
|
94
|
+
if (!response.ok)
|
|
95
|
+
throw await CaltraApiError.fromResponse(response);
|
|
96
|
+
return schema.parse(await response.json());
|
|
97
|
+
}
|
|
98
|
+
async headers(input) {
|
|
99
|
+
const headers = new Headers(input);
|
|
100
|
+
headers.set("authorization", `Bearer ${await this.options.tokenProvider()}`);
|
|
101
|
+
return headers;
|
|
102
|
+
}
|
|
103
|
+
url(path) {
|
|
104
|
+
return new URL(`${this.apiUrl}/client/v1${path}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AAWrE,MAAM,UAAU,GAAG,CAAsB,IAAO,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;IAC5D,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;IACnB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CACnC,CAAC,CAAC,MAAM,EAAE,CAAC;AAEZ,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3B,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IACtB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAClC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;CACjB,CAAC,CAAC,MAAM,EAAE,CAAC;AAEZ,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7B,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACrE,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IACtB,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE;IACrB,MAAM,EAAE,CAAC,CAAC,IAAI,C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QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAChD;YACE,GAAG,IAAI;YACP,OAAO,EAAE,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC;SAC1C,CACF,CAAC;QACF,IAAI,CAAC,QAAQ,CAAC,EAAE;YAAE,MAAM,MAAM,cAAc,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;QACpE,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7C,CAAC;IAEO,KAAK,CAAC,OAAO,CAAC,KAAmB;QACvC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC;QACnC,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,UAAU,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;QAC7E,OAAO,OAAO,CAAC;IACjB,CAAC;IAEO,GAAG,CAAC,IAAY;QACtB,OAAO,IAAI,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,aAAa,IAAI,EAAE,CAAC,CAAC;IACpD,CAAC;CACF"}
|
package/dist/error.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CaltraApiProblem } from "./types.js";
|
|
2
|
+
/** Preserves Caltra's stable RFC problem fields for application-level recovery decisions. */
|
|
3
|
+
export declare class CaltraApiError extends Error {
|
|
4
|
+
readonly problem: CaltraApiProblem;
|
|
5
|
+
constructor(problem: CaltraApiProblem);
|
|
6
|
+
get code(): string;
|
|
7
|
+
get requestId(): string;
|
|
8
|
+
get retryable(): boolean;
|
|
9
|
+
get status(): number;
|
|
10
|
+
static fromResponse(response: Response): Promise<CaltraApiError>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,6FAA6F;AAC7F,qBAAa,cAAe,SAAQ,KAAK;IAC3B,QAAQ,CAAC,OAAO,EAAE,gBAAgB;gBAAzB,OAAO,EAAE,gBAAgB;IAK9C,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,IAAI,MAAM,IAAI,MAAM,CAEnB;WAEY,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,cAAc,CAAC;CAgBvE"}
|
package/dist/error.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** Preserves Caltra's stable RFC problem fields for application-level recovery decisions. */
|
|
2
|
+
export class CaltraApiError extends Error {
|
|
3
|
+
problem;
|
|
4
|
+
constructor(problem) {
|
|
5
|
+
super(problem.detail);
|
|
6
|
+
this.problem = problem;
|
|
7
|
+
this.name = "CaltraApiError";
|
|
8
|
+
}
|
|
9
|
+
get code() {
|
|
10
|
+
return this.problem.code;
|
|
11
|
+
}
|
|
12
|
+
get requestId() {
|
|
13
|
+
return this.problem.request_id;
|
|
14
|
+
}
|
|
15
|
+
get retryable() {
|
|
16
|
+
return this.problem.retryable;
|
|
17
|
+
}
|
|
18
|
+
get status() {
|
|
19
|
+
return this.problem.status;
|
|
20
|
+
}
|
|
21
|
+
static async fromResponse(response) {
|
|
22
|
+
try {
|
|
23
|
+
const problem = await response.json();
|
|
24
|
+
return new CaltraApiError(problem);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return new CaltraApiError({
|
|
28
|
+
code: "invalid_response",
|
|
29
|
+
detail: `Caltra returned HTTP ${response.status} without a valid problem body.`,
|
|
30
|
+
request_id: response.headers.get("x-request-id") ?? "",
|
|
31
|
+
retryable: response.status >= 500,
|
|
32
|
+
status: response.status,
|
|
33
|
+
title: "Invalid response",
|
|
34
|
+
type: "about:blank",
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAEA,6FAA6F;AAC7F,MAAM,OAAO,cAAe,SAAQ,KAAK;IAClB;IAArB,YAAqB,OAAyB;QAC5C,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QADH,YAAO,GAAP,OAAO,CAAkB;QAE5C,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IAC3B,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;IACjC,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC;IAChC,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;IAC7B,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,QAAkB;QAC1C,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAsB,CAAC;YAC1D,OAAO,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;QACrC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,cAAc,CAAC;gBACxB,IAAI,EAAE,kBAAkB;gBACxB,MAAM,EAAE,wBAAwB,QAAQ,CAAC,MAAM,gCAAgC;gBAC/E,UAAU,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE;gBACtD,SAAS,EAAE,QAAQ,CAAC,MAAM,IAAI,GAAG;gBACjC,MAAM,EAAE,QAAQ,CAAC,MAAM;gBACvB,KAAK,EAAE,kBAAkB;gBACzB,IAAI,EAAE,aAAa;aACpB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CaltraSessionEvent } from "./types.js";
|
|
2
|
+
/** Converts one authenticated fetch response into validated Caltra lifecycle events. */
|
|
3
|
+
export declare class CaltraSessionEventConnection implements AsyncIterable<CaltraSessionEvent> {
|
|
4
|
+
private readonly events;
|
|
5
|
+
private readonly waiters;
|
|
6
|
+
private error;
|
|
7
|
+
private finished;
|
|
8
|
+
private reader?;
|
|
9
|
+
constructor(response: Response);
|
|
10
|
+
[Symbol.asyncIterator](): AsyncIterator<CaltraSessionEvent>;
|
|
11
|
+
close(): Promise<void>;
|
|
12
|
+
private next;
|
|
13
|
+
private read;
|
|
14
|
+
private parse;
|
|
15
|
+
private push;
|
|
16
|
+
private resolveWaiters;
|
|
17
|
+
private rejectWaiters;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=event_connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event_connection.d.ts","sourceRoot":"","sources":["../src/event_connection.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAUrD,wFAAwF;AACxF,qBAAa,4BAA6B,YAAW,aAAa,CAAC,kBAAkB,CAAC;IACpF,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA4B;IACnD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAGhB;IACR,OAAO,CAAC,KAAK,CAAU;IACvB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,MAAM,CAAC,CAA0C;gBAE7C,QAAQ,EAAE,QAAQ;IAM9B,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,kBAAkB,CAAC;IAUrD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAOd,IAAI;YAUJ,IAAI;IAsBlB,OAAO,CAAC,KAAK;IAYb,OAAO,CAAC,IAAI;IAMZ,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,aAAa;CAGtB"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { createParser } from "eventsource-parser";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
const EventDataSchema = z.object({
|
|
4
|
+
message_id: z.string().uuid(),
|
|
5
|
+
session_id: z.string().uuid(),
|
|
6
|
+
turn_id: z.string().uuid(),
|
|
7
|
+
}).strict();
|
|
8
|
+
const DeltaDataSchema = EventDataSchema.extend({ delta: z.string() }).strict();
|
|
9
|
+
/** Converts one authenticated fetch response into validated Caltra lifecycle events. */
|
|
10
|
+
export class CaltraSessionEventConnection {
|
|
11
|
+
events = [];
|
|
12
|
+
waiters = [];
|
|
13
|
+
error;
|
|
14
|
+
finished = false;
|
|
15
|
+
reader;
|
|
16
|
+
constructor(response) {
|
|
17
|
+
if (!response.body)
|
|
18
|
+
throw new Error("Caltra's event response does not contain a body.");
|
|
19
|
+
this.reader = response.body.getReader();
|
|
20
|
+
void this.read();
|
|
21
|
+
}
|
|
22
|
+
[Symbol.asyncIterator]() {
|
|
23
|
+
return {
|
|
24
|
+
next: async () => await this.next(),
|
|
25
|
+
return: async () => {
|
|
26
|
+
await this.close();
|
|
27
|
+
return { done: true, value: undefined };
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
async close() {
|
|
32
|
+
if (this.finished)
|
|
33
|
+
return;
|
|
34
|
+
this.finished = true;
|
|
35
|
+
await this.reader?.cancel();
|
|
36
|
+
this.resolveWaiters();
|
|
37
|
+
}
|
|
38
|
+
async next() {
|
|
39
|
+
const event = this.events.shift();
|
|
40
|
+
if (event)
|
|
41
|
+
return { done: false, value: event };
|
|
42
|
+
if (this.error)
|
|
43
|
+
throw this.error;
|
|
44
|
+
if (this.finished)
|
|
45
|
+
return { done: true, value: undefined };
|
|
46
|
+
return await new Promise((resolve, reject) => {
|
|
47
|
+
this.waiters.push({ reject, resolve });
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
async read() {
|
|
51
|
+
const decoder = new TextDecoder();
|
|
52
|
+
const parser = createParser({
|
|
53
|
+
onEvent: (message) => this.push(this.parse(message)),
|
|
54
|
+
});
|
|
55
|
+
try {
|
|
56
|
+
while (!this.finished) {
|
|
57
|
+
const result = await this.reader.read();
|
|
58
|
+
if (result.done)
|
|
59
|
+
break;
|
|
60
|
+
parser.feed(decoder.decode(result.value, { stream: true }));
|
|
61
|
+
}
|
|
62
|
+
parser.feed(decoder.decode());
|
|
63
|
+
this.finished = true;
|
|
64
|
+
this.resolveWaiters();
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
if (this.finished)
|
|
68
|
+
return;
|
|
69
|
+
this.error = error;
|
|
70
|
+
this.finished = true;
|
|
71
|
+
this.rejectWaiters(error);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
parse(message) {
|
|
75
|
+
const event = message.event;
|
|
76
|
+
const value = JSON.parse(message.data);
|
|
77
|
+
if (event === "message.delta") {
|
|
78
|
+
return { data: DeltaDataSchema.parse(value), event, id: message.id ?? "" };
|
|
79
|
+
}
|
|
80
|
+
if (event === "message.started" || event === "message.completed") {
|
|
81
|
+
return { data: EventDataSchema.parse(value), event, id: message.id ?? "" };
|
|
82
|
+
}
|
|
83
|
+
throw new Error(`Unsupported Caltra session event: ${event ?? "unnamed"}`);
|
|
84
|
+
}
|
|
85
|
+
push(event) {
|
|
86
|
+
const waiter = this.waiters.shift();
|
|
87
|
+
if (waiter)
|
|
88
|
+
waiter.resolve({ done: false, value: event });
|
|
89
|
+
else
|
|
90
|
+
this.events.push(event);
|
|
91
|
+
}
|
|
92
|
+
resolveWaiters() {
|
|
93
|
+
for (const waiter of this.waiters.splice(0))
|
|
94
|
+
waiter.resolve({ done: true, value: undefined });
|
|
95
|
+
}
|
|
96
|
+
rejectWaiters(error) {
|
|
97
|
+
for (const waiter of this.waiters.splice(0))
|
|
98
|
+
waiter.reject(error);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=event_connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event_connection.js","sourceRoot":"","sources":["../src/event_connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA2B,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE;IAC7B,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE;IAC7B,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE;CAC3B,CAAC,CAAC,MAAM,EAAE,CAAC;AAEZ,MAAM,eAAe,GAAG,eAAe,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;AAE/E,wFAAwF;AACxF,MAAM,OAAO,4BAA4B;IACtB,MAAM,GAAyB,EAAE,CAAC;IAClC,OAAO,GAGnB,EAAE,CAAC;IACA,KAAK,CAAU;IACf,QAAQ,GAAG,KAAK,CAAC;IACjB,MAAM,CAA2C;IAEzD,YAAY,QAAkB;QAC5B,IAAI,CAAC,QAAQ,CAAC,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;QACxF,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;QACxC,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC;IACnB,CAAC;IAED,CAAC,MAAM,CAAC,aAAa,CAAC;QACpB,OAAO;YACL,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,IAAI,CA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AE,CAAC;QAC7E,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,qCAAqC,KAAK,IAAI,SAAS,EAAE,CAAC,CAAC;IAC7E,CAAC;IAEO,IAAI,CAAC,KAAyB;QACpC,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACpC,IAAI,MAAM;YAAE,MAAM,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;;YACrD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAEO,cAAc;QACpB,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;YAAE,MAAM,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;IAChG,CAAC;IAEO,aAAa,CAAC,KAAc;QAClC,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;YAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACpE,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { CaltraClient } from "./client.js";
|
|
2
|
+
export { CaltraApiError } from "./error.js";
|
|
3
|
+
export { CaltraSessionEventConnection } from "./event_connection.js";
|
|
4
|
+
export type { CaltraAgent, CaltraApiProblem, CaltraClientOptions, CaltraMessageCompletedEvent, CaltraMessageDeltaEvent, CaltraMessageStartedEvent, CaltraMessageSubmission, CaltraPage, CaltraPageInput, CaltraSession, CaltraSessionEvent, CaltraSessionMessage, CaltraTokenProvider, } from "./types.js";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AACrE,YAAY,EACV,WAAW,EACX,gBAAgB,EAChB,mBAAmB,EACnB,2BAA2B,EAC3B,uBAAuB,EACvB,yBAAyB,EACzB,uBAAuB,EACvB,UAAU,EACV,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export type CaltraTokenProvider = () => Promise<string>;
|
|
2
|
+
export interface CaltraClientOptions {
|
|
3
|
+
apiUrl: string;
|
|
4
|
+
fetch?: typeof fetch;
|
|
5
|
+
tokenInvalidator?: () => Promise<void> | void;
|
|
6
|
+
tokenProvider: CaltraTokenProvider;
|
|
7
|
+
}
|
|
8
|
+
export interface CaltraPageInput {
|
|
9
|
+
cursor?: string;
|
|
10
|
+
limit?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface CaltraPage<T> {
|
|
13
|
+
data: T[];
|
|
14
|
+
next_cursor: string | null;
|
|
15
|
+
}
|
|
16
|
+
export interface CaltraAgent {
|
|
17
|
+
created_at: string;
|
|
18
|
+
description: string | null;
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
}
|
|
22
|
+
export interface CaltraSession {
|
|
23
|
+
agent: {
|
|
24
|
+
id: string;
|
|
25
|
+
name: string;
|
|
26
|
+
};
|
|
27
|
+
created_at: string;
|
|
28
|
+
id: string;
|
|
29
|
+
status: "active" | "closed";
|
|
30
|
+
updated_at: string;
|
|
31
|
+
}
|
|
32
|
+
export interface CaltraSessionMessage {
|
|
33
|
+
created_at: string;
|
|
34
|
+
id: string;
|
|
35
|
+
role: "user" | "assistant";
|
|
36
|
+
status: "streaming" | "completed" | "failed" | "cancelled";
|
|
37
|
+
text: string;
|
|
38
|
+
}
|
|
39
|
+
interface CaltraSessionEventData {
|
|
40
|
+
message_id: string;
|
|
41
|
+
session_id: string;
|
|
42
|
+
turn_id: string;
|
|
43
|
+
}
|
|
44
|
+
export interface CaltraMessageStartedEvent {
|
|
45
|
+
data: CaltraSessionEventData;
|
|
46
|
+
event: "message.started";
|
|
47
|
+
id: string;
|
|
48
|
+
}
|
|
49
|
+
export interface CaltraMessageDeltaEvent {
|
|
50
|
+
data: CaltraSessionEventData & {
|
|
51
|
+
delta: string;
|
|
52
|
+
};
|
|
53
|
+
event: "message.delta";
|
|
54
|
+
id: string;
|
|
55
|
+
}
|
|
56
|
+
export interface CaltraMessageCompletedEvent {
|
|
57
|
+
data: CaltraSessionEventData;
|
|
58
|
+
event: "message.completed";
|
|
59
|
+
id: string;
|
|
60
|
+
}
|
|
61
|
+
export type CaltraSessionEvent = CaltraMessageStartedEvent | CaltraMessageDeltaEvent | CaltraMessageCompletedEvent;
|
|
62
|
+
export interface CaltraMessageSubmission {
|
|
63
|
+
message_id: string;
|
|
64
|
+
turn_id: string;
|
|
65
|
+
}
|
|
66
|
+
export interface CaltraApiProblem {
|
|
67
|
+
code: string;
|
|
68
|
+
detail: string;
|
|
69
|
+
request_id: string;
|
|
70
|
+
retryable: boolean;
|
|
71
|
+
status: number;
|
|
72
|
+
title: string;
|
|
73
|
+
type: string;
|
|
74
|
+
}
|
|
75
|
+
export {};
|
|
76
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
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,sBAAsB;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,sBAAsB,CAAC;IAC7B,KAAK,EAAE,iBAAiB,CAAC;IACzB,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,sBAAsB,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACjD,KAAK,EAAE,eAAe,CAAC;IACvB,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,2BAA2B;IAC1C,IAAI,EAAE,sBAAsB,CAAC;IAC7B,KAAK,EAAE,mBAAmB,CAAC;IAC3B,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,MAAM,kBAAkB,GAC1B,yBAAyB,GACzB,uBAAuB,GACvB,2BAA2B,CAAC;AAEhC,MAAM,WAAW,uBAAuB;IACtC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@caltra/client",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Framework-neutral browser client for the Caltra Client API",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/caltra-dev/caltra-sdk.git",
|
|
10
|
+
"directory": "packages/client"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/caltra-dev/caltra-sdk#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/caltra-dev/caltra-sdk/issues"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc -p tsconfig.json",
|
|
27
|
+
"test": "vitest run tests",
|
|
28
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"eventsource-parser": "4.1.0",
|
|
32
|
+
"zod": "4.4.3"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"typescript": "5.9.3",
|
|
36
|
+
"vitest": "4.1.11"
|
|
37
|
+
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=24.0.0"
|
|
40
|
+
},
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public",
|
|
44
|
+
"registry": "https://registry.npmjs.org"
|
|
45
|
+
}
|
|
46
|
+
}
|