@lambforge/agents 0.0.0-stage → 0.0.3
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 +91 -2
- package/dist/client.d.ts +103 -0
- package/dist/client.js +303 -0
- package/dist/client.js.map +1 -0
- package/dist/documents.d.ts +19 -0
- package/dist/documents.js +30 -0
- package/dist/documents.js.map +1 -0
- package/dist/errors.d.ts +16 -0
- package/dist/errors.js +42 -0
- package/dist/errors.js.map +1 -0
- package/dist/http.d.ts +24 -0
- package/dist/http.js +60 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/lambforge.d.ts +38 -0
- package/dist/lambforge.js +46 -0
- package/dist/lambforge.js.map +1 -0
- package/dist/node.d.ts +33 -0
- package/dist/node.js +110 -0
- package/dist/node.js.map +1 -0
- package/dist/types.d.ts +128 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/ws.d.ts +44 -0
- package/dist/ws.js +118 -0
- package/dist/ws.js.map +1 -0
- package/package.json +45 -4
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>;
|
package/dist/http.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.subscriptionsUrl = exports.graphqlUrl = exports.DEFAULT_URL = void 0;
|
|
4
|
+
exports.request$ = request$;
|
|
5
|
+
const rxjs_1 = require("rxjs");
|
|
6
|
+
const errors_1 = require("./errors");
|
|
7
|
+
exports.DEFAULT_URL = 'https://api.lambforge.com';
|
|
8
|
+
const graphqlUrl = (url) => `${url.replace(/\/+$/, '')}/graphql`;
|
|
9
|
+
exports.graphqlUrl = graphqlUrl;
|
|
10
|
+
const subscriptionsUrl = (url) => `${url.replace(/\/+$/, '').replace(/^http/, 'ws')}/subscriptions`;
|
|
11
|
+
exports.subscriptionsUrl = subscriptionsUrl;
|
|
12
|
+
/**
|
|
13
|
+
* One GraphQL operation over HTTP. `token` goes RAW in `authorization`
|
|
14
|
+
* (an `lfk_` / `lfp_` key or a session token - never `Bearer `). Emits the
|
|
15
|
+
* value of `field`; cancelling aborts the request.
|
|
16
|
+
*/
|
|
17
|
+
function request$(endpoint, token, query, variables, field) {
|
|
18
|
+
return new rxjs_1.Observable((subscriber) => {
|
|
19
|
+
const controller = new AbortController();
|
|
20
|
+
const fetchImpl = (endpoint.fetch ?? globalThis.fetch);
|
|
21
|
+
if (!fetchImpl) {
|
|
22
|
+
subscriber.error(new errors_1.LambforgeError('No fetch available', 'network'));
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
fetchImpl((0, exports.graphqlUrl)(endpoint.url), {
|
|
26
|
+
method: 'POST',
|
|
27
|
+
headers: {
|
|
28
|
+
'content-type': 'application/json',
|
|
29
|
+
...(token ? { authorization: token } : {}),
|
|
30
|
+
},
|
|
31
|
+
body: JSON.stringify({ query, variables }),
|
|
32
|
+
signal: controller.signal,
|
|
33
|
+
})
|
|
34
|
+
.then(async (res) => {
|
|
35
|
+
let body;
|
|
36
|
+
try {
|
|
37
|
+
body = (await res.json());
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
throw new errors_1.LambforgeError(`Lambforge answered ${res.status}`, res.status === 401 ? 'unauthorized' : 'network', res.status);
|
|
41
|
+
}
|
|
42
|
+
if (body.errors?.length)
|
|
43
|
+
throw (0, errors_1.errorFromGraphQL)(body.errors, res.status);
|
|
44
|
+
if (!body.data || !(field in body.data)) {
|
|
45
|
+
throw new errors_1.LambforgeError(`Lambforge answered ${res.status} without ${field}`, 'network', res.status);
|
|
46
|
+
}
|
|
47
|
+
subscriber.next(body.data[field]);
|
|
48
|
+
subscriber.complete();
|
|
49
|
+
})
|
|
50
|
+
.catch((e) => {
|
|
51
|
+
if (controller.signal.aborted)
|
|
52
|
+
return;
|
|
53
|
+
subscriber.error(e instanceof errors_1.LambforgeError
|
|
54
|
+
? e
|
|
55
|
+
: new errors_1.LambforgeError(String(e?.message ?? e), 'network'));
|
|
56
|
+
});
|
|
57
|
+
return () => controller.abort();
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=http.js.map
|
package/dist/http.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":";;;AAiCA,4BAuDC;AAxFD,+BAAkC;AAElC,qCAA4D;AAkB/C,QAAA,WAAW,GAAG,2BAA2B,CAAC;AAEhD,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,EAAE,CACxC,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE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|
|
2
|
+
export { AgentErrorCode, LambforgeError } from './errors';
|
|
3
|
+
export { DEFAULT_URL, FetchLike } from './http';
|
|
4
|
+
export { Lambforge, LambforgeOptions } from './lambforge';
|
|
5
|
+
export * from './types';
|
|
6
|
+
export { WebSocketConstructor, WebSocketLike, WS_PROTOCOLS } from './ws';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.WS_PROTOCOLS = exports.Lambforge = exports.DEFAULT_URL = exports.LambforgeError = exports.deviceId = exports.AgentConversation = exports.AgentClient = void 0;
|
|
18
|
+
var client_1 = require("./client");
|
|
19
|
+
Object.defineProperty(exports, "AgentClient", { enumerable: true, get: function () { return client_1.AgentClient; } });
|
|
20
|
+
Object.defineProperty(exports, "AgentConversation", { enumerable: true, get: function () { return client_1.AgentConversation; } });
|
|
21
|
+
Object.defineProperty(exports, "deviceId", { enumerable: true, get: function () { return client_1.deviceId; } });
|
|
22
|
+
var errors_1 = require("./errors");
|
|
23
|
+
Object.defineProperty(exports, "LambforgeError", { enumerable: true, get: function () { return errors_1.LambforgeError; } });
|
|
24
|
+
var http_1 = require("./http");
|
|
25
|
+
Object.defineProperty(exports, "DEFAULT_URL", { enumerable: true, get: function () { return http_1.DEFAULT_URL; } });
|
|
26
|
+
var lambforge_1 = require("./lambforge");
|
|
27
|
+
Object.defineProperty(exports, "Lambforge", { enumerable: true, get: function () { return lambforge_1.Lambforge; } });
|
|
28
|
+
__exportStar(require("./types"), exports);
|
|
29
|
+
var ws_1 = require("./ws");
|
|
30
|
+
Object.defineProperty(exports, "WS_PROTOCOLS", { enumerable: true, get: function () { return ws_1.WS_PROTOCOLS; } });
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mCAA8F;AAArF,qGAAA,WAAW,OAAA;AAAsB,2GAAA,iBAAiB,OAAA;AAAE,kGAAA,QAAQ,OAAA;AACrE,mCAA0D;AAAjC,wGAAA,cAAc,OAAA;AACvC,+BAAgD;AAAvC,mGAAA,WAAW,OAAA;AACpB,yCAA0D;AAAjD,sGAAA,SAAS,OAAA;AAClB,0CAAwB;AACxB,2BAAyE;AAA3B,kGAAA,YAAY,OAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { FetchLike } from './http';
|
|
3
|
+
import { AgentEmbedSettings, CreateAgentInput, CreateSessionInput, ProjectAgent, SessionToken, UpdateAgentInput } from './types';
|
|
4
|
+
export interface LambforgeOptions {
|
|
5
|
+
/** a secret agent key (`lfk_...`) - server side only */
|
|
6
|
+
apiKey: string;
|
|
7
|
+
/** the project the key belongs to */
|
|
8
|
+
projectId: string;
|
|
9
|
+
/** default https://api.lambforge.com */
|
|
10
|
+
url?: string;
|
|
11
|
+
fetch?: FetchLike;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Server side: manage the project's agents and mint visitor sessions with a
|
|
15
|
+
* secret agent key. The key needs the scopes it uses (`agents:manage`,
|
|
16
|
+
* `agents:session`) - the dashboard sets them.
|
|
17
|
+
*/
|
|
18
|
+
export declare class Lambforge {
|
|
19
|
+
private readonly endpoint;
|
|
20
|
+
private readonly apiKey;
|
|
21
|
+
readonly projectId: string;
|
|
22
|
+
constructor(options: LambforgeOptions);
|
|
23
|
+
private call$;
|
|
24
|
+
readonly agents: {
|
|
25
|
+
list: () => Observable<ProjectAgent[]>;
|
|
26
|
+
get: (id: string) => Observable<ProjectAgent>;
|
|
27
|
+
create: (input: CreateAgentInput) => Observable<ProjectAgent>;
|
|
28
|
+
/** a key may change instructions, tools, description and isActive */
|
|
29
|
+
update: (id: string, input: UpdateAgentInput) => Observable<ProjectAgent>;
|
|
30
|
+
delete: (id: string) => Observable<boolean>;
|
|
31
|
+
/** publish / unpublish and the visitor settings */
|
|
32
|
+
embed: (id: string, embed: AgentEmbedSettings) => Observable<ProjectAgent>;
|
|
33
|
+
};
|
|
34
|
+
readonly sessions: {
|
|
35
|
+
/** A session for one of your users - hand `token` to the browser. */
|
|
36
|
+
create: (input: CreateSessionInput) => Observable<SessionToken>;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Lambforge = void 0;
|
|
4
|
+
const documents_1 = require("./documents");
|
|
5
|
+
const errors_1 = require("./errors");
|
|
6
|
+
const http_1 = require("./http");
|
|
7
|
+
/**
|
|
8
|
+
* Server side: manage the project's agents and mint visitor sessions with a
|
|
9
|
+
* secret agent key. The key needs the scopes it uses (`agents:manage`,
|
|
10
|
+
* `agents:session`) - the dashboard sets them.
|
|
11
|
+
*/
|
|
12
|
+
class Lambforge {
|
|
13
|
+
endpoint;
|
|
14
|
+
apiKey;
|
|
15
|
+
projectId;
|
|
16
|
+
constructor(options) {
|
|
17
|
+
if (!options?.apiKey?.startsWith('lfk_')) {
|
|
18
|
+
throw new errors_1.LambforgeError('Lambforge: apiKey must be a secret agent key (lfk_...)', 'bad-request');
|
|
19
|
+
}
|
|
20
|
+
if (typeof globalThis.document !== 'undefined') {
|
|
21
|
+
throw new errors_1.LambforgeError('Lambforge: a secret key must never reach a browser - mint sessions on your server and use AgentClient here', 'bad-request');
|
|
22
|
+
}
|
|
23
|
+
this.apiKey = options.apiKey;
|
|
24
|
+
this.projectId = options.projectId;
|
|
25
|
+
this.endpoint = { url: options.url ?? http_1.DEFAULT_URL, fetch: options.fetch };
|
|
26
|
+
}
|
|
27
|
+
call$(query, variables, field) {
|
|
28
|
+
return (0, http_1.request$)(this.endpoint, this.apiKey, query, variables, field);
|
|
29
|
+
}
|
|
30
|
+
agents = {
|
|
31
|
+
list: () => this.call$(documents_1.DOCS.listAgents, { projectId: this.projectId }, 'listProjectAgents'),
|
|
32
|
+
get: (id) => this.call$(documents_1.DOCS.getAgent, { id }, 'getProjectAgent'),
|
|
33
|
+
create: (input) => this.call$(documents_1.DOCS.createAgent, { projectId: this.projectId, payload: input }, 'createProjectAgent'),
|
|
34
|
+
/** a key may change instructions, tools, description and isActive */
|
|
35
|
+
update: (id, input) => this.call$(documents_1.DOCS.updateAgent, { id, payload: input }, 'updateProjectAgent'),
|
|
36
|
+
delete: (id) => this.call$(documents_1.DOCS.deleteAgent, { id }, 'deleteProjectAgent'),
|
|
37
|
+
/** publish / unpublish and the visitor settings */
|
|
38
|
+
embed: (id, embed) => this.call$(documents_1.DOCS.updateEmbed, { agentId: id, embed }, 'updateAgentEmbed'),
|
|
39
|
+
};
|
|
40
|
+
sessions = {
|
|
41
|
+
/** A session for one of your users - hand `token` to the browser. */
|
|
42
|
+
create: (input) => this.call$(documents_1.DOCS.createSession, { ...input }, 'createAgentSession'),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
exports.Lambforge = Lambforge;
|
|
46
|
+
//# sourceMappingURL=lambforge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I,CAAC,QAAQ,EAAE,EAAE,EAAE,EAAE,EAAE,iBAAiB,CAAC;QACtD,MAAM,EAAE,CAAC,KAAuB,EAA4B,EAAE,CAC5D,IAAI,CAAC,KAAK,CACR,gBAAI,CAAC,WAAW,EAChB,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,EAC7C,oBAAoB,CACrB;QACH,qEAAqE;QACrE,MAAM,EAAE,CAAC,EAAU,EAAE,KAAuB,EAA4B,EAAE,CACxE,IAAI,CAAC,KAAK,CAAC,gBAAI,CAAC,WAAW,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,oBAAoB,CAAC;QAC5E,MAAM,EAAE,CAAC,EAAU,EAAuB,EAAE,CAC1C,IAAI,CAAC,KAAK,CAAC,gBAAI,CAAC,WAAW,EAAE,EAAE,EAAE,EAAE,EAAE,oBAAoB,CAAC;QAC5D,mDAAmD;QACnD,KAAK,EAAE,CAAC,EAAU,EAAE,KAAyB,EAA4B,EAAE,CACzE,IAAI,CAAC,KAAK,CAAC,gBAAI,CAAC,WAAW,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,kBAAkB,CAAC;KAC3E,CAAC;IAEO,QAAQ,GAAG;QAClB,qEAAqE;QACrE,MAAM,EAAE,CAAC,KAAyB,EAA4B,EAAE,CAC9D,IAAI,CAAC,KAAK,CAAC,gBAAI,CAAC,aAAa,EAAE,EAAE,GAAG,KAAK,EAAE,EAAE,oBAAoB,CAAC;KACrE,CAAC;CACH;AA3DD,8BA2DC"}
|
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
/**
|
|
3
|
+
* Node only (`@lambforge/agents/node`): check the identity Lambforge sends
|
|
4
|
+
* to your MCP server for `signed` agents - `Authorization: Bearer <JWT>`,
|
|
5
|
+
* ES256, signed with a key published at <url>/agents/jwks.json.
|
|
6
|
+
*/
|
|
7
|
+
export interface AgentAssertion {
|
|
8
|
+
/** your visitor's id (`anon:<device>` for anonymous visitors) */
|
|
9
|
+
subject: string;
|
|
10
|
+
projectId: string;
|
|
11
|
+
agent: {
|
|
12
|
+
id: string;
|
|
13
|
+
name: string;
|
|
14
|
+
};
|
|
15
|
+
conversationId: string;
|
|
16
|
+
anonymous: boolean;
|
|
17
|
+
/** the claims your server put on the session */
|
|
18
|
+
claims: Record<string, unknown>;
|
|
19
|
+
expiresAt: Date;
|
|
20
|
+
}
|
|
21
|
+
export interface VerifyOptions {
|
|
22
|
+
/** your project's id - assertions for other projects are refused */
|
|
23
|
+
projectId: string;
|
|
24
|
+
/** your MCP server's URL as Lambforge calls it (checked when given) */
|
|
25
|
+
audience?: string;
|
|
26
|
+
/** default https://api.lambforge.com/agents/jwks.json */
|
|
27
|
+
jwksUrl?: string;
|
|
28
|
+
/** seconds of clock skew allowed, default 30 */
|
|
29
|
+
clockTolerance?: number;
|
|
30
|
+
}
|
|
31
|
+
/** Verifies an assertion (with or without `Bearer `); errors `unauthorized`. */
|
|
32
|
+
export declare function verifyAgentAssertion(authorization: string, options: VerifyOptions): Observable<AgentAssertion>;
|
|
33
|
+
export * from './index';
|
package/dist/node.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.verifyAgentAssertion = verifyAgentAssertion;
|
|
18
|
+
const node_crypto_1 = require("node:crypto");
|
|
19
|
+
const rxjs_1 = require("rxjs");
|
|
20
|
+
const operators_1 = require("rxjs/operators");
|
|
21
|
+
const errors_1 = require("./errors");
|
|
22
|
+
const http_1 = require("./http");
|
|
23
|
+
const JWKS_TTL_MS = 10 * 60_000;
|
|
24
|
+
const jwksCache = new Map();
|
|
25
|
+
const b64json = (part) => JSON.parse(Buffer.from(part, 'base64url').toString('utf8'));
|
|
26
|
+
function jwks$(url, fresh) {
|
|
27
|
+
const cached = jwksCache.get(url);
|
|
28
|
+
if (!fresh && cached && Date.now() - cached.at < JWKS_TTL_MS) {
|
|
29
|
+
return (0, rxjs_1.of)(cached.keys);
|
|
30
|
+
}
|
|
31
|
+
return (0, rxjs_1.defer)(() => (0, rxjs_1.from)(fetch(url))).pipe((0, operators_1.switchMap)((res) => {
|
|
32
|
+
if (res.status !== 200) {
|
|
33
|
+
throw new errors_1.LambforgeError(`JWKS answered ${res.status}`, 'network');
|
|
34
|
+
}
|
|
35
|
+
return (0, rxjs_1.from)(res.json());
|
|
36
|
+
}), (0, operators_1.map)((body) => {
|
|
37
|
+
const keys = (body.keys ?? []).filter((k) => !k.use || k.use === 'sig');
|
|
38
|
+
jwksCache.set(url, { at: Date.now(), keys });
|
|
39
|
+
return keys;
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
const keyOf = (keys, kid) => {
|
|
43
|
+
const jwk = kid ? keys.find((k) => k.kid === kid) : keys.length === 1 ? keys[0] : null;
|
|
44
|
+
return jwk ? (0, node_crypto_1.createPublicKey)({ key: jwk, format: 'jwk' }) : null;
|
|
45
|
+
};
|
|
46
|
+
/** Verifies an assertion (with or without `Bearer `); errors `unauthorized`. */
|
|
47
|
+
function verifyAgentAssertion(authorization, options) {
|
|
48
|
+
const refuse = (why) => (0, rxjs_1.throwError)(() => new errors_1.LambforgeError(`agent-assertion: ${why}`, 'unauthorized'));
|
|
49
|
+
const token = String(authorization ?? '').replace(/^Bearer\s+/i, '').trim();
|
|
50
|
+
const parts = token.split('.');
|
|
51
|
+
if (parts.length !== 3)
|
|
52
|
+
return refuse('not a JWT');
|
|
53
|
+
let header;
|
|
54
|
+
let payload;
|
|
55
|
+
try {
|
|
56
|
+
header = b64json(parts[0]);
|
|
57
|
+
payload = b64json(parts[1]);
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return refuse('not a JWT');
|
|
61
|
+
}
|
|
62
|
+
if (header.alg !== 'ES256')
|
|
63
|
+
return refuse('unexpected algorithm');
|
|
64
|
+
const url = options.jwksUrl ?? `${http_1.DEFAULT_URL}/agents/jwks.json`;
|
|
65
|
+
const signed = Buffer.from(`${parts[0]}.${parts[1]}`);
|
|
66
|
+
const signature = Buffer.from(parts[2], 'base64url');
|
|
67
|
+
return jwks$(url, false).pipe(
|
|
68
|
+
// a key we have not seen yet: the keys may have rotated - fetch once more
|
|
69
|
+
(0, operators_1.switchMap)((keys) => keyOf(keys, header.kid)
|
|
70
|
+
? (0, rxjs_1.of)(keys)
|
|
71
|
+
: jwks$(url, true)), (0, operators_1.switchMap)((keys) => {
|
|
72
|
+
const key = keyOf(keys, header.kid);
|
|
73
|
+
if (!key)
|
|
74
|
+
return refuse('unknown signing key');
|
|
75
|
+
const ok = (0, node_crypto_1.verify)('sha256', signed, { key, dsaEncoding: 'ieee-p1363' }, signature);
|
|
76
|
+
if (!ok)
|
|
77
|
+
return refuse('bad signature');
|
|
78
|
+
const now = Math.floor(Date.now() / 1000);
|
|
79
|
+
const skew = options.clockTolerance ?? 30;
|
|
80
|
+
if (payload.iss !== 'lambforge')
|
|
81
|
+
return refuse('wrong issuer');
|
|
82
|
+
if (payload.typ !== 'agent-assertion')
|
|
83
|
+
return refuse('not an agent assertion');
|
|
84
|
+
if (typeof payload.exp !== 'number' || payload.exp + skew < now) {
|
|
85
|
+
return refuse('expired');
|
|
86
|
+
}
|
|
87
|
+
if (typeof payload.nbf === 'number' && payload.nbf - skew > now) {
|
|
88
|
+
return refuse('not valid yet');
|
|
89
|
+
}
|
|
90
|
+
if (payload.pid !== options.projectId)
|
|
91
|
+
return refuse('another project');
|
|
92
|
+
if (options.audience) {
|
|
93
|
+
const aud = Array.isArray(payload.aud) ? payload.aud : [payload.aud];
|
|
94
|
+
if (!aud.includes(options.audience))
|
|
95
|
+
return refuse('another audience');
|
|
96
|
+
}
|
|
97
|
+
const agent = (payload.agent ?? {});
|
|
98
|
+
return (0, rxjs_1.of)({
|
|
99
|
+
subject: String(payload.sub ?? ''),
|
|
100
|
+
projectId: String(payload.pid),
|
|
101
|
+
agent: { id: String(agent.id ?? ''), name: String(agent.name ?? '') },
|
|
102
|
+
conversationId: String(payload.conversation ?? ''),
|
|
103
|
+
anonymous: payload.anonymous === true,
|
|
104
|
+
claims: (payload.claims ?? {}),
|
|
105
|
+
expiresAt: new Date(payload.exp * 1000),
|
|
106
|
+
});
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
__exportStar(require("./index"), exports);
|
|
110
|
+
//# sourceMappingURL=node.js.map
|
package/dist/node.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AA6EA,oDAkEC;AA/ID,6CAAiE;AACjE,+BAA+D;AAC/D,8CAAgD;AAEhD,qCAA0C;AAC1C,iCAAqC;AAwCrC,MAAM,WAAW,GAAG,EAAE,GAAG,MAAM,CAAC;AAChC,MAAM,SAAS,GAAG,IAAI,GAAG,EAAuC,CAAC;AAEjE,MAAM,OAAO,GAAG,CAAC,IAAY,EAAE,EAAE,CAC/B,IAAI,C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CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC,EAAE;YACrE,cAAc,EAAE,MAAM,CAAC,OAAO,CAAC,YAAY,IAAI,EAAE,CAAC;YAClD,SAAS,EAAE,OAAO,CAAC,SAAS,KAAK,IAAI;YACrC,MAAM,EAAE,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAA4B;YACzD,SAAS,EAAE,IAAI,IAAI,CAAE,OAAO,CAAC,GAAc,GAAG,IAAI,CAAC;SACpD,CAAC,CAAC;IACL,CAAC,CAAC,CACH,CAAC;AACJ,CAAC;AAED,0CAAwB"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { AgentErrorCode } from './errors';
|
|
2
|
+
export interface EmbedAgent {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
description?: string | null;
|
|
6
|
+
welcome?: string | null;
|
|
7
|
+
suggestions?: string[] | null;
|
|
8
|
+
}
|
|
9
|
+
export interface SessionToken {
|
|
10
|
+
token: string;
|
|
11
|
+
/** ISO time; renewed shortly before */
|
|
12
|
+
expiresAt?: string | null;
|
|
13
|
+
agents?: EmbedAgent[] | null;
|
|
14
|
+
}
|
|
15
|
+
export interface AgentToolCall {
|
|
16
|
+
name?: string | null;
|
|
17
|
+
status?: string | null;
|
|
18
|
+
}
|
|
19
|
+
export interface AgentMessage {
|
|
20
|
+
id: string;
|
|
21
|
+
role: 'user' | 'assistant';
|
|
22
|
+
text: string;
|
|
23
|
+
toolCalls?: AgentToolCall[] | null;
|
|
24
|
+
createdAt?: string | null;
|
|
25
|
+
}
|
|
26
|
+
export interface ConversationSummary {
|
|
27
|
+
id: string;
|
|
28
|
+
agentId: string;
|
|
29
|
+
title?: string | null;
|
|
30
|
+
messageCount?: number | null;
|
|
31
|
+
/** pass to `events(afterSeq)` to resume */
|
|
32
|
+
lastSeq?: number | null;
|
|
33
|
+
answering?: boolean | null;
|
|
34
|
+
lastMessageAt?: string | null;
|
|
35
|
+
createdAt?: string | null;
|
|
36
|
+
}
|
|
37
|
+
export interface ConversationDetail extends ConversationSummary {
|
|
38
|
+
messages: AgentMessage[];
|
|
39
|
+
}
|
|
40
|
+
interface EventBase {
|
|
41
|
+
conversationId: string;
|
|
42
|
+
seq: number;
|
|
43
|
+
runId?: string | null;
|
|
44
|
+
createdAt?: string | null;
|
|
45
|
+
}
|
|
46
|
+
export type AgentEvent = (EventBase & {
|
|
47
|
+
type: 'message';
|
|
48
|
+
data: AgentMessage;
|
|
49
|
+
}) | (EventBase & {
|
|
50
|
+
type: 'run-started';
|
|
51
|
+
data: {
|
|
52
|
+
agent?: string;
|
|
53
|
+
};
|
|
54
|
+
}) | (EventBase & {
|
|
55
|
+
type: 'done';
|
|
56
|
+
data: {
|
|
57
|
+
usage?: {
|
|
58
|
+
totalTokens?: number;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
}) | (EventBase & {
|
|
62
|
+
type: 'error';
|
|
63
|
+
data: {
|
|
64
|
+
code: AgentErrorCode;
|
|
65
|
+
message: string;
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
export interface SentMessage {
|
|
69
|
+
conversationId: string;
|
|
70
|
+
runId: string;
|
|
71
|
+
seq: number;
|
|
72
|
+
}
|
|
73
|
+
export type AgentIdentityMode = 'auto' | 'signed' | 'forward';
|
|
74
|
+
export interface AgentEmbedSettings {
|
|
75
|
+
published?: boolean;
|
|
76
|
+
identity?: AgentIdentityMode;
|
|
77
|
+
allowedOrigins?: string[];
|
|
78
|
+
welcome?: string;
|
|
79
|
+
suggestions?: string[];
|
|
80
|
+
showToolDetails?: boolean;
|
|
81
|
+
maxMessagesPerConversation?: number;
|
|
82
|
+
retentionDays?: number;
|
|
83
|
+
}
|
|
84
|
+
export interface ProjectAgent {
|
|
85
|
+
id: string;
|
|
86
|
+
name: string;
|
|
87
|
+
type: string;
|
|
88
|
+
description?: string | null;
|
|
89
|
+
instructions?: string | null;
|
|
90
|
+
tools?: string[] | null;
|
|
91
|
+
isActive?: boolean | null;
|
|
92
|
+
modelName?: string | null;
|
|
93
|
+
mcpLambdaId?: string | null;
|
|
94
|
+
mcpLambdaName?: string | null;
|
|
95
|
+
embed?: (AgentEmbedSettings & {
|
|
96
|
+
publishedAt?: string | null;
|
|
97
|
+
}) | null;
|
|
98
|
+
createdAt?: string | null;
|
|
99
|
+
updatedAt?: string | null;
|
|
100
|
+
}
|
|
101
|
+
export interface CreateAgentInput {
|
|
102
|
+
name: string;
|
|
103
|
+
/** slug, unique in the project (e.g. SUPPORT) */
|
|
104
|
+
type: string;
|
|
105
|
+
instructions: string;
|
|
106
|
+
description?: string;
|
|
107
|
+
/** the tools visitors may use - required to publish */
|
|
108
|
+
tools?: string[];
|
|
109
|
+
isActive?: boolean;
|
|
110
|
+
modelName?: string;
|
|
111
|
+
/** the project's MCP-server lambda the agent uses */
|
|
112
|
+
mcpLambdaId?: string;
|
|
113
|
+
}
|
|
114
|
+
/** What a key may change after creation (the rest is set in the dashboard). */
|
|
115
|
+
export type UpdateAgentInput = Partial<Pick<CreateAgentInput, 'instructions' | 'tools' | 'description' | 'isActive'>>;
|
|
116
|
+
export interface CreateSessionInput {
|
|
117
|
+
/** your user's stable id - conversations belong to it */
|
|
118
|
+
subject: string;
|
|
119
|
+
/** agent ids or names (default: every published agent the key allows) */
|
|
120
|
+
agents?: string[];
|
|
121
|
+
/** small facts signed into what the agent's MCP server receives */
|
|
122
|
+
claims?: Record<string, unknown>;
|
|
123
|
+
/** 300..3600, default 3600 */
|
|
124
|
+
ttlSeconds?: number;
|
|
125
|
+
/** pin the session to one site (e.g. https://app.example.com) */
|
|
126
|
+
origin?: string;
|
|
127
|
+
}
|
|
128
|
+
export {};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/dist/ws.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
/** The part of a WebSocket this package uses (browser `WebSocket`, Node 22+, or `ws`). */
|
|
3
|
+
export interface WebSocketLike {
|
|
4
|
+
readonly protocol: string;
|
|
5
|
+
readonly readyState: number;
|
|
6
|
+
send(data: string): void;
|
|
7
|
+
close(code?: number, reason?: string): void;
|
|
8
|
+
onopen: ((ev: unknown) => void) | null;
|
|
9
|
+
onmessage: ((ev: {
|
|
10
|
+
data: unknown;
|
|
11
|
+
}) => void) | null;
|
|
12
|
+
onclose: ((ev: {
|
|
13
|
+
code?: number;
|
|
14
|
+
reason?: string;
|
|
15
|
+
}) => void) | null;
|
|
16
|
+
onerror: ((ev: unknown) => void) | null;
|
|
17
|
+
}
|
|
18
|
+
export type WebSocketConstructor = new (url: string, protocols: string[]) => WebSocketLike;
|
|
19
|
+
/**
|
|
20
|
+
* Both protocols are offered and the client follows the server's choice
|
|
21
|
+
* (Lambforge plan 53 moves the platform from the legacy `graphql-ws`
|
|
22
|
+
* protocol of subscriptions-transport-ws to `graphql-transport-ws` of the
|
|
23
|
+
* graphql-ws package). The legacy one goes FIRST: a legacy server takes
|
|
24
|
+
* the first offered protocol and closes with 1002 when it is not
|
|
25
|
+
* `graphql-ws` (seen on api.lambforge.com 2026-12-03); a graphql-ws server
|
|
26
|
+
* picks `graphql-transport-ws` wherever it is in the list.
|
|
27
|
+
*/
|
|
28
|
+
export declare const WS_PROTOCOLS: string[];
|
|
29
|
+
export interface SubscribeOptions {
|
|
30
|
+
url: string;
|
|
31
|
+
WebSocket: WebSocketConstructor;
|
|
32
|
+
connectionParams: Record<string, unknown>;
|
|
33
|
+
query: string;
|
|
34
|
+
variables: Record<string, unknown>;
|
|
35
|
+
field: string;
|
|
36
|
+
/** called once the subscription is registered (catch up after this) */
|
|
37
|
+
onStarted?: () => void;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* One subscription on its own socket. Emits `data[field]` per event;
|
|
41
|
+
* errors with a LambforgeError (code `network` when the socket drops);
|
|
42
|
+
* completes when the server completes. Unsubscribe stops and closes.
|
|
43
|
+
*/
|
|
44
|
+
export declare function subscription$<T>(o: SubscribeOptions): Observable<T>;
|