@fro.bot/opencode-plugin 0.3.5 → 0.3.6
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.
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Buffer as Buffer$1 } from "node:buffer";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
2
3
|
import { inspect } from "node:util";
|
|
3
4
|
import * as zlib from "node:zlib";
|
|
4
5
|
import { Readable } from "node:stream";
|
|
@@ -7,7 +8,7 @@ import { randomBytes } from "node:crypto";
|
|
|
7
8
|
/** only globals that common to node and browsers are allowed */
|
|
8
9
|
var _globalThis = typeof globalThis === "object" ? globalThis : global;
|
|
9
10
|
// ../../node_modules/@opentelemetry/api/build/esm/version.js
|
|
10
|
-
var VERSION$
|
|
11
|
+
var VERSION$4 = "1.9.0";
|
|
11
12
|
// ../../node_modules/@opentelemetry/api/build/esm/internal/semver.js
|
|
12
13
|
var re = /^(\d+)\.(\d+)\.(\d+)(-(.+))?$/;
|
|
13
14
|
/**
|
|
@@ -86,27 +87,27 @@ function _makeCompatibilityCheck(ownVersion) {
|
|
|
86
87
|
*
|
|
87
88
|
* @param version version of the API requesting an instance of the global API
|
|
88
89
|
*/
|
|
89
|
-
var isCompatible = _makeCompatibilityCheck(VERSION$
|
|
90
|
+
var isCompatible = _makeCompatibilityCheck(VERSION$4);
|
|
90
91
|
// ../../node_modules/@opentelemetry/api/build/esm/internal/global-utils.js
|
|
91
|
-
var major = VERSION$
|
|
92
|
+
var major = VERSION$4.split(".")[0];
|
|
92
93
|
var GLOBAL_OPENTELEMETRY_API_KEY = Symbol.for("opentelemetry.js.api." + major);
|
|
93
94
|
var _global = _globalThis;
|
|
94
95
|
function registerGlobal(type, instance, diag, allowOverride) {
|
|
95
96
|
var _a;
|
|
96
97
|
if (allowOverride === void 0) allowOverride = false;
|
|
97
|
-
var api = _global[GLOBAL_OPENTELEMETRY_API_KEY] = (_a = _global[GLOBAL_OPENTELEMETRY_API_KEY]) !== null && _a !== void 0 ? _a : { version: VERSION$
|
|
98
|
+
var api = _global[GLOBAL_OPENTELEMETRY_API_KEY] = (_a = _global[GLOBAL_OPENTELEMETRY_API_KEY]) !== null && _a !== void 0 ? _a : { version: VERSION$4 };
|
|
98
99
|
if (!allowOverride && api[type]) {
|
|
99
100
|
var err = /* @__PURE__ */ new Error("@opentelemetry/api: Attempted duplicate registration of API: " + type);
|
|
100
101
|
diag.error(err.stack || err.message);
|
|
101
102
|
return false;
|
|
102
103
|
}
|
|
103
104
|
if (api.version !== "1.9.0") {
|
|
104
|
-
var err = /* @__PURE__ */ new Error("@opentelemetry/api: Registration of version v" + api.version + " for " + type + " does not match previously registered API v" + VERSION$
|
|
105
|
+
var err = /* @__PURE__ */ new Error("@opentelemetry/api: Registration of version v" + api.version + " for " + type + " does not match previously registered API v" + VERSION$4);
|
|
105
106
|
diag.error(err.stack || err.message);
|
|
106
107
|
return false;
|
|
107
108
|
}
|
|
108
109
|
api[type] = instance;
|
|
109
|
-
diag.debug("@opentelemetry/api: Registered a global for " + type + " v" + VERSION$
|
|
110
|
+
diag.debug("@opentelemetry/api: Registered a global for " + type + " v" + VERSION$4 + ".");
|
|
110
111
|
return true;
|
|
111
112
|
}
|
|
112
113
|
function getGlobal(type) {
|
|
@@ -116,7 +117,7 @@ function getGlobal(type) {
|
|
|
116
117
|
return (_b = _global[GLOBAL_OPENTELEMETRY_API_KEY]) === null || _b === void 0 ? void 0 : _b[type];
|
|
117
118
|
}
|
|
118
119
|
function unregisterGlobal(type, diag) {
|
|
119
|
-
diag.debug("@opentelemetry/api: Unregistering a global for " + type + " v" + VERSION$
|
|
120
|
+
diag.debug("@opentelemetry/api: Unregistering a global for " + type + " v" + VERSION$4 + ".");
|
|
120
121
|
var api = _global[GLOBAL_OPENTELEMETRY_API_KEY];
|
|
121
122
|
if (api) delete api[type];
|
|
122
123
|
}
|
|
@@ -1233,7 +1234,7 @@ function getStringFromEnv(key) {
|
|
|
1233
1234
|
return raw;
|
|
1234
1235
|
}
|
|
1235
1236
|
// ../../node_modules/@opentelemetry/core/build/esm/version.js
|
|
1236
|
-
const VERSION$
|
|
1237
|
+
const VERSION$3 = "2.8.0";
|
|
1237
1238
|
// ../../node_modules/@opentelemetry/semantic-conventions/build/esm/stable_attributes.js
|
|
1238
1239
|
/**
|
|
1239
1240
|
* The exception message.
|
|
@@ -1316,7 +1317,7 @@ const SDK_INFO = {
|
|
|
1316
1317
|
[ATTR_TELEMETRY_SDK_NAME]: "opentelemetry",
|
|
1317
1318
|
[ATTR_PROCESS_RUNTIME_NAME]: "node",
|
|
1318
1319
|
[ATTR_TELEMETRY_SDK_LANGUAGE]: TELEMETRY_SDK_LANGUAGE_VALUE_NODEJS,
|
|
1319
|
-
[ATTR_TELEMETRY_SDK_VERSION]: VERSION$
|
|
1320
|
+
[ATTR_TELEMETRY_SDK_VERSION]: VERSION$3
|
|
1320
1321
|
};
|
|
1321
1322
|
// ../../node_modules/@opentelemetry/core/build/esm/platform/node/index.js
|
|
1322
1323
|
/**
|
|
@@ -2917,7 +2918,7 @@ function samplingDecisionToString(decision) {
|
|
|
2917
2918
|
}
|
|
2918
2919
|
}
|
|
2919
2920
|
// ../../node_modules/@opentelemetry/sdk-trace-base/build/esm/version.js
|
|
2920
|
-
const VERSION = "2.8.0";
|
|
2921
|
+
const VERSION$1 = "2.8.0";
|
|
2921
2922
|
// ../../node_modules/@opentelemetry/sdk-trace-base/build/esm/Tracer.js
|
|
2922
2923
|
/**
|
|
2923
2924
|
* This class represents a basic tracer.
|
|
@@ -2943,7 +2944,7 @@ var Tracer = class {
|
|
|
2943
2944
|
this._resource = resource;
|
|
2944
2945
|
this._spanProcessor = spanProcessor;
|
|
2945
2946
|
this.instrumentationScope = instrumentationScope;
|
|
2946
|
-
const meter = localConfig.meterProvider ? localConfig.meterProvider.getMeter("@opentelemetry/sdk-trace", VERSION) : createNoopMeter();
|
|
2947
|
+
const meter = localConfig.meterProvider ? localConfig.meterProvider.getMeter("@opentelemetry/sdk-trace", VERSION$1) : createNoopMeter();
|
|
2947
2948
|
this._tracerMetrics = new TracerMetrics(meter);
|
|
2948
2949
|
}
|
|
2949
2950
|
/**
|
|
@@ -4529,8 +4530,19 @@ function createSpanExporter(options) {
|
|
|
4529
4530
|
}, JsonTraceSerializer));
|
|
4530
4531
|
let ended;
|
|
4531
4532
|
let envelopeBytes = 0;
|
|
4533
|
+
const processor = {
|
|
4534
|
+
onStart: () => {},
|
|
4535
|
+
onEnd: (span) => {
|
|
4536
|
+
ended = span;
|
|
4537
|
+
},
|
|
4538
|
+
forceFlush: async () => {},
|
|
4539
|
+
shutdown: async () => {}
|
|
4540
|
+
};
|
|
4532
4541
|
const tracer = new BasicTracerProvider({
|
|
4533
|
-
resource: resourceFromAttributes({
|
|
4542
|
+
resource: resourceFromAttributes({
|
|
4543
|
+
...options.resourceAttributes,
|
|
4544
|
+
"service.name": options.serviceName
|
|
4545
|
+
}),
|
|
4534
4546
|
sampler: new AlwaysOnSampler(),
|
|
4535
4547
|
idGenerator,
|
|
4536
4548
|
spanLimits: SDK_SPAN_LIMITS,
|
|
@@ -4538,14 +4550,7 @@ function createSpanExporter(options) {
|
|
|
4538
4550
|
attributeCountLimit: SDK_SPAN_LIMITS.attributeCountLimit,
|
|
4539
4551
|
attributeValueLengthLimit: Number.POSITIVE_INFINITY
|
|
4540
4552
|
},
|
|
4541
|
-
spanProcessors: [
|
|
4542
|
-
onStart: () => {},
|
|
4543
|
-
onEnd: (span) => {
|
|
4544
|
-
ended = span;
|
|
4545
|
-
},
|
|
4546
|
-
forceFlush: async () => {},
|
|
4547
|
-
shutdown: async () => {}
|
|
4548
|
-
}]
|
|
4553
|
+
spanProcessors: [processor]
|
|
4549
4554
|
}).getTracer(options.serviceName);
|
|
4550
4555
|
function trip() {
|
|
4551
4556
|
if (tripped || cancelled) return;
|
|
@@ -4769,6 +4774,37 @@ function createSpanExporter(options) {
|
|
|
4769
4774
|
}
|
|
4770
4775
|
};
|
|
4771
4776
|
}
|
|
4777
|
+
// src/package-version.ts
|
|
4778
|
+
/**
|
|
4779
|
+
* The plugin's own version, read at run time from the `package.json` that ships beside the built files.
|
|
4780
|
+
*
|
|
4781
|
+
* Not a build-time constant: the release job builds with a placeholder version and writes the real one into the staged
|
|
4782
|
+
* `package.json` afterwards (`npm pkg set version`), so a constant baked in by the build would always be the placeholder.
|
|
4783
|
+
* The tarball carries `package.json` at its root and the built files in `dist/`, so `../package.json` from a built module
|
|
4784
|
+
* is the manifest; this file sits one directory below the package root in the source tree too, so the same path reads the
|
|
4785
|
+
* workspace manifest there. Only `node:fs` is imported: the release import gate allows nothing else.
|
|
4786
|
+
*/
|
|
4787
|
+
const PLUGIN_PACKAGE_NAME = "@fro.bot/opencode-plugin";
|
|
4788
|
+
/** A semantic version, prerelease and build metadata allowed, and nothing else: it ends up as an attribute value. */
|
|
4789
|
+
const VERSION = /^\d+\.\d+\.\d+(?:-[\da-z.-]+)?(?:\+[\da-z.-]+)?$/i;
|
|
4790
|
+
const MAX_VERSION_CHARS = 64;
|
|
4791
|
+
/**
|
|
4792
|
+
* The version, or `undefined` when it cannot be read: a missing or unreadable file, text that is not JSON, another
|
|
4793
|
+
* package's manifest, or a value that is not a bounded semantic version. Never throws: the version is a label, and a
|
|
4794
|
+
* trace without it is still a trace.
|
|
4795
|
+
*/
|
|
4796
|
+
function readPackageVersion(manifest = new URL("../package.json", import.meta.url), read = (url) => readFileSync(url, "utf8")) {
|
|
4797
|
+
try {
|
|
4798
|
+
const document = JSON.parse(read(manifest));
|
|
4799
|
+
if (typeof document !== "object" || document === null || Array.isArray(document)) return void 0;
|
|
4800
|
+
const { name, version } = document;
|
|
4801
|
+
if (name !== PLUGIN_PACKAGE_NAME) return void 0;
|
|
4802
|
+
if (typeof version !== "string" || version.length > MAX_VERSION_CHARS || !VERSION.test(version)) return void 0;
|
|
4803
|
+
return version;
|
|
4804
|
+
} catch {
|
|
4805
|
+
return;
|
|
4806
|
+
}
|
|
4807
|
+
}
|
|
4772
4808
|
// src/tracing/content.ts
|
|
4773
4809
|
/** Per-attribute ceilings for content, in serialized characters. */
|
|
4774
4810
|
const CONTENT_MAX_CHARS = {
|
|
@@ -4980,6 +5016,35 @@ function extractPromptMessage(prompt) {
|
|
|
4980
5016
|
}]
|
|
4981
5017
|
};
|
|
4982
5018
|
}
|
|
5019
|
+
const REPOSITORY_SLUG = /^[\w.-]+\/[\w.-]+$/;
|
|
5020
|
+
const RUN_NUMBER = /^\d{1,20}$/;
|
|
5021
|
+
const ONLY_DOTS = /^\.+$/;
|
|
5022
|
+
/**
|
|
5023
|
+
* The run's page on its GitHub server, in the form GitHub itself gives: `<server>/<owner>/<repo>/actions/runs/<run id>` for the
|
|
5024
|
+
* first attempt (the API's `html_url` for attempt 1 has no `/attempts/` part, though GitHub serves it) and
|
|
5025
|
+
* `<server>/<owner>/<repo>/actions/runs/<run id>/attempts/<attempt>` for a re-run. Built only from parts that cannot change its
|
|
5026
|
+
* shape (an `owner/repo` slug that is not a dot path, and run and attempt numbers that are digits); anything else gives no URL,
|
|
5027
|
+
* never a guessed one.
|
|
5028
|
+
*/
|
|
5029
|
+
function pipelineRunUrl(serverUrl, identity) {
|
|
5030
|
+
const { repository, runId, attempt } = identity;
|
|
5031
|
+
if (!REPOSITORY_SLUG.test(repository) || repository.split("/").some((part) => ONLY_DOTS.test(part))) return void 0;
|
|
5032
|
+
if (!RUN_NUMBER.test(runId) || !RUN_NUMBER.test(attempt)) return void 0;
|
|
5033
|
+
const run = `${serverUrl}/${repository}/actions/runs/${runId}`;
|
|
5034
|
+
return attempt === "1" ? run : `${run}/attempts/${attempt}`;
|
|
5035
|
+
}
|
|
5036
|
+
/**
|
|
5037
|
+
* OpenTelemetry's CI/CD attributes for the run (`cicd.pipeline.run.id` and `cicd.pipeline.run.url.full`, in the core
|
|
5038
|
+
* conventions at release-candidate stability; the GenAI revision this plugin pins does not define them). The id is the run id
|
|
5039
|
+
* the other identity attributes carry; the URL needs the launcher's server and is left out without it.
|
|
5040
|
+
*/
|
|
5041
|
+
function ciPipelineRunAttributes(identity, serverUrl) {
|
|
5042
|
+
const url = serverUrl === void 0 ? void 0 : pipelineRunUrl(serverUrl, identity);
|
|
5043
|
+
return {
|
|
5044
|
+
"cicd.pipeline.run.id": identity.runId,
|
|
5045
|
+
...url === void 0 ? {} : { "cicd.pipeline.run.url.full": url }
|
|
5046
|
+
};
|
|
5047
|
+
}
|
|
4983
5048
|
/**
|
|
4984
5049
|
* Identity the Action supplies, as the attributes every span of its runs carries: the `fro_bot.*` names, and a mirror of each
|
|
4985
5050
|
* under `langfuse.trace.metadata.<key>`. Langfuse's OTLP ingestion (`extractMetadata` in langfuse/langfuse
|
|
@@ -4991,7 +5056,7 @@ function extractPromptMessage(prompt) {
|
|
|
4991
5056
|
* The launcher's invocation id, when it has one, is part of the same identity: it names the one Action step that started the
|
|
4992
5057
|
* server, which `run.id`, `run.attempt` and `job` cannot do (two steps of one job share all three).
|
|
4993
5058
|
*/
|
|
4994
|
-
const actionIdentityAttributes = (identity, invocationId) => ({
|
|
5059
|
+
const actionIdentityAttributes = (identity, invocationId, serverUrl) => ({
|
|
4995
5060
|
"fro_bot.repository": identity.repository,
|
|
4996
5061
|
"fro_bot.run.id": identity.runId,
|
|
4997
5062
|
"fro_bot.run.attempt": identity.attempt,
|
|
@@ -5002,6 +5067,7 @@ const actionIdentityAttributes = (identity, invocationId) => ({
|
|
|
5002
5067
|
"langfuse.trace.metadata.run_attempt": identity.attempt,
|
|
5003
5068
|
"langfuse.trace.metadata.job": identity.job,
|
|
5004
5069
|
"langfuse.trace.metadata.trigger": identity.trigger,
|
|
5070
|
+
...ciPipelineRunAttributes(identity, serverUrl),
|
|
5005
5071
|
...invocationId === void 0 ? {} : {
|
|
5006
5072
|
"fro_bot.invocation.id": invocationId,
|
|
5007
5073
|
"langfuse.trace.metadata.invocation_id": invocationId
|
|
@@ -5324,15 +5390,23 @@ function pruneTools(tools, limit, limits, shared) {
|
|
|
5324
5390
|
if (!isRecord$1(tools)) return void 0;
|
|
5325
5391
|
const meter = meterFor(limit, limits, shared);
|
|
5326
5392
|
const copy = {};
|
|
5393
|
+
let incomplete = false;
|
|
5327
5394
|
for (const name of Object.keys(tools)) {
|
|
5328
|
-
if (name === "__proto__")
|
|
5395
|
+
if (name === "__proto__") {
|
|
5396
|
+
incomplete = true;
|
|
5397
|
+
continue;
|
|
5398
|
+
}
|
|
5329
5399
|
spend(meter, 0, 1);
|
|
5330
5400
|
if (meter.over) return {
|
|
5331
5401
|
value: omittedContent("snapshot-bound"),
|
|
5332
|
-
chars: 0
|
|
5402
|
+
chars: 0,
|
|
5403
|
+
incomplete: false
|
|
5333
5404
|
};
|
|
5334
5405
|
const tool = readKey(tools, name);
|
|
5335
|
-
if (!isRecord$1(tool))
|
|
5406
|
+
if (!isRecord$1(tool)) {
|
|
5407
|
+
incomplete = true;
|
|
5408
|
+
continue;
|
|
5409
|
+
}
|
|
5336
5410
|
spend(meter, name.length, 1);
|
|
5337
5411
|
const description = asString$1(readKey(tool, "description"));
|
|
5338
5412
|
if (description !== void 0) spend(meter, description.length, 0);
|
|
@@ -5340,7 +5414,8 @@ function pruneTools(tools, limit, limits, shared) {
|
|
|
5340
5414
|
const input = isRecord$1(rawInput) ? copyValue(rawInput, meter, 1) : void 0;
|
|
5341
5415
|
if (meter.over) return {
|
|
5342
5416
|
value: omittedContent("snapshot-bound"),
|
|
5343
|
-
chars: 0
|
|
5417
|
+
chars: 0,
|
|
5418
|
+
incomplete: false
|
|
5344
5419
|
};
|
|
5345
5420
|
copy[name] = Object.freeze({
|
|
5346
5421
|
...description === void 0 ? {} : { description },
|
|
@@ -5349,7 +5424,8 @@ function pruneTools(tools, limit, limits, shared) {
|
|
|
5349
5424
|
}
|
|
5350
5425
|
return {
|
|
5351
5426
|
value: Object.freeze(copy),
|
|
5352
|
-
chars: meter.chars
|
|
5427
|
+
chars: meter.chars,
|
|
5428
|
+
incomplete
|
|
5353
5429
|
};
|
|
5354
5430
|
}
|
|
5355
5431
|
function omittedRequest(reason) {
|
|
@@ -5401,6 +5477,7 @@ function snapshotRequest(input, context = {}) {
|
|
|
5401
5477
|
...system === void 0 ? {} : { system: system.value },
|
|
5402
5478
|
...messages === void 0 ? {} : { messages },
|
|
5403
5479
|
...tools === void 0 ? {} : { tools: tools.value },
|
|
5480
|
+
...tools?.incomplete === true ? { toolsIncomplete: true } : {},
|
|
5404
5481
|
...droppedMessages > 0 ? { droppedMessages } : {},
|
|
5405
5482
|
size: used
|
|
5406
5483
|
});
|
|
@@ -5524,6 +5601,56 @@ function snapshotToolResult(result, context = {}) {
|
|
|
5524
5601
|
function snapshotSize(value) {
|
|
5525
5602
|
return isRecord$1(value) && typeof value.size === "number" ? value.size : 0;
|
|
5526
5603
|
}
|
|
5604
|
+
// src/tracing/tool-definitions.ts
|
|
5605
|
+
/**
|
|
5606
|
+
* What a request's tool list says, worked out once per snapshot: how many tools it offered, how long their serialized
|
|
5607
|
+
* definitions are, and their names (to tell whether a called tool was among them).
|
|
5608
|
+
*
|
|
5609
|
+
* The list is the hook-time snapshot's `tools` record (`snapshot.ts`), the same one `gen_ai.tool.definitions` is built from. So
|
|
5610
|
+
* the count and length describe what this plugin captured of the request, not what the provider billed: the snapshot keeps a
|
|
5611
|
+
* tool's name, description and input schema and nothing else.
|
|
5612
|
+
*
|
|
5613
|
+
* Plain functions: no SDK, no I/O, no clock. Nothing here throws.
|
|
5614
|
+
*/
|
|
5615
|
+
/** The snapshot's `tools` object is frozen and lives as long as its request, so the stats live exactly as long as it does. */
|
|
5616
|
+
const computed = /* @__PURE__ */ new WeakMap();
|
|
5617
|
+
function compute(tools) {
|
|
5618
|
+
try {
|
|
5619
|
+
const names = new Set(Object.keys(tools));
|
|
5620
|
+
const definitions = extractToolDefinitions(tools);
|
|
5621
|
+
return {
|
|
5622
|
+
names,
|
|
5623
|
+
count: names.size,
|
|
5624
|
+
chars: definitions === void 0 ? 0 : JSON.stringify(definitions).length
|
|
5625
|
+
};
|
|
5626
|
+
} catch {
|
|
5627
|
+
return;
|
|
5628
|
+
}
|
|
5629
|
+
}
|
|
5630
|
+
/**
|
|
5631
|
+
* The stats of a request's `tools`, or `undefined` when the list is not known: absent, not an object, or a field the
|
|
5632
|
+
* snapshot could not take (`OmittedContent`). Computed once per `tools` object: the next ask is a lookup.
|
|
5633
|
+
*/
|
|
5634
|
+
function toolDefinitionStats(tools) {
|
|
5635
|
+
if (typeof tools !== "object" || tools === null || Array.isArray(tools)) return void 0;
|
|
5636
|
+
if (omittedReason(tools) !== void 0) return void 0;
|
|
5637
|
+
const known = computed.get(tools);
|
|
5638
|
+
if (known !== void 0 || computed.has(tools)) return known;
|
|
5639
|
+
const stats = compute(tools);
|
|
5640
|
+
computed.set(tools, stats);
|
|
5641
|
+
return stats;
|
|
5642
|
+
}
|
|
5643
|
+
/**
|
|
5644
|
+
* The offered tool names of a request snapshot (the object a `request` observation carries as its content), only when the list
|
|
5645
|
+
* is the whole of what was offered. A snapshot that dropped an entry (`toolsIncomplete`) or left the list out is not: a name
|
|
5646
|
+
* missing from it proves nothing, so no names are given.
|
|
5647
|
+
*/
|
|
5648
|
+
function offeredToolNames(request) {
|
|
5649
|
+
if (typeof request !== "object" || request === null || Array.isArray(request)) return void 0;
|
|
5650
|
+
const { tools, toolsIncomplete } = request;
|
|
5651
|
+
if (toolsIncomplete === true) return void 0;
|
|
5652
|
+
return toolDefinitionStats(tools)?.names;
|
|
5653
|
+
}
|
|
5527
5654
|
// src/tracing/genai-attributes.ts
|
|
5528
5655
|
/** Set only when the value is defined: an uncaptured field sets no attribute. */
|
|
5529
5656
|
function set(attributes, name, value) {
|
|
@@ -5537,9 +5664,26 @@ function identityAttributes(record, options) {
|
|
|
5537
5664
|
"langfuse.session.id": options.sessionId ?? record.rootSessionId
|
|
5538
5665
|
};
|
|
5539
5666
|
set(attributes, "gen_ai.agent.name", record.agent);
|
|
5540
|
-
if (options.identity !== void 0) Object.assign(attributes, actionIdentityAttributes(options.identity, options.invocationId));
|
|
5667
|
+
if (options.identity !== void 0) Object.assign(attributes, actionIdentityAttributes(options.identity, options.invocationId, options.serverUrl));
|
|
5541
5668
|
return attributes;
|
|
5542
5669
|
}
|
|
5670
|
+
/**
|
|
5671
|
+
* Langfuse's observation type, said outright. Its ingestion maps `gen_ai.operation.name` to a type only after
|
|
5672
|
+
* `langfuse.observation.type`, and a type named here is not at the mercy of that mapping (which has changed between releases).
|
|
5673
|
+
*/
|
|
5674
|
+
const OBSERVATION_TYPE = {
|
|
5675
|
+
chat: "generation",
|
|
5676
|
+
invoke_agent: "agent",
|
|
5677
|
+
execute_tool: "tool"
|
|
5678
|
+
};
|
|
5679
|
+
/**
|
|
5680
|
+
* Langfuse's `cost_details`, as the JSON object it reads. Set only for a cost that is a positive, finite number: a supplied cost
|
|
5681
|
+
* replaces the cost Langfuse works out from the usage and its price list, and OpenCode reports 0 for a model it has no price for,
|
|
5682
|
+
* so a zero is "unknown" as often as "free" and would zero the cost Langfuse could have worked out.
|
|
5683
|
+
*/
|
|
5684
|
+
function costDetails(cost) {
|
|
5685
|
+
return cost !== void 0 && Number.isFinite(cost) && cost > 0 ? JSON.stringify({ total: cost }) : void 0;
|
|
5686
|
+
}
|
|
5543
5687
|
function outcomeAttributes(record) {
|
|
5544
5688
|
const attributes = { "fro_bot.outcome": record.status };
|
|
5545
5689
|
if (record.marks.length > 0) attributes["fro_bot.span.marks"] = record.marks;
|
|
@@ -5597,6 +5741,7 @@ function chatSpan(record, options) {
|
|
|
5597
5741
|
const preDropped = {};
|
|
5598
5742
|
const attributes = {
|
|
5599
5743
|
"gen_ai.operation.name": "chat",
|
|
5744
|
+
"langfuse.observation.type": OBSERVATION_TYPE.chat,
|
|
5600
5745
|
...identityAttributes(record, options),
|
|
5601
5746
|
...outcomeAttributes(record),
|
|
5602
5747
|
"fro_bot.request.kind": record.requestKind,
|
|
@@ -5609,11 +5754,18 @@ function chatSpan(record, options) {
|
|
|
5609
5754
|
set(attributes, "gen_ai.response.finish_reasons", finishReasons(record));
|
|
5610
5755
|
Object.assign(attributes, usageAttributes(record.usage));
|
|
5611
5756
|
if (record.cost !== void 0) attributes["fro_bot.usage.cost_usd"] = record.cost;
|
|
5757
|
+
set(attributes, "langfuse.observation.cost_details", costDetails(record.cost));
|
|
5612
5758
|
if (record.followOnOf.length > 0) attributes["fro_bot.turn.follow_on_of"] = record.followOnOf;
|
|
5613
5759
|
const request = record.request ?? {};
|
|
5614
5760
|
const system = extractSystemInstructions(noting(request.system, "gen_ai.system_instructions", omitted));
|
|
5615
5761
|
if (system !== void 0) attributes["gen_ai.system_instructions"] = contentAttribute(system, CONTENT_MAX_CHARS.systemInstructions);
|
|
5616
|
-
const
|
|
5762
|
+
const tools = noting(request.tools, "gen_ai.tool.definitions", omitted);
|
|
5763
|
+
const definitions = extractToolDefinitions(tools);
|
|
5764
|
+
const sizes = toolDefinitionStats(tools);
|
|
5765
|
+
if (sizes !== void 0) {
|
|
5766
|
+
attributes["fro_bot.tool_definitions.count"] = sizes.count;
|
|
5767
|
+
attributes["fro_bot.tool_definitions.chars"] = sizes.chars;
|
|
5768
|
+
}
|
|
5617
5769
|
if (definitions !== void 0) attributes["gen_ai.tool.definitions"] = contentAttribute(definitions, CONTENT_MAX_CHARS.toolDefinitions);
|
|
5618
5770
|
const output = extractOutputMessages({
|
|
5619
5771
|
texts: record.texts,
|
|
@@ -5645,6 +5797,7 @@ function chatSpan(record, options) {
|
|
|
5645
5797
|
function toolSpan(record, options) {
|
|
5646
5798
|
const attributes = {
|
|
5647
5799
|
"gen_ai.operation.name": "execute_tool",
|
|
5800
|
+
"langfuse.observation.type": OBSERVATION_TYPE.execute_tool,
|
|
5648
5801
|
...identityAttributes(record, options),
|
|
5649
5802
|
...outcomeAttributes(record),
|
|
5650
5803
|
"gen_ai.tool.name": record.tool,
|
|
@@ -5653,6 +5806,7 @@ function toolSpan(record, options) {
|
|
|
5653
5806
|
"fro_bot.tool.outcome": record.outcome
|
|
5654
5807
|
};
|
|
5655
5808
|
set(attributes, "fro_bot.tool.error_type", record.errorType);
|
|
5809
|
+
set(attributes, "fro_bot.tool.offered", record.offered);
|
|
5656
5810
|
set(attributes, "fro_bot.subagent.session_id", record.childSessionId);
|
|
5657
5811
|
if (record.providerExecuted) attributes["fro_bot.tool.provider_executed"] = true;
|
|
5658
5812
|
const omitted = [];
|
|
@@ -5691,6 +5845,7 @@ function invokeSpan(record, options) {
|
|
|
5691
5845
|
const omitted = [];
|
|
5692
5846
|
const attributes = {
|
|
5693
5847
|
"gen_ai.operation.name": "invoke_agent",
|
|
5848
|
+
"langfuse.observation.type": OBSERVATION_TYPE.invoke_agent,
|
|
5694
5849
|
...identityAttributes(record, options),
|
|
5695
5850
|
...outcomeAttributes(record),
|
|
5696
5851
|
"fro_bot.agent.role": record.role
|
|
@@ -5714,7 +5869,7 @@ function invokeSpan(record, options) {
|
|
|
5714
5869
|
traceId: record.traceId,
|
|
5715
5870
|
spanId: record.spanId,
|
|
5716
5871
|
parentSpanId: record.parentSpanId,
|
|
5717
|
-
name: `invoke_agent ${record.agent
|
|
5872
|
+
name: record.agent === void 0 || record.agent === "" ? "invoke_agent" : `invoke_agent ${record.agent}`,
|
|
5718
5873
|
kind: "internal",
|
|
5719
5874
|
startMs: record.start,
|
|
5720
5875
|
endMs: record.end,
|
|
@@ -5806,7 +5961,8 @@ const DEFAULT_LIMITS = {
|
|
|
5806
5961
|
maxPendingToolNotes: 64,
|
|
5807
5962
|
toolNoteWaitMs: 1e4,
|
|
5808
5963
|
tombstoneTtlMs: 864e5,
|
|
5809
|
-
maxHookTimes: 64
|
|
5964
|
+
maxHookTimes: 64,
|
|
5965
|
+
maxHeldToolSpans: 256
|
|
5810
5966
|
};
|
|
5811
5967
|
const CREATING_KINDS = /* @__PURE__ */ new Set([
|
|
5812
5968
|
"prompt",
|
|
@@ -5815,6 +5971,12 @@ const CREATING_KINDS = /* @__PURE__ */ new Set([
|
|
|
5815
5971
|
"execution.started",
|
|
5816
5972
|
"request"
|
|
5817
5973
|
]);
|
|
5974
|
+
/** Whether the call's name was offered, or undefined when it cannot be said: no known list, no known name, or a call the provider ran. */
|
|
5975
|
+
function offeredFlag(tool) {
|
|
5976
|
+
if (tool.offeredNames === void 0 || tool.offerBasis?.certain !== true) return void 0;
|
|
5977
|
+
if (tool.providerExecuted || tool.tool === "unknown") return void 0;
|
|
5978
|
+
return tool.offeredNames.has(tool.tool);
|
|
5979
|
+
}
|
|
5818
5980
|
function applyBefore(tool, o) {
|
|
5819
5981
|
tool.agent = o.agent ?? tool.agent;
|
|
5820
5982
|
if (tool.tool === "unknown") tool.tool = o.tool;
|
|
@@ -5855,6 +6017,8 @@ function createTurnModel(options) {
|
|
|
5855
6017
|
const releasedChildren = /* @__PURE__ */ new Set();
|
|
5856
6018
|
/** Characters of model output held by open requests, against `maxHeldOutputChars`. */
|
|
5857
6019
|
let heldOutputChars = 0;
|
|
6020
|
+
/** Tool spans held across the model, against `maxHeldToolSpans`. */
|
|
6021
|
+
let heldToolSpans = 0;
|
|
5858
6022
|
/** Snapshots dropped with no span to carry them, until `takeDiscarded` hands them back. */
|
|
5859
6023
|
let discarded = [];
|
|
5860
6024
|
/** Snapshots that gained a second owner, until `takeRetained` hands them over. */
|
|
@@ -5994,7 +6158,7 @@ function createTurnModel(options) {
|
|
|
5994
6158
|
spanId: invoke.spanId,
|
|
5995
6159
|
traceId: trace.id,
|
|
5996
6160
|
parentSpanId: invoke.parentSpanId,
|
|
5997
|
-
name: `invoke_agent ${invoke.agent
|
|
6161
|
+
name: invoke.agent === void 0 || invoke.agent === "" ? "invoke_agent" : `invoke_agent ${invoke.agent}`,
|
|
5998
6162
|
start: invoke.start,
|
|
5999
6163
|
end: Math.max(at, invoke.start),
|
|
6000
6164
|
status: invoke.status,
|
|
@@ -6013,6 +6177,8 @@ function createTurnModel(options) {
|
|
|
6013
6177
|
function emitRequest(request, at, status, error, extraMarks = []) {
|
|
6014
6178
|
if (request.closed) return;
|
|
6015
6179
|
request.closed = true;
|
|
6180
|
+
request.certainty.closed = true;
|
|
6181
|
+
releaseHeld(request.certainty);
|
|
6016
6182
|
const hook = sessions.get(request.sessionId)?.hooks.find((candidate) => candidate.request === request);
|
|
6017
6183
|
if (hook !== void 0) hook.request = void 0;
|
|
6018
6184
|
heldOutputChars = Math.max(0, heldOutputChars - request.outputChars);
|
|
@@ -6058,7 +6224,7 @@ function createTurnModel(options) {
|
|
|
6058
6224
|
function emitTool(tool, at, outcome, extra) {
|
|
6059
6225
|
tool.trace.openSpans = Math.max(0, tool.trace.openSpans - 1);
|
|
6060
6226
|
const failed = outcome !== "success";
|
|
6061
|
-
|
|
6227
|
+
const record = {
|
|
6062
6228
|
kind: "execute_tool",
|
|
6063
6229
|
spanId: tool.spanId,
|
|
6064
6230
|
traceId: tool.trace.id,
|
|
@@ -6073,7 +6239,7 @@ function createTurnModel(options) {
|
|
|
6073
6239
|
} : void 0,
|
|
6074
6240
|
sessionId: tool.sessionId,
|
|
6075
6241
|
rootSessionId: tool.trace.rootSessionId,
|
|
6076
|
-
agent: tool.agent,
|
|
6242
|
+
agent: tool.agent ?? tool.askedAgent ?? tool.ownerAgent,
|
|
6077
6243
|
gaps: [...tool.gaps],
|
|
6078
6244
|
marks: [...extra.marks ?? []],
|
|
6079
6245
|
tool: tool.tool,
|
|
@@ -6085,7 +6251,34 @@ function createTurnModel(options) {
|
|
|
6085
6251
|
toolTruncated: extra.truncated,
|
|
6086
6252
|
childSessionId: tool.childSessionId,
|
|
6087
6253
|
providerExecuted: tool.providerExecuted,
|
|
6254
|
+
offered: offeredFlag(tool),
|
|
6088
6255
|
discarded: tool.discarded
|
|
6256
|
+
};
|
|
6257
|
+
const basis = tool.offerBasis;
|
|
6258
|
+
if (record.offered !== void 0 && basis !== void 0 && !(basis.certain && basis.stepEnded)) {
|
|
6259
|
+
if (basis.certain && !basis.closed && heldToolSpans < limits.maxHeldToolSpans) {
|
|
6260
|
+
basis.held.push(record);
|
|
6261
|
+
heldToolSpans += 1;
|
|
6262
|
+
return;
|
|
6263
|
+
}
|
|
6264
|
+
emit({
|
|
6265
|
+
...record,
|
|
6266
|
+
offered: void 0
|
|
6267
|
+
});
|
|
6268
|
+
return;
|
|
6269
|
+
}
|
|
6270
|
+
emit(record);
|
|
6271
|
+
}
|
|
6272
|
+
/** Exports the tool spans waiting on a request: with their verdict if it settled certain, else without one. */
|
|
6273
|
+
function releaseHeld(basis) {
|
|
6274
|
+
const held = basis.held;
|
|
6275
|
+
if (held.length === 0) return;
|
|
6276
|
+
basis.held = [];
|
|
6277
|
+
heldToolSpans = Math.max(0, heldToolSpans - held.length);
|
|
6278
|
+
const trusted = basis.certain && basis.stepEnded;
|
|
6279
|
+
for (const record of held) emit(trusted ? record : {
|
|
6280
|
+
...record,
|
|
6281
|
+
offered: void 0
|
|
6089
6282
|
});
|
|
6090
6283
|
}
|
|
6091
6284
|
/** Closes a trace: its descendants first, then its root. `incomplete` marks every span that was still open. */
|
|
@@ -6448,7 +6641,7 @@ function createTurnModel(options) {
|
|
|
6448
6641
|
parentSpanId: invoke.spanId,
|
|
6449
6642
|
requestKind: o.requestKind,
|
|
6450
6643
|
start: o.at,
|
|
6451
|
-
agent: o.requestKind === "title"
|
|
6644
|
+
agent: o.requestKind === "title" || o.requestKind === "compaction" ? void 0 : o.agent,
|
|
6452
6645
|
model: o.model,
|
|
6453
6646
|
provider: o.provider,
|
|
6454
6647
|
request: o.content,
|
|
@@ -6467,6 +6660,12 @@ function createTurnModel(options) {
|
|
|
6467
6660
|
marks: /* @__PURE__ */ new Set(),
|
|
6468
6661
|
closed: false,
|
|
6469
6662
|
bindUncertain: false,
|
|
6663
|
+
certainty: {
|
|
6664
|
+
certain: true,
|
|
6665
|
+
stepEnded: false,
|
|
6666
|
+
closed: false,
|
|
6667
|
+
held: []
|
|
6668
|
+
},
|
|
6470
6669
|
stepAgent: void 0,
|
|
6471
6670
|
stepModel: void 0,
|
|
6472
6671
|
stepProvider: void 0
|
|
@@ -6474,7 +6673,10 @@ function createTurnModel(options) {
|
|
|
6474
6673
|
if (o.content === void 0) request.gaps.add("request");
|
|
6475
6674
|
node.requests.push(request);
|
|
6476
6675
|
if (o.requestKind === "primary") {
|
|
6477
|
-
if (node.withheld)
|
|
6676
|
+
if (node.withheld) {
|
|
6677
|
+
request.bindUncertain = true;
|
|
6678
|
+
request.certainty.certain = false;
|
|
6679
|
+
}
|
|
6478
6680
|
recordHook(node, o.at, request);
|
|
6479
6681
|
}
|
|
6480
6682
|
}
|
|
@@ -6515,6 +6717,8 @@ function createTurnModel(options) {
|
|
|
6515
6717
|
for (const request of node.requests) {
|
|
6516
6718
|
if (request.requestKind !== "primary" || request.closed || request.bindUncertain) continue;
|
|
6517
6719
|
request.bindUncertain = true;
|
|
6720
|
+
request.certainty.certain = false;
|
|
6721
|
+
releaseHeld(request.certainty);
|
|
6518
6722
|
for (const call of request.toolCalls) discard(call.input);
|
|
6519
6723
|
request.toolCalls = [];
|
|
6520
6724
|
}
|
|
@@ -6633,6 +6837,7 @@ function createTurnModel(options) {
|
|
|
6633
6837
|
const node = sessions.get(o.sessionId);
|
|
6634
6838
|
const request = node?.stepOwner.get(o.messageId);
|
|
6635
6839
|
if (node === void 0 || request === void 0) return;
|
|
6840
|
+
request.certainty.stepEnded = request.certainty.certain;
|
|
6636
6841
|
request.finishReason = o.finish;
|
|
6637
6842
|
request.rawFinishReason = o.rawFinish;
|
|
6638
6843
|
request.usage = o.usage;
|
|
@@ -6728,6 +6933,10 @@ function createTurnModel(options) {
|
|
|
6728
6933
|
tool: init.tool ?? note?.tool ?? note?.before?.tool ?? note?.after?.tool ?? "unknown",
|
|
6729
6934
|
start: at,
|
|
6730
6935
|
agent: void 0,
|
|
6936
|
+
ownerAgent: node.agent,
|
|
6937
|
+
askedAgent: void 0,
|
|
6938
|
+
offeredNames: void 0,
|
|
6939
|
+
offerBasis: void 0,
|
|
6731
6940
|
input: void 0,
|
|
6732
6941
|
callInput: void 0,
|
|
6733
6942
|
inputFromHook: false,
|
|
@@ -6783,9 +6992,14 @@ function createTurnModel(options) {
|
|
|
6783
6992
|
}
|
|
6784
6993
|
tool.providerExecuted = o.executed;
|
|
6785
6994
|
tool.callInput = o.input;
|
|
6995
|
+
const asked = o.messageId === void 0 ? void 0 : node.stepOwner.get(o.messageId);
|
|
6996
|
+
if (asked !== void 0 && !asked.bindUncertain) {
|
|
6997
|
+
tool.offeredNames = offeredToolNames(asked.request);
|
|
6998
|
+
tool.offerBasis = asked.certainty;
|
|
6999
|
+
tool.askedAgent = asked.agent ?? asked.stepAgent;
|
|
7000
|
+
}
|
|
6786
7001
|
if (!tool.inputFromHook) tool.input = o.input;
|
|
6787
7002
|
else if (o.input !== void 0) tool.discarded.push(o.input);
|
|
6788
|
-
const asked = o.messageId === void 0 ? void 0 : node.stepOwner.get(o.messageId);
|
|
6789
7003
|
if (asked !== void 0 && !asked.bindUncertain) {
|
|
6790
7004
|
if (asked.toolCalls.length >= limits.maxOutputParts) asked.gaps.add("tool-calls-over-limit");
|
|
6791
7005
|
else {
|
|
@@ -7196,7 +7410,8 @@ function createTracePipeline(options) {
|
|
|
7196
7410
|
identity: options.identity,
|
|
7197
7411
|
rootSpan: options.rootSpan,
|
|
7198
7412
|
sessionId: options.sessionId,
|
|
7199
|
-
invocationId: options.invocationId
|
|
7413
|
+
invocationId: options.invocationId,
|
|
7414
|
+
serverUrl: options.serverUrl
|
|
7200
7415
|
};
|
|
7201
7416
|
/** Observations waiting for the model, each with the raw text it holds against `maxInboxChars`. */
|
|
7202
7417
|
const inbox = [];
|
|
@@ -7915,6 +8130,31 @@ async function registerObservers(host, emit, now = Date.now, snapshot = {}) {
|
|
|
7915
8130
|
const CLEANUP_BOUND_MS = 3e3;
|
|
7916
8131
|
/** The `service.name` of every span this plugin exports. The Action's own spans carry a different one. */
|
|
7917
8132
|
const PLUGIN_SERVICE_NAME = "fro-bot-opencode-plugin";
|
|
8133
|
+
/** A version as a resource value: short, printable, no spaces. Anything else is not trusted as a label. */
|
|
8134
|
+
const RESOURCE_VERSION = /^[\da-z][\w.+-]{0,63}$/i;
|
|
8135
|
+
/**
|
|
8136
|
+
* A version that is safe to put on the resource, or `undefined`. The resource is built once and no span's scrub pass reaches
|
|
8137
|
+
* it, so the text passes the same scrubber here and goes out only when the scrubber leaves it exactly as it was and the
|
|
8138
|
+
* safety net does not recognise it: a value that would need redacting is left unset, never sent altered.
|
|
8139
|
+
*/
|
|
8140
|
+
function resourceVersion(value, scrubber) {
|
|
8141
|
+
if (value === void 0 || !RESOURCE_VERSION.test(value)) return void 0;
|
|
8142
|
+
try {
|
|
8143
|
+
const result = scrubber.scrub(value);
|
|
8144
|
+
if (!result.ok || result.text !== value || scrubber.survived?.(value) === true) return void 0;
|
|
8145
|
+
return value;
|
|
8146
|
+
} catch {
|
|
8147
|
+
return;
|
|
8148
|
+
}
|
|
8149
|
+
}
|
|
8150
|
+
/** The plugin's own version. Reading it must never stop tracing from starting. */
|
|
8151
|
+
function pluginVersion(options) {
|
|
8152
|
+
try {
|
|
8153
|
+
return (options.readVersion ?? readPackageVersion)();
|
|
8154
|
+
} catch {
|
|
8155
|
+
return;
|
|
8156
|
+
}
|
|
8157
|
+
}
|
|
7918
8158
|
async function startTracing(host, settings, options) {
|
|
7919
8159
|
const { log } = options;
|
|
7920
8160
|
const local = settings.host === "local";
|
|
@@ -7922,9 +8162,18 @@ async function startTracing(host, settings, options) {
|
|
|
7922
8162
|
env: options.env,
|
|
7923
8163
|
extraSecrets: local ? Object.values(settings.headers) : []
|
|
7924
8164
|
});
|
|
8165
|
+
const version = resourceVersion(pluginVersion(options), scrubber);
|
|
8166
|
+
const opencodeVersion = resourceVersion(options.opencodeVersion, scrubber);
|
|
7925
8167
|
const exporter = createSpanExporter({
|
|
7926
8168
|
url: settings.endpoint,
|
|
7927
8169
|
serviceName: PLUGIN_SERVICE_NAME,
|
|
8170
|
+
resourceAttributes: {
|
|
8171
|
+
...version === void 0 ? {} : {
|
|
8172
|
+
"service.version": version,
|
|
8173
|
+
"langfuse.release": version
|
|
8174
|
+
},
|
|
8175
|
+
...opencodeVersion === void 0 ? {} : { "fro_bot.opencode.version": opencodeVersion }
|
|
8176
|
+
},
|
|
7928
8177
|
headers: local ? settings.headers : {},
|
|
7929
8178
|
reportCounts: !local,
|
|
7930
8179
|
onStopped: () => {
|
|
@@ -7940,7 +8189,8 @@ async function startTracing(host, settings, options) {
|
|
|
7940
8189
|
identity: settings.identity,
|
|
7941
8190
|
rootSpan: settings.rootSpan,
|
|
7942
8191
|
sessionId: settings.sessionId,
|
|
7943
|
-
invocationId: settings.invocationId
|
|
8192
|
+
invocationId: settings.invocationId,
|
|
8193
|
+
serverUrl: settings.serverUrl
|
|
7944
8194
|
} : {},
|
|
7945
8195
|
...options.now === void 0 ? {} : { now: options.now }
|
|
7946
8196
|
});
|
|
@@ -7977,4 +8227,4 @@ async function startTracing(host, settings, options) {
|
|
|
7977
8227
|
}
|
|
7978
8228
|
export { startTracing };
|
|
7979
8229
|
|
|
7980
|
-
//# sourceMappingURL=tracing-
|
|
8230
|
+
//# sourceMappingURL=tracing-B58yZAvo.mjs.map
|