@lambforge/agents 0.0.0-stage → 0.0.2

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 CHANGED
@@ -1,3 +1,89 @@
1
- # Temporary Holding Version
1
+ # @lambforge/agents
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Put your [Lambforge](https://lambforge.com) agents on your own site or API.
4
+ Your server mints a short-lived session for each of your users; the browser
5
+ (or any Node process) chats with the agent and gets the answer as live
6
+ events. Every method returns an RxJS `Observable`.
7
+
8
+ ```sh
9
+ npm install @lambforge/agents rxjs
10
+ ```
11
+
12
+ ## On your server: sessions (and agents)
13
+
14
+ Create a **secret** agent key (`lfk_...`) in the dashboard with the scopes you
15
+ need (`agents:session` to mint sessions, `agents:manage` to manage agents).
16
+ It never leaves your server.
17
+
18
+ ```ts
19
+ import { Lambforge } from '@lambforge/agents';
20
+
21
+ const lf = new Lambforge({ apiKey: process.env.LAMBFORGE_KEY, projectId: '...' });
22
+
23
+ // e.g. GET /agent-token for a signed-in user
24
+ lf.sessions
25
+ .create({ subject: user.id, claims: { companyId: user.companyId } })
26
+ .subscribe(({ token, expiresAt }) => res.json({ token, expiresAt }));
27
+
28
+ lf.agents.list(); // create / get / update / delete / embed (publish)
29
+ ```
30
+
31
+ ## In the browser: chat
32
+
33
+ ```ts
34
+ import { AgentClient } from '@lambforge/agents';
35
+
36
+ const client = new AgentClient({
37
+ getToken: () => fetch('/agent-token').then((r) => r.json()),
38
+ });
39
+
40
+ const chat = client.agent('Support').conversation(); // a new conversation
41
+ chat.send('Which invoices are overdue?').subscribe((event) => {
42
+ if (event.type === 'message' && event.data.role === 'assistant') show(event.data.text);
43
+ if (event.type === 'error') showError(event.data.code); // limit-reached, cap-reached, ...
44
+ });
45
+ ```
46
+
47
+ `send` emits that run's events (your message, `run-started`, the answer,
48
+ then `done` or `error`) and completes. Events arrive in order without
49
+ duplicates; a dropped connection reconnects and catches up. Without a
50
+ WebSocket (`WebSocket: false`, or Node < 22 without the `ws` package) the
51
+ client polls.
52
+
53
+ Other ways to get a session:
54
+
55
+ ```ts
56
+ // the visitor's own sign-in token (an identity provider of your project)
57
+ new AgentClient({ exchange: { projectId, idToken: () => auth.currentUser.getIdToken() } });
58
+
59
+ // anonymous visitors: a publishable key (lfp_...) + a Cloudflare Turnstile token
60
+ new AgentClient({ anonymous: { publishableKey: 'lfp_...', turnstileToken: () => turnstile.getResponse() } });
61
+ ```
62
+
63
+ More: `client.agents()`, `client.conversations()`,
64
+ `client.agent(name).conversation(id).history() / .events() / .abort()`,
65
+ `send(text, { credential })` for `forward` agents (your user's own token
66
+ goes to your MCP server only, never stored).
67
+
68
+ ## On your MCP server: who is asking (`signed` agents)
69
+
70
+ ```ts
71
+ import { verifyAgentAssertion } from '@lambforge/agents/node';
72
+
73
+ verifyAgentAssertion(req.headers.authorization, {
74
+ projectId: '...',
75
+ audience: 'https://your-mcp-url', // optional
76
+ }).subscribe(({ subject, claims, agent }) => ...);
77
+ ```
78
+
79
+ Checks the ES256 signature against
80
+ `https://api.lambforge.com/agents/jwks.json` (cached, refetched for a new
81
+ key), the issuer, the expiry, your project and the audience.
82
+
83
+ ## Errors
84
+
85
+ Failures are `LambforgeError` with a `code`: `limit-reached`,
86
+ `cap-reached`, `agent-unavailable`, `session-expired`,
87
+ `credential-expired`, `aborted`, `internal`, `unauthorized`,
88
+ `bad-request`, `network`. A refused session is renewed once
89
+ automatically; a message is never resent.
@@ -0,0 +1,95 @@
1
+ import { Observable } from 'rxjs';
2
+ import { Endpoint, FetchLike } from './http';
3
+ import { AgentEvent, ConversationDetail, ConversationSummary, EmbedAgent, SessionToken } from './types';
4
+ import { WebSocketConstructor } from './ws';
5
+ /** A value now, later (Promise) or as an Observable. */
6
+ export type Lazy<T> = () => T | Promise<T> | Observable<T>;
7
+ export interface AgentClientOptions {
8
+ /** default https://api.lambforge.com */
9
+ url?: string;
10
+ /** Your backend mints the session (`Lambforge.sessions.create`) and returns it. */
11
+ getToken?: Lazy<SessionToken | string>;
12
+ /** The visitor's own sign-in token -> a session (an identity provider of the project). */
13
+ exchange?: {
14
+ projectId: string;
15
+ idToken: Lazy<string>;
16
+ agents?: string[];
17
+ };
18
+ /** Anonymous visitors: a publishable key (`lfp_`) + a Turnstile token. */
19
+ anonymous?: {
20
+ publishableKey: string;
21
+ turnstileToken: Lazy<string>;
22
+ /** 16-128 of A-Z a-z 0-9 _ - ; default: one per browser (localStorage) */
23
+ deviceId?: string;
24
+ agents?: string[];
25
+ };
26
+ fetch?: FetchLike;
27
+ /** WebSocket implementation (Node < 22: `require('ws')`); `false` = poll */
28
+ WebSocket?: WebSocketConstructor | false;
29
+ /** polling interval without a WebSocket, default 1500 ms */
30
+ pollIntervalMs?: number;
31
+ }
32
+ /**
33
+ * The visitor side, browser or Node: the agents of a session, their
34
+ * conversations and live events. Holds the session token and renews it
35
+ * shortly before it expires (or once when the server says it expired).
36
+ * Never give it a secret key - mint sessions on your server.
37
+ */
38
+ export declare class AgentClient {
39
+ private readonly options;
40
+ readonly endpoint: Endpoint;
41
+ private current;
42
+ private pending$;
43
+ constructor(options: AgentClientOptions);
44
+ /** The current session token (renewed when needed). */
45
+ token$(): Observable<string>;
46
+ /** Forget the session (the next call gets a new one). */
47
+ invalidate(): void;
48
+ private session$;
49
+ /** One operation with the session; a refused session is renewed once. */
50
+ call$<T>(query: string, variables: Record<string, unknown>, field: string): Observable<T>;
51
+ /** The agents this session may use. */
52
+ agents(): Observable<EmbedAgent[]>;
53
+ /** The visitor's conversations (newest first), optionally of one agent. */
54
+ conversations(agent?: string): Observable<ConversationSummary[]>;
55
+ /** A chat with one agent (id or name); `conversationId` continues one. */
56
+ agent(agent: string): {
57
+ conversation: (conversationId?: string) => AgentConversation;
58
+ conversations: () => Observable<ConversationSummary[]>;
59
+ };
60
+ /**
61
+ * Every event of a conversation after `afterSeq`, in order, without
62
+ * duplicates and without gaps: live over the WebSocket (reconnecting with
63
+ * backoff, catching up after each start) or polled without one. Never
64
+ * completes by itself.
65
+ */
66
+ events(conversationId: string, afterSeq?: number): Observable<AgentEvent>;
67
+ private webSocket;
68
+ }
69
+ /** One conversation with one agent. */
70
+ export declare class AgentConversation {
71
+ private readonly client;
72
+ readonly agent: string;
73
+ /** null until the first message creates it */
74
+ id: string | null;
75
+ constructor(client: AgentClient, agent: string,
76
+ /** null until the first message creates it */
77
+ id: string | null);
78
+ /**
79
+ * Send a message; emits the events of THAT run - the stored visitor
80
+ * message, `run-started`, the answer, then `done` or `error` - and
81
+ * completes. A failed send (limits, caps, an unavailable agent) errors
82
+ * instead. Nothing is resent automatically.
83
+ */
84
+ send(text: string, options?: {
85
+ credential?: string;
86
+ }): Observable<AgentEvent>;
87
+ /** Live events from now on (or after `afterSeq`). */
88
+ events(afterSeq?: number): Observable<AgentEvent>;
89
+ /** The stored messages (and `lastSeq` / `answering` to resume). */
90
+ history(): Observable<ConversationDetail>;
91
+ /** Stop the answer in progress. */
92
+ abort(): Observable<boolean>;
93
+ }
94
+ /** One id per browser (localStorage), else a fresh one per client. */
95
+ export declare function deviceId(): string;
package/dist/client.js ADDED
@@ -0,0 +1,295 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AgentConversation = exports.AgentClient = void 0;
4
+ exports.deviceId = deviceId;
5
+ const rxjs_1 = require("rxjs");
6
+ const operators_1 = require("rxjs/operators");
7
+ const documents_1 = require("./documents");
8
+ const errors_1 = require("./errors");
9
+ const http_1 = require("./http");
10
+ const ws_1 = require("./ws");
11
+ const lazy$ = (source) => (0, rxjs_1.defer)(() => {
12
+ const value = source();
13
+ return (0, rxjs_1.isObservable)(value) ? value.pipe((0, operators_1.take)(1)) : (0, rxjs_1.from)(Promise.resolve(value));
14
+ });
15
+ /** Renew this long before the session expires. */
16
+ const RENEW_BEFORE_MS = 60_000;
17
+ const DEVICE_KEY = 'lambforge.agents.device';
18
+ const RECONNECT_MAX_MS = 15_000;
19
+ /**
20
+ * The visitor side, browser or Node: the agents of a session, their
21
+ * conversations and live events. Holds the session token and renews it
22
+ * shortly before it expires (or once when the server says it expired).
23
+ * Never give it a secret key - mint sessions on your server.
24
+ */
25
+ class AgentClient {
26
+ options;
27
+ endpoint;
28
+ current = null;
29
+ pending$ = null;
30
+ constructor(options) {
31
+ this.options = options;
32
+ const sources = [options.getToken, options.exchange, options.anonymous].filter(Boolean).length;
33
+ if (sources !== 1) {
34
+ throw new errors_1.LambforgeError('AgentClient: give exactly one of getToken, exchange or anonymous', 'bad-request');
35
+ }
36
+ if (options.anonymous && !options.anonymous.publishableKey.startsWith('lfp_')) {
37
+ throw new errors_1.LambforgeError('AgentClient: anonymous visitors need a publishable key (lfp_...)', 'bad-request');
38
+ }
39
+ this.endpoint = { url: options.url ?? http_1.DEFAULT_URL, fetch: options.fetch };
40
+ }
41
+ // ------------------------------------------------------------- session
42
+ /** The current session token (renewed when needed). */
43
+ token$() {
44
+ if (this.current && Date.now() < this.current.renewAt) {
45
+ return (0, rxjs_1.of)(this.current.token);
46
+ }
47
+ if (!this.pending$) {
48
+ this.pending$ = this.session$().pipe((0, operators_1.tap)((s) => {
49
+ const expires = s.expiresAt ? Date.parse(s.expiresAt) : NaN;
50
+ this.current = {
51
+ token: s.token,
52
+ renewAt: Number.isFinite(expires)
53
+ ? Math.max(Date.now() + 30_000, expires - RENEW_BEFORE_MS)
54
+ : Date.now() + 50 * 60_000,
55
+ };
56
+ }), (0, operators_1.map)((s) => s.token), (0, operators_1.finalize)(() => (this.pending$ = null)), (0, operators_1.shareReplay)(1));
57
+ }
58
+ return this.pending$;
59
+ }
60
+ /** Forget the session (the next call gets a new one). */
61
+ invalidate() {
62
+ this.current = null;
63
+ }
64
+ session$() {
65
+ const o = this.options;
66
+ if (o.getToken) {
67
+ return lazy$(o.getToken).pipe((0, operators_1.map)((t) => (typeof t === 'string' ? { token: t } : t)));
68
+ }
69
+ if (o.exchange) {
70
+ const { projectId, idToken, agents } = o.exchange;
71
+ return lazy$(idToken).pipe((0, operators_1.switchMap)((token) => (0, http_1.request$)(this.endpoint, null, documents_1.DOCS.exchangeSession, { projectId, token, agents }, 'exchangeAgentSession')));
72
+ }
73
+ const a = o.anonymous;
74
+ return lazy$(a.turnstileToken).pipe((0, operators_1.switchMap)((turnstileToken) => (0, http_1.request$)(this.endpoint, a.publishableKey, documents_1.DOCS.anonymousSession, {
75
+ deviceId: a.deviceId ?? deviceId(),
76
+ turnstileToken,
77
+ agents: a.agents,
78
+ }, 'createAnonymousAgentSession')));
79
+ }
80
+ /** One operation with the session; a refused session is renewed once. */
81
+ call$(query, variables, field) {
82
+ const once = () => this.token$().pipe((0, operators_1.switchMap)((token) => (0, http_1.request$)(this.endpoint, token, query, variables, field)));
83
+ return once().pipe((0, operators_1.catchError)((e) => {
84
+ if (e?.code !== 'session-expired' && e?.code !== 'unauthorized') {
85
+ return (0, rxjs_1.throwError)(() => e);
86
+ }
87
+ this.invalidate();
88
+ return once();
89
+ }));
90
+ }
91
+ // -------------------------------------------------------------- reading
92
+ /** The agents this session may use. */
93
+ agents() {
94
+ return this.call$(documents_1.DOCS.sessionAgents, {}, 'sessionAgents');
95
+ }
96
+ /** The visitor's conversations (newest first), optionally of one agent. */
97
+ conversations(agent) {
98
+ return this.call$(documents_1.DOCS.conversations, { agent }, 'agentConversations');
99
+ }
100
+ /** A chat with one agent (id or name); `conversationId` continues one. */
101
+ agent(agent) {
102
+ return {
103
+ conversation: (conversationId) => new AgentConversation(this, agent, conversationId ?? null),
104
+ conversations: () => this.conversations(agent),
105
+ };
106
+ }
107
+ // --------------------------------------------------------------- events
108
+ /**
109
+ * Every event of a conversation after `afterSeq`, in order, without
110
+ * duplicates and without gaps: live over the WebSocket (reconnecting with
111
+ * backoff, catching up after each start) or polled without one. Never
112
+ * completes by itself.
113
+ */
114
+ events(conversationId, afterSeq = 0) {
115
+ return new rxjs_1.Observable((subscriber) => {
116
+ let last = afterSeq;
117
+ const held = new Map();
118
+ const subs = new rxjs_1.Subscription();
119
+ let catching = false;
120
+ let again = false;
121
+ const flush = () => {
122
+ while (held.has(last + 1)) {
123
+ const e = held.get(last + 1);
124
+ held.delete(last + 1);
125
+ last = e.seq;
126
+ subscriber.next(e);
127
+ }
128
+ };
129
+ const accept = (e) => {
130
+ if (!e || e.seq <= last)
131
+ return;
132
+ held.set(e.seq, e);
133
+ flush();
134
+ if (held.size)
135
+ catchUp(); // a gap: ask the server what is missing
136
+ };
137
+ const catchUp = () => {
138
+ if (catching) {
139
+ again = true;
140
+ return;
141
+ }
142
+ catching = true;
143
+ subs.add(this.call$(documents_1.DOCS.events, { conversationId, afterSeq: last }, 'agentConversationEvents').subscribe({
144
+ next: (list) => {
145
+ list.forEach((e) => held.set(e.seq, e));
146
+ flush();
147
+ // the server has nothing in between: deliver what is held
148
+ if (held.size && !list.length) {
149
+ last = Math.min(...held.keys()) - 1;
150
+ flush();
151
+ }
152
+ },
153
+ error: (e) => {
154
+ catching = false;
155
+ subscriber.error(e);
156
+ },
157
+ complete: () => {
158
+ catching = false;
159
+ if (again) {
160
+ again = false;
161
+ catchUp();
162
+ }
163
+ },
164
+ }));
165
+ };
166
+ const WS = this.webSocket();
167
+ if (!WS) {
168
+ catchUp();
169
+ subs.add((0, rxjs_1.timer)(this.options.pollIntervalMs ?? 1500, this.options.pollIntervalMs ?? 1500).subscribe(() => catchUp()));
170
+ return subs;
171
+ }
172
+ let attempt = 0;
173
+ let renewed = false;
174
+ const connect = () => {
175
+ subs.add(this.token$()
176
+ .pipe((0, operators_1.switchMap)((token) => (0, ws_1.subscription$)({
177
+ url: (0, http_1.subscriptionsUrl)(this.endpoint.url),
178
+ WebSocket: WS,
179
+ connectionParams: { agentSession: token },
180
+ query: documents_1.DOCS.liveEvents,
181
+ variables: { conversationId },
182
+ field: 'agentEvents',
183
+ onStarted: () => {
184
+ attempt = 0;
185
+ renewed = false;
186
+ catchUp();
187
+ },
188
+ })))
189
+ .subscribe({
190
+ next: accept,
191
+ error: (e) => {
192
+ if (e?.code === 'unauthorized' && !renewed) {
193
+ renewed = true;
194
+ this.invalidate();
195
+ connect();
196
+ return;
197
+ }
198
+ if (e?.code !== 'network') {
199
+ subscriber.error(e);
200
+ return;
201
+ }
202
+ const wait = Math.min(RECONNECT_MAX_MS, 1000 * 2 ** attempt++);
203
+ subs.add((0, rxjs_1.timer)(wait * (0.75 + Math.random() / 2)).subscribe(connect));
204
+ },
205
+ complete: () => subscriber.complete(),
206
+ }));
207
+ };
208
+ connect();
209
+ return subs;
210
+ });
211
+ }
212
+ webSocket() {
213
+ if (this.options.WebSocket === false)
214
+ return null;
215
+ return (this.options.WebSocket ??
216
+ (globalThis.WebSocket || null));
217
+ }
218
+ }
219
+ exports.AgentClient = AgentClient;
220
+ /** One conversation with one agent. */
221
+ class AgentConversation {
222
+ client;
223
+ agent;
224
+ id;
225
+ constructor(client, agent,
226
+ /** null until the first message creates it */
227
+ id) {
228
+ this.client = client;
229
+ this.agent = agent;
230
+ this.id = id;
231
+ }
232
+ /**
233
+ * Send a message; emits the events of THAT run - the stored visitor
234
+ * message, `run-started`, the answer, then `done` or `error` - and
235
+ * completes. A failed send (limits, caps, an unavailable agent) errors
236
+ * instead. Nothing is resent automatically.
237
+ */
238
+ send(text, options = {}) {
239
+ return this.client
240
+ .call$(documents_1.DOCS.send, {
241
+ agent: this.agent,
242
+ conversationId: this.id,
243
+ text,
244
+ credential: options.credential,
245
+ }, 'sendAgentMessage')
246
+ .pipe((0, operators_1.tap)((sent) => (this.id = sent.conversationId)), (0, operators_1.switchMap)((sent) =>
247
+ // seq = run-started; seq - 1 = the visitor's message
248
+ this.client.events(sent.conversationId, Math.max(0, sent.seq - 2)).pipe((0, operators_1.takeWhile)((e) => !((e.type === 'done' || e.type === 'error') &&
249
+ e.runId === sent.runId), true))));
250
+ }
251
+ /** Live events from now on (or after `afterSeq`). */
252
+ events(afterSeq) {
253
+ if (!this.id) {
254
+ return (0, rxjs_1.throwError)(() => new errors_1.LambforgeError('No conversation yet - send a message first', 'bad-request'));
255
+ }
256
+ return afterSeq === undefined
257
+ ? this.history().pipe((0, operators_1.switchMap)((c) => this.client.events(this.id, c.lastSeq ?? 0)))
258
+ : this.client.events(this.id, afterSeq);
259
+ }
260
+ /** The stored messages (and `lastSeq` / `answering` to resume). */
261
+ history() {
262
+ if (!this.id) {
263
+ return (0, rxjs_1.throwError)(() => new errors_1.LambforgeError('No conversation yet - send a message first', 'bad-request'));
264
+ }
265
+ return this.client.call$(documents_1.DOCS.conversation, { id: this.id }, 'agentConversation');
266
+ }
267
+ /** Stop the answer in progress. */
268
+ abort() {
269
+ if (!this.id)
270
+ return (0, rxjs_1.of)(false);
271
+ return this.client.call$(documents_1.DOCS.abort, { conversationId: this.id }, 'abortAgentRun');
272
+ }
273
+ }
274
+ exports.AgentConversation = AgentConversation;
275
+ /** One id per browser (localStorage), else a fresh one per client. */
276
+ function deviceId() {
277
+ const storage = globalThis.localStorage;
278
+ try {
279
+ const stored = storage?.getItem(DEVICE_KEY);
280
+ if (stored && /^[A-Za-z0-9_-]{16,128}$/.test(stored))
281
+ return stored;
282
+ }
283
+ catch {
284
+ /* storage blocked */
285
+ }
286
+ const id = globalThis.crypto.randomUUID().replace(/-/g, '');
287
+ try {
288
+ storage?.setItem(DEVICE_KEY, id);
289
+ }
290
+ catch {
291
+ /* storage blocked */
292
+ }
293
+ return id;
294
+ }
295
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AA0bA,4BAeC;AAzcD,+BASc;AACd,8CASwB;AAExB,2CAAmC;AACnC,qCAA0C;AAC1C,iCAMgB;AAShB,6BAA2D;AAK3D,MAAM,KAAK,GAAG,CAAI,MAAe,EAAiB,EAAE,CAClD,IAAA,YAAK,EAAC,GAAG,EAAE;IACT,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC;IACvB,OAAO,IAAA,mBAAY,EAAC,KAAK,CAAC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C,CAAC;QAC/B,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CACtB,gBAAI,CAAC,KAAK,EACV,EAAE,cAAc,EAAE,IAAI,CAAC,EAAE,EAAE,EAC3B,eAAe,CAChB,CAAC;IACJ,CAAC;CACF;AAjFD,8CAiFC;AAED,sEAAsE;AACtE,SAAgB,QAAQ;IACtB,MAAM,OAAO,GAAI,UAA6C,CAAC,YAAY,CAAC;IAC5E,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;QAC5C,IAAI,MAAM,IAAI,yBAAyB,CAAC,IAAI,CAAC,MAAM,CAAC;YAAE,OAAO,MAAM,CAAC;IACtE,CAAC;IAAC,MAAM,CAAC;QACP,qBAAqB;IACvB,CAAC;IACD,MAAM,EAAE,GAAG,UAAU,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAC5D,IAAI,CAAC;QACH,OAAO,EAAE,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IACnC,CAAC;IAAC,MAAM,CAAC;QACP,qBAAqB;IACvB,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC"}
@@ -0,0 +1,19 @@
1
+ /** The GraphQL operations this package sends (one place to keep in sync). */
2
+ export declare const DOCS: {
3
+ listAgents: string;
4
+ getAgent: string;
5
+ createAgent: string;
6
+ updateAgent: string;
7
+ deleteAgent: string;
8
+ updateEmbed: string;
9
+ createSession: string;
10
+ exchangeSession: string;
11
+ anonymousSession: string;
12
+ sessionAgents: string;
13
+ conversations: string;
14
+ conversation: string;
15
+ events: string;
16
+ send: string;
17
+ abort: string;
18
+ liveEvents: string;
19
+ };
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ /** The GraphQL operations this package sends (one place to keep in sync). */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.DOCS = void 0;
5
+ const AGENT = `id name type description instructions tools isActive modelName mcpLambdaId mcpLambdaName createdAt updatedAt
6
+ embed { published identity allowedOrigins welcome suggestions showToolDetails maxMessagesPerConversation retentionDays publishedAt }`;
7
+ const EMBED_AGENT = 'id name description welcome suggestions';
8
+ const SESSION = `token expiresAt agents { ${EMBED_AGENT} }`;
9
+ const SUMMARY = 'id agentId title messageCount lastSeq answering lastMessageAt createdAt';
10
+ const MESSAGE = 'id role text toolCalls { name status } createdAt';
11
+ const EVENT = 'conversationId seq type runId data createdAt';
12
+ exports.DOCS = {
13
+ listAgents: `query ($projectId: String!) { listProjectAgents(projectId: $projectId) { ${AGENT} } }`,
14
+ getAgent: `query ($id: String!) { getProjectAgent(id: $id) { ${AGENT} } }`,
15
+ createAgent: `mutation ($projectId: String!, $payload: CreateProjectAgentInput!) { createProjectAgent(projectId: $projectId, payload: $payload) { ${AGENT} } }`,
16
+ updateAgent: `mutation ($id: String!, $payload: UpdateProjectAgentInput!) { updateProjectAgent(id: $id, payload: $payload) { ${AGENT} } }`,
17
+ deleteAgent: `mutation ($id: String!) { deleteProjectAgent(id: $id) }`,
18
+ updateEmbed: `mutation ($agentId: String!, $embed: AgentEmbedInput!) { updateAgentEmbed(agentId: $agentId, embed: $embed) { ${AGENT} } }`,
19
+ createSession: `mutation ($subject: String!, $agents: [String], $claims: JSON, $ttlSeconds: Int, $origin: String) { createAgentSession(subject: $subject, agents: $agents, claims: $claims, ttlSeconds: $ttlSeconds, origin: $origin) { ${SESSION} } }`,
20
+ exchangeSession: `mutation ($projectId: String!, $token: String!, $agents: [String]) { exchangeAgentSession(projectId: $projectId, token: $token, agents: $agents) { ${SESSION} } }`,
21
+ anonymousSession: `mutation ($deviceId: String!, $turnstileToken: String!, $agents: [String]) { createAnonymousAgentSession(deviceId: $deviceId, turnstileToken: $turnstileToken, agents: $agents) { ${SESSION} } }`,
22
+ sessionAgents: `query { sessionAgents { ${EMBED_AGENT} } }`,
23
+ conversations: `query ($agent: String) { agentConversations(agent: $agent) { ${SUMMARY} } }`,
24
+ conversation: `query ($id: String!) { agentConversation(id: $id) { ${SUMMARY} messages { ${MESSAGE} } } }`,
25
+ events: `query ($conversationId: String!, $afterSeq: Int) { agentConversationEvents(conversationId: $conversationId, afterSeq: $afterSeq) { ${EVENT} } }`,
26
+ send: `mutation ($agent: String!, $conversationId: String, $text: String!, $credential: String) { sendAgentMessage(agent: $agent, conversationId: $conversationId, text: $text, credential: $credential) { conversationId runId seq } }`,
27
+ abort: `mutation ($conversationId: String!) { abortAgentRun(conversationId: $conversationId) }`,
28
+ liveEvents: `subscription ($conversationId: String!) { agentEvents(conversationId: $conversationId) { ${EVENT} } }`,
29
+ };
30
+ //# sourceMappingURL=documents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"documents.js","sourceRoot":"","sources":["../src/documents.ts"],"names":[],"mappings":";AAAA,6EAA6E;;;AAE7E,MAAM,KAAK,GAAG;uIACyH,CAAC;AACxI,MAAM,WAAW,GAAG,yCAAyC,CAAC;AAC9D,MAAM,OAAO,GAAG,4BAA4B,WAAW,IAAI,CAAC;AAC5D,MAAM,OAAO,GACX,yEAAyE,CAAC;AAC5E,MAAM,OAAO,GAAG,kDAAkD,CAAC;AACnE,MAAM,KAAK,GAAG,8CAA8C,CAAC;AAEhD,QAAA,IAAI,GAAG;IAClB,UAAU,EAAE,4EAA4E,KAAK,MAAM;IACnG,QAAQ,EAAE,qDAAqD,KAAK,MAAM;IAC1E,WAAW,EAAE,uIAAuI,KAAK,MAAM;IAC/J,WAAW,EAAE,kHAAkH,KAAK,MAAM;IAC1I,WAAW,EAAE,yDAAyD;IACtE,WAAW,EAAE,iHAAiH,KAAK,MAAM;IACzI,aAAa,EAAE,2NAA2N,OAAO,MAAM;IACvP,eAAe,EAAE,sJAAsJ,OAAO,MAAM;IACpL,gBAAgB,EAAE,qLAAqL,OAAO,MAAM;IACpN,aAAa,EAAE,2BAA2B,WAAW,MAAM;IAC3D,aAAa,EAAE,gEAAgE,OAAO,MAAM;IAC5F,YAAY,EAAE,uDAAuD,OAAO,eAAe,OAAO,QAAQ;IAC1G,MAAM,EAAE,sIAAsI,KAAK,MAAM;IACzJ,IAAI,EAAE,kOAAkO;IACxO,KAAK,EAAE,wFAAwF;IAC/F,UAAU,EAAE,4FAA4F,KAAK,MAAM;CACpH,CAAC"}
@@ -0,0 +1,16 @@
1
+ /** Why a call or a run was refused - stable codes a UI can switch on. */
2
+ export type AgentErrorCode = 'limit-reached' | 'cap-reached' | 'agent-unavailable' | 'session-expired' | 'credential-expired' | 'aborted' | 'internal' | 'unauthorized' | 'bad-request' | 'network';
3
+ export declare class LambforgeError extends Error {
4
+ readonly code: AgentErrorCode;
5
+ readonly status?: number | undefined;
6
+ constructor(message: string, code: AgentErrorCode, status?: number | undefined);
7
+ }
8
+ interface GraphQLErrorLike {
9
+ message?: string;
10
+ extensions?: {
11
+ code?: string;
12
+ };
13
+ }
14
+ /** The first GraphQL error as a LambforgeError with a usable code. */
15
+ export declare function errorFromGraphQL(errors: GraphQLErrorLike[], status?: number): LambforgeError;
16
+ export {};
package/dist/errors.js ADDED
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LambforgeError = void 0;
4
+ exports.errorFromGraphQL = errorFromGraphQL;
5
+ const SERVER_CODES = [
6
+ 'limit-reached',
7
+ 'cap-reached',
8
+ 'agent-unavailable',
9
+ 'session-expired',
10
+ 'credential-expired',
11
+ 'aborted',
12
+ 'internal',
13
+ ];
14
+ class LambforgeError extends Error {
15
+ code;
16
+ status;
17
+ constructor(message, code, status) {
18
+ super(message);
19
+ this.code = code;
20
+ this.status = status;
21
+ this.name = 'LambforgeError';
22
+ }
23
+ }
24
+ exports.LambforgeError = LambforgeError;
25
+ /** The first GraphQL error as a LambforgeError with a usable code. */
26
+ function errorFromGraphQL(errors, status) {
27
+ const first = errors?.[0] ?? {};
28
+ const message = String(first.message ?? 'Request failed');
29
+ const prefix = message.match(/^([a-z-]+):/)?.[1];
30
+ if (prefix && SERVER_CODES.includes(prefix)) {
31
+ return new LambforgeError(message, prefix, status);
32
+ }
33
+ if (message === 'session-expired') {
34
+ return new LambforgeError(message, 'session-expired', status);
35
+ }
36
+ if (first.extensions?.code === 'UNAUTHENTICATED' ||
37
+ /not authorized|unauthorized|invalid sign-in token/i.test(message)) {
38
+ return new LambforgeError(message, 'unauthorized', status);
39
+ }
40
+ return new LambforgeError(message, 'bad-request', status);
41
+ }
42
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAwCA,4CAoBC;AA/CD,MAAM,YAAY,GAAqB;IACrC,eAAe;IACf,aAAa;IACb,mBAAmB;IACnB,iBAAiB;IACjB,oBAAoB;IACpB,SAAS;IACT,UAAU;CACX,CAAC;AAEF,MAAa,cAAe,SAAQ,KAAK;IAG5B;IACA;IAHX,YACE,OAAe,EACN,IAAoB,EACpB,MAAe;QAExB,KAAK,CAAC,OAAO,CAAC,CAAC;QAHN,SAAI,GAAJ,IAAI,CAAgB;QACpB,WAAM,GAAN,MAAM,CAAS;QAGxB,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AATD,wCASC;AAOD,sEAAsE;AACtE,SAAgB,gBAAgB,CAC9B,MAA0B,EAC1B,MAAe;IAEf,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAChC,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,IAAI,gBAAgB,CAAC,CAAC;IAC1D,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC,CAA+B,CAAC;IAC/E,IAAI,MAAM,IAAI,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5C,OAAO,IAAI,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACrD,CAAC;IACD,IAAI,OAAO,KAAK,iBAAiB,EAAE,CAAC;QAClC,OAAO,IAAI,cAAc,CAAC,OAAO,EAAE,iBAAiB,EAAE,MAAM,CAAC,CAAC;IAChE,CAAC;IACD,IACE,KAAK,CAAC,UAAU,EAAE,IAAI,KAAK,iBAAiB;QAC5C,oDAAoD,CAAC,IAAI,CAAC,OAAO,CAAC,EAClE,CAAC;QACD,OAAO,IAAI,cAAc,CAAC,OAAO,EAAE,cAAc,EAAE,MAAM,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,IAAI,cAAc,CAAC,OAAO,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC;AAC5D,CAAC"}
package/dist/http.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ import { Observable } from 'rxjs';
2
+ export type FetchLike = (input: string, init: {
3
+ method: string;
4
+ headers: Record<string, string>;
5
+ body: string;
6
+ signal: AbortSignal;
7
+ }) => Promise<{
8
+ status: number;
9
+ json(): Promise<unknown>;
10
+ }>;
11
+ export interface Endpoint {
12
+ /** `https://api.lambforge.com` (GraphQL at /graphql, WebSocket at /subscriptions) */
13
+ url: string;
14
+ fetch?: FetchLike;
15
+ }
16
+ export declare const DEFAULT_URL = "https://api.lambforge.com";
17
+ export declare const graphqlUrl: (url: string) => string;
18
+ export declare const subscriptionsUrl: (url: string) => string;
19
+ /**
20
+ * One GraphQL operation over HTTP. `token` goes RAW in `authorization`
21
+ * (an `lfk_` / `lfp_` key or a session token - never `Bearer `). Emits the
22
+ * value of `field`; cancelling aborts the request.
23
+ */
24
+ export declare function request$<T>(endpoint: Endpoint, token: string | null, query: string, variables: Record<string, unknown>, field: string): Observable<T>;