@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/ws.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WS_PROTOCOLS = void 0;
|
|
4
|
+
exports.subscription$ = subscription$;
|
|
5
|
+
const rxjs_1 = require("rxjs");
|
|
6
|
+
const errors_1 = require("./errors");
|
|
7
|
+
/**
|
|
8
|
+
* Both protocols are offered and the client follows the server's choice
|
|
9
|
+
* (Lambforge plan 53 moves the platform from the legacy `graphql-ws`
|
|
10
|
+
* protocol of subscriptions-transport-ws to `graphql-transport-ws` of the
|
|
11
|
+
* graphql-ws package). The legacy one goes FIRST: a legacy server takes
|
|
12
|
+
* the first offered protocol and closes with 1002 when it is not
|
|
13
|
+
* `graphql-ws` (seen on api.lambforge.com 2026-12-03); a graphql-ws server
|
|
14
|
+
* picks `graphql-transport-ws` wherever it is in the list.
|
|
15
|
+
*/
|
|
16
|
+
exports.WS_PROTOCOLS = ['graphql-ws', 'graphql-transport-ws'];
|
|
17
|
+
/**
|
|
18
|
+
* One subscription on its own socket. Emits `data[field]` per event;
|
|
19
|
+
* errors with a LambforgeError (code `network` when the socket drops);
|
|
20
|
+
* completes when the server completes. Unsubscribe stops and closes.
|
|
21
|
+
*/
|
|
22
|
+
function subscription$(o) {
|
|
23
|
+
return new rxjs_1.Observable((subscriber) => {
|
|
24
|
+
const id = '1';
|
|
25
|
+
let done = false;
|
|
26
|
+
const ws = new o.WebSocket(o.url, exports.WS_PROTOCOLS);
|
|
27
|
+
const modern = () => ws.protocol === 'graphql-transport-ws';
|
|
28
|
+
const send = (msg) => {
|
|
29
|
+
if (ws.readyState === 1)
|
|
30
|
+
ws.send(JSON.stringify(msg));
|
|
31
|
+
};
|
|
32
|
+
const fail = (e) => {
|
|
33
|
+
if (done)
|
|
34
|
+
return;
|
|
35
|
+
done = true;
|
|
36
|
+
subscriber.error(e);
|
|
37
|
+
try {
|
|
38
|
+
ws.close(1000);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
/* already closed */
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
ws.onopen = () => send({ type: 'connection_init', payload: o.connectionParams });
|
|
45
|
+
ws.onmessage = (ev) => {
|
|
46
|
+
let msg;
|
|
47
|
+
try {
|
|
48
|
+
msg = JSON.parse(String(ev.data));
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
switch (msg.type) {
|
|
54
|
+
case 'connection_ack':
|
|
55
|
+
send({
|
|
56
|
+
id,
|
|
57
|
+
type: modern() ? 'subscribe' : 'start',
|
|
58
|
+
payload: { query: o.query, variables: o.variables },
|
|
59
|
+
});
|
|
60
|
+
o.onStarted?.();
|
|
61
|
+
return;
|
|
62
|
+
case 'ping':
|
|
63
|
+
send({ type: 'pong' });
|
|
64
|
+
return;
|
|
65
|
+
case 'next':
|
|
66
|
+
case 'data': {
|
|
67
|
+
const payload = msg.payload;
|
|
68
|
+
if (payload?.errors?.length) {
|
|
69
|
+
fail((0, errors_1.errorFromGraphQL)(payload.errors));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (payload?.data)
|
|
73
|
+
subscriber.next(payload.data[o.field]);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
case 'error':
|
|
77
|
+
fail((0, errors_1.errorFromGraphQL)((Array.isArray(msg.payload)
|
|
78
|
+
? msg.payload
|
|
79
|
+
: [msg.payload])));
|
|
80
|
+
return;
|
|
81
|
+
case 'connection_error':
|
|
82
|
+
fail(new errors_1.LambforgeError(String(msg.payload?.message ??
|
|
83
|
+
'connection refused'), 'unauthorized'));
|
|
84
|
+
return;
|
|
85
|
+
case 'complete':
|
|
86
|
+
if (done)
|
|
87
|
+
return;
|
|
88
|
+
done = true;
|
|
89
|
+
subscriber.complete();
|
|
90
|
+
ws.close(1000);
|
|
91
|
+
return;
|
|
92
|
+
default:
|
|
93
|
+
return; // ka, pong
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
ws.onclose = (ev) => {
|
|
97
|
+
if (done)
|
|
98
|
+
return;
|
|
99
|
+
const unauthorized = ev?.code === 4401 || ev?.code === 4403;
|
|
100
|
+
fail(new errors_1.LambforgeError(`connection closed${ev?.code ? ` (${ev.code}${ev.reason ? ` ${ev.reason}` : ''})` : ''}`, unauthorized ? 'unauthorized' : 'network'));
|
|
101
|
+
};
|
|
102
|
+
ws.onerror = () => undefined; // onclose follows with the reason
|
|
103
|
+
return () => {
|
|
104
|
+
if (!done) {
|
|
105
|
+
done = true;
|
|
106
|
+
send({ id, type: modern() ? 'complete' : 'stop' });
|
|
107
|
+
}
|
|
108
|
+
ws.onmessage = ws.onclose = ws.onerror = ws.onopen = null;
|
|
109
|
+
try {
|
|
110
|
+
ws.close(1000);
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
/* never opened */
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=ws.js.map
|
package/dist/ws.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ws.js","sourceRoot":"","sources":["../src/ws.ts"],"names":[],"mappings":";;;AAgDA,sCA6GC;AA7JD,+BAAkC;AAElC,qCAA4D;AAmB5D;;;;;;;;GAQG;AACU,QAAA,YAAY,GAAG,CAAC,YAAY,EAAE,sBAAsB,CAAC,CAAC;AAanE;;;;GAIG;AACH,SAAgB,aAAa,CAAI,CAAmB;IAClD,OAAO,IAAI,iBAAU,CAAI,CAAC,UAAU,EAAE,EAAE;QACtC,MAAM,EAAE,GAAG,GAAG,CAAC;QACf,IAAI,IAAI,GAAG,KAAK,CAAC;QACjB,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,EAAE,oBAAY,CAAC,CAAC;QAChD,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,EAAE,CAAC,QAAQ,KAAK,sBAAsB,CAAC;QAC5D,MAAM,IAAI,GAAG,CAAC,GAA4B,EAAE,EAAE;YAC5C,IAAI,EAAE,CAAC,UAAU,KAAK,CAAC;gBAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;QACxD,CAAC,CAAC;QACF,MAAM,IAAI,GAAG,CAAC,CAAiB,EAAE,EAAE;YACjC,IAAI,IAAI;gBAAE,OAAO;YACjB,IAAI,GAAG,IAAI,CAAC;YACZ,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACpB,IAAI,CAAC;gBACH,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACjB,CAAC;YAAC,MAAM,CAAC;gBACP,oBAAoB;YACtB,CAAC;QACH,CAAC,CAAC;QAEF,EAAE,CA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E;YACV,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,IAAI,GAAG,IAAI,CAAC;gBACZ,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;YACrD,CAAC;YACD,EAAE,CAAC,SAAS,GAAG,EAAE,CAAC,OAAO,GAAG,EAAE,CAAC,OAAO,GAAG,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC;YAC1D,IAAI,CAAC;gBACH,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACjB,CAAC;YAAC,MAAM,CAAC;gBACP,kBAAkB;YACpB,CAAC;QACH,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lambforge/agents",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "Put your Lambforge agents on your own site or API: agent and session management with a key, visitor chat with live events (browser and Node)",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./node": {
|
|
14
|
+
"types": "./dist/node.d.ts",
|
|
15
|
+
"default": "./dist/node.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md"
|
|
21
|
+
],
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/lamb-forge/packages.git",
|
|
25
|
+
"directory": "packages/agents"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://lambforge.com/docs",
|
|
28
|
+
"keywords": [
|
|
29
|
+
"lambforge",
|
|
30
|
+
"ai-agent",
|
|
31
|
+
"chat",
|
|
32
|
+
"mcp",
|
|
33
|
+
"embed"
|
|
34
|
+
],
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
40
|
+
"lint": "tsc --noEmit -p tsconfig.json",
|
|
41
|
+
"test": "tsx --test test/*.test.ts"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"rxjs": "^7.8.2"
|
|
45
|
+
},
|
|
46
|
+
"gitHead": "bf64a1b9123164ecc48d8356f8cd146f182ef464"
|
|
47
|
+
}
|