@intelli-1113/stratos-sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # @intelli-1113/stratos-sdk
2
+
3
+ One-line [OpenLLMetry](https://traceloop.com/docs/openllmetry) telemetry for **Stratos AI** — streams agent liveness, tokens, cost, prompts and tool usage to your Stratos dashboard.
4
+
5
+ ## Install
6
+ ```bash
7
+ npm i @intelli-1113/stratos-sdk
8
+ ```
9
+
10
+ ## Configure (environment)
11
+ ```bash
12
+ STRATOS_TOKEN=<token from Stratos → Add agent> # required
13
+ STRATOS_URL=https://stratos.lnt.com # optional, default http://localhost:4000
14
+ STRATOS_APP_NAME=my-agent # optional display name
15
+ ```
16
+
17
+ ## Use — pick one
18
+
19
+ **Zero code changes** (recommended) — load before your app via Node's `--import`:
20
+ ```bash
21
+ node --import @intelli-1113/stratos-sdk/register server.js
22
+ ```
23
+
24
+ **One line** — must be the FIRST import in your entrypoint (before `openai`/`langchain`/etc.):
25
+ ```js
26
+ import "@intelli-1113/stratos-sdk/register";
27
+ ```
28
+
29
+ **Programmatic** — if you want to pass config explicitly:
30
+ ```js
31
+ import { start } from "@intelli-1113/stratos-sdk";
32
+ start({ token: "...", url: "https://stratos.lnt.com", appName: "my-agent" });
33
+ ```
34
+
35
+ ## Why it must load first
36
+ OpenLLMetry patches `openai`/`langchain` to capture spans — it has to run **before** those modules are imported. The `--import` flag and the `/register` entry both guarantee that.
37
+
38
+ ## Changing the URL or token
39
+ Both come from env, read at startup — change the `.env` value and restart. No code edit, no SDK re-publish.
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@intelli-1113/stratos-sdk",
3
+ "version": "1.0.0",
4
+ "description": "One-line OpenLLMetry telemetry for Stratos AI — agent liveness, tokens, cost, prompts and tools.",
5
+ "type": "module",
6
+ "main": "./src/index.js",
7
+ "exports": {
8
+ ".": "./src/index.js",
9
+ "./register": "./src/register.js"
10
+ },
11
+ "files": ["src"],
12
+ "scripts": {
13
+ "test": "node -e \"import('./src/index.js').then(m=>console.log('ok',Object.keys(m)))\""
14
+ },
15
+ "keywords": ["stratos", "openllmetry", "opentelemetry", "observability", "llm", "agent"],
16
+ "license": "MIT",
17
+ "dependencies": {
18
+ "@opentelemetry/exporter-trace-otlp-http": "^0.203.0",
19
+ "@traceloop/node-server-sdk": "^0.27.0"
20
+ }
21
+ }
package/src/index.js ADDED
@@ -0,0 +1,49 @@
1
+ // @intelli-1113/stratos-sdk — initialize OpenLLMetry and stream telemetry to Stratos AI.
2
+ //
3
+ // Config comes from the environment (so the ingest URL / token can change
4
+ // without editing code or re-publishing the SDK):
5
+ // STRATOS_TOKEN enrollment token from Stratos "Add agent" (required)
6
+ // STRATOS_URL Stratos origin, e.g. https://stratos.lnt.com (default http://localhost:4000)
7
+ // STRATOS_APP_NAME display name for this agent (optional)
8
+ //
9
+ // Why this exists: traceloop defaults to OTLP *protobuf* at <baseUrl>/v1/traces;
10
+ // Stratos ingests OTLP *JSON* at /api/ingest. This wires a JSON exporter to the
11
+ // right URL and runs a heartbeat so the agent shows online while it's up.
12
+ import * as traceloop from "@traceloop/node-server-sdk";
13
+ import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
14
+
15
+ let started = false;
16
+
17
+ export function start(opts = {}) {
18
+ if (started) return; // idempotent — safe to import/register more than once
19
+ const token = opts.token || process.env.STRATOS_TOKEN || "";
20
+ const origin = (opts.url || process.env.STRATOS_URL || "http://localhost:4000").replace(/\/+$/, "");
21
+ const appName = opts.appName || process.env.STRATOS_APP_NAME || process.env.npm_package_name || "agent";
22
+ const heartbeatMs = Number(opts.heartbeatMs || process.env.STRATOS_HEARTBEAT_MS || 30000);
23
+
24
+ if (!token) {
25
+ console.warn("[stratos] STRATOS_TOKEN not set — telemetry disabled. Add the token from Stratos > Add agent.");
26
+ return;
27
+ }
28
+ started = true;
29
+
30
+ const ingest = `${origin}/api/ingest`;
31
+ const heartbeatUrl = `${origin}/api/heartbeat`;
32
+
33
+ traceloop.initialize({
34
+ appName,
35
+ disableBatch: true,
36
+ exporter: new OTLPTraceExporter({ url: ingest, headers: { "x-stratos-token": token } }),
37
+ });
38
+
39
+ // Keep the agent "online" while the process is alive (telemetry alone only
40
+ // fires on LLM calls, which would let liveness lapse between requests).
41
+ const ping = () =>
42
+ fetch(heartbeatUrl, { method: "POST", headers: { "x-stratos-token": token } }).catch(() => {});
43
+ ping();
44
+ if (heartbeatMs > 0) setInterval(ping, heartbeatMs).unref();
45
+
46
+ console.log(`[stratos] telemetry → ${ingest} (heartbeat ${heartbeatMs}ms)`);
47
+ }
48
+
49
+ export default { start };
@@ -0,0 +1,5 @@
1
+ // Side-effect entry so telemetry starts before your app code loads.
2
+ // node --import @intelli-1113/stratos-sdk/register server.js (zero code changes)
3
+ // import "@intelli-1113/stratos-sdk/register"; (first line of entrypoint)
4
+ import { start } from "./index.js";
5
+ start();