diff --git a/bun.lock b/bun.lock index aeadc093b..ee6a1baf9 100644 --- a/bun.lock +++ b/bun.lock @@ -95,6 +95,23 @@ "@types/bun": "catalog:", }, }, + "packages/bcode-laminar": { + "name": "@browser-use/bcode-laminar", + "version": "0.0.0", + "dependencies": { + "@grpc/grpc-js": "1.14.3", + "@opencode-ai/plugin": "workspace:*", + "@opentelemetry/api": "1.9.0", + "@opentelemetry/core": "2.6.1", + "@opentelemetry/exporter-trace-otlp-grpc": "0.214.0", + "@opentelemetry/sdk-node": "0.214.0", + "@opentelemetry/sdk-trace-base": "2.6.1", + }, + "devDependencies": { + "@tsconfig/bun": "catalog:", + "@types/bun": "catalog:", + }, + }, "packages/console/app": { "name": "@opencode-ai/console-app", "version": "1.14.39", @@ -358,6 +375,7 @@ "@ai-sdk/xai": "3.0.82", "@aws-sdk/credential-providers": "3.993.0", "@browser-use/bcode-browser": "workspace:*", + "@browser-use/bcode-laminar": "workspace:*", "@clack/prompts": "1.0.0-alpha.1", "@effect/opentelemetry": "catalog:", "@effect/platform-node": "catalog:", @@ -1011,6 +1029,8 @@ "@browser-use/bcode-browser": ["@browser-use/bcode-browser@workspace:packages/bcode-browser"], + "@browser-use/bcode-laminar": ["@browser-use/bcode-laminar@workspace:packages/bcode-laminar"], + "@browser-use/browsercode-core": ["@browser-use/browsercode-core@workspace:packages/opencode"], "@bufbuild/protobuf": ["@bufbuild/protobuf@2.11.0", "", {}, "sha512-sBXGT13cpmPR5BMgHE6UEEfEaShh5Ror6rfN3yEK5si7QVrtZg8LEPQb0VVhiLRUslD2yLnXtnRzG035J/mZXQ=="], @@ -1195,6 +1215,10 @@ "@graphql-typed-document-node/core": ["@graphql-typed-document-node/core@3.2.0", "", { "peerDependencies": { "graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" } }, "sha512-mB9oAsNCm9aM3/SOv4YtBMqZbYj10R7dkq8byBqxGY/ncFwhf2oQzMV+LCRlWoDSEBJ3COiR1yeDvMtsoOsuFQ=="], + "@grpc/grpc-js": ["@grpc/grpc-js@1.14.3", "", { "dependencies": { "@grpc/proto-loader": "^0.8.0", "@js-sdsl/ordered-map": "^4.4.2" } }, "sha512-Iq8QQQ/7X3Sac15oB6p0FmUg/klxQvXLeileoqrTRGJYLV+/9tubbr9ipz0GKHjmXVsgFPo/+W+2cA8eNcR+XA=="], + + "@grpc/proto-loader": ["@grpc/proto-loader@0.8.0", "", { "dependencies": { "lodash.camelcase": "^4.3.0", "long": "^5.0.0", "protobufjs": "^7.5.3", "yargs": "^17.7.2" }, "bin": { "proto-loader-gen-types": "build/bin/proto-loader-gen-types.js" } }, "sha512-rc1hOQtjIWGxcxpb9aHAfLpIctjEnsDehj0DAiVfBlmT84uvR0uUtN2hEi/ecvWVjXUGf5qPF4qEgiLOx1YIMQ=="], + "@happy-dom/global-registrator": ["@happy-dom/global-registrator@20.0.11", "", { "dependencies": { "@types/node": "^20.0.0", "happy-dom": "^20.0.11" } }, "sha512-GqNqiShBT/lzkHTMC/slKBrvN0DsD4Di8ssBk4aDaVgEn+2WMzE6DXxq701ndSXj7/0cJ8mNT71pM7Bnrr6JRw=="], "@hey-api/codegen-core": ["@hey-api/codegen-core@0.5.5", "", { "dependencies": { "@hey-api/types": "0.1.2", "ansi-colors": "4.1.3", "c12": "3.3.3", "color-support": "1.1.3" }, "peerDependencies": { "typescript": ">=5.5.3" } }, "sha512-f2ZHucnA2wBGAY8ipB4wn/mrEYW+WUxU2huJmUvfDO6AE2vfILSHeF3wCO39Pz4wUYPoAWZByaauftLrOfC12Q=="], @@ -1343,6 +1367,8 @@ "@js-joda/core": ["@js-joda/core@5.7.0", "", {}, "sha512-WBu4ULVVxySLLzK1Ppq+OdfP+adRS4ntmDQT915rzDJ++i95gc2jZkM5B6LWEAwN3lGXpfie3yPABozdD3K3Vg=="], + "@js-sdsl/ordered-map": ["@js-sdsl/ordered-map@4.4.2", "", {}, "sha512-iUKgm52T8HOE/makSxjqoWhe95ZJA1/G1sYsGev2JDKUSS14KAgg1LHb+Ba+IPow0xflbnSkOsZcO08C7w1gYw=="], + "@js-temporal/polyfill": ["@js-temporal/polyfill@0.5.1", "", { "dependencies": { "jsbi": "^4.3.0" } }, "sha512-hloP58zRVCRSpgDxmqCWJNlizAlUgJFqG2ypq79DCvyv9tHjRYMDOcPFjzfl/A1/YxDvRCZz8wvZvmapQnKwFQ=="], "@jsdevtools/ono": ["@jsdevtools/ono@7.1.3", "", {}, "sha512-4JQNk+3mVzK3xh2rqd6RB4J46qUR19azEHBneZyTZM+c456qOrbbM/5xcR8huNCCcbVt7+UmizG6GuUvPvKUYg=="], @@ -1573,22 +1599,54 @@ "@opentelemetry/api-logs": ["@opentelemetry/api-logs@0.214.0", "", { "dependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-40lSJeqYO8Uz2Yj7u94/SJWE/wONa7rmMKjI1ZcIjgf3MHNHv1OZUCrCETGuaRF62d5pQD1wKIW+L4lmSMTzZA=="], + "@opentelemetry/configuration": ["@opentelemetry/configuration@0.214.0", "", { "dependencies": { "@opentelemetry/core": "2.6.1", "yaml": "^2.0.0" }, "peerDependencies": { "@opentelemetry/api": "^1.9.0" } }, "sha512-Q+awuEwxhETwIAXuxHvIY5ZMEP0ZqvxLTi9kclrkyVJppEUXYL3Bhiw3jYrxdHYMh0Y0tVInQH9FEZ1aMinvLA=="], + "@opentelemetry/context-async-hooks": ["@opentelemetry/context-async-hooks@2.6.1", "", { "peerDependencies": { "@opentelemetry/api": ">=1.0.0 <1.10.0" } }, "sha512-XHzhwRNkBpeP8Fs/qjGrAf9r9PRv67wkJQ/7ZPaBQQ68DYlTBBx5MF9LvPx7mhuXcDessKK2b+DcxqwpgkcivQ=="], "@opentelemetry/core": ["@opentelemetry/core@2.6.1", "", { "dependencies": { "@opentelemetry/semantic-conventions": "^1.29.0" }, "peerDependencies": { "@opentelemetry/api": ">=1.0.0 <1.10.0" } }, "sha512-8xHSGWpJP9wBxgBpnqGL0R3PbdWQndL1Qp50qrg71+B28zK5OQmUgcDKLJgzyAAV38t4tOyLMGDD60LneR5W8g=="], + "@opentelemetry/exporter-logs-otlp-grpc": ["@opentelemetry/exporter-logs-otlp-grpc@0.214.0", "", { "dependencies": { "@grpc/grpc-js": "^1.14.3", "@opentelemetry/core": "2.6.1", "@opentelemetry/otlp-exporter-base": "0.214.0", "@opentelemetry/otlp-grpc-exporter-base": "0.214.0", "@opentelemetry/otlp-transformer": "0.214.0", "@opentelemetry/sdk-logs": "0.214.0" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-SwmFRwO8mi6nndzbsjPgSFg7qy1WeNHRFD+s6uCsdiUDUt3+yzI2qiHE3/ub2f37+/CbeGcG+Ugc8Gwr6nu2Aw=="], + + "@opentelemetry/exporter-logs-otlp-http": ["@opentelemetry/exporter-logs-otlp-http@0.214.0", "", { "dependencies": { "@opentelemetry/api-logs": "0.214.0", "@opentelemetry/core": "2.6.1", "@opentelemetry/otlp-exporter-base": "0.214.0", "@opentelemetry/otlp-transformer": "0.214.0", "@opentelemetry/sdk-logs": "0.214.0" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-9qv2Tl/Hq6qc5pJCbzFJnzA0uvlb9DgM70yGJPYf3bA5LlLkRCpcn81i4JbcIH4grlQIWY6A+W7YG0LLvS1BAw=="], + + "@opentelemetry/exporter-logs-otlp-proto": ["@opentelemetry/exporter-logs-otlp-proto@0.214.0", "", { "dependencies": { "@opentelemetry/api-logs": "0.214.0", "@opentelemetry/core": "2.6.1", "@opentelemetry/otlp-exporter-base": "0.214.0", "@opentelemetry/otlp-transformer": "0.214.0", "@opentelemetry/resources": "2.6.1", "@opentelemetry/sdk-logs": "0.214.0", "@opentelemetry/sdk-trace-base": "2.6.1" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-IWAVvCO1TlpotRjFmhQFz9RSfQy5BsLtDRBtptSrXZRwfyRPpuql/RMe5zdmu0Gxl3ERDFwOzOqkf3bwy7Jzcw=="], + + "@opentelemetry/exporter-metrics-otlp-grpc": ["@opentelemetry/exporter-metrics-otlp-grpc@0.214.0", "", { "dependencies": { "@grpc/grpc-js": "^1.14.3", "@opentelemetry/core": "2.6.1", "@opentelemetry/exporter-metrics-otlp-http": "0.214.0", "@opentelemetry/otlp-exporter-base": "0.214.0", "@opentelemetry/otlp-grpc-exporter-base": "0.214.0", "@opentelemetry/otlp-transformer": "0.214.0", "@opentelemetry/resources": "2.6.1", "@opentelemetry/sdk-metrics": "2.6.1" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-0NGxWHVYHgbp51SEzmsP+Hdups81eRs229STcSWHo3WO0aqY6RpJ9csxfyEtFgaNrBDv6UfOh0je4ss/ROS6XA=="], + + "@opentelemetry/exporter-metrics-otlp-http": ["@opentelemetry/exporter-metrics-otlp-http@0.214.0", "", { "dependencies": { "@opentelemetry/core": "2.6.1", "@opentelemetry/otlp-exporter-base": "0.214.0", "@opentelemetry/otlp-transformer": "0.214.0", "@opentelemetry/resources": "2.6.1", "@opentelemetry/sdk-metrics": "2.6.1" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-Tx/59RmjBgkXJ3qnsD04rpDrVWL53LU/czpgLJh+Ab98nAroe91I7vZ3uGN9mxwPS0jsZEnmqmHygVwB2vRMlA=="], + + "@opentelemetry/exporter-metrics-otlp-proto": ["@opentelemetry/exporter-metrics-otlp-proto@0.214.0", "", { "dependencies": { "@opentelemetry/core": "2.6.1", "@opentelemetry/exporter-metrics-otlp-http": "0.214.0", "@opentelemetry/otlp-exporter-base": "0.214.0", "@opentelemetry/otlp-transformer": "0.214.0", "@opentelemetry/resources": "2.6.1", "@opentelemetry/sdk-metrics": "2.6.1" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-pJIcghFGhx3VSCgP5U+yZx+OMNj0t+ttnhC8IjL5Wza7vWIczctF6t3AGcVQffi2dEqX+ZHANoBwoPR8y6RMKA=="], + + "@opentelemetry/exporter-prometheus": ["@opentelemetry/exporter-prometheus@0.214.0", "", { "dependencies": { "@opentelemetry/core": "2.6.1", "@opentelemetry/resources": "2.6.1", "@opentelemetry/sdk-metrics": "2.6.1", "@opentelemetry/semantic-conventions": "^1.29.0" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-4TGYoZKebUWVuYkV6r5wS2dUF4zH7EbWFw/Uqz1ZM1tGHQeFT9wzHGXq3iSIXMUrwu5jRdxjfMaXrYejPu2kpQ=="], + + "@opentelemetry/exporter-trace-otlp-grpc": ["@opentelemetry/exporter-trace-otlp-grpc@0.214.0", "", { "dependencies": { "@grpc/grpc-js": "^1.14.3", "@opentelemetry/core": "2.6.1", "@opentelemetry/otlp-exporter-base": "0.214.0", "@opentelemetry/otlp-grpc-exporter-base": "0.214.0", "@opentelemetry/otlp-transformer": "0.214.0", "@opentelemetry/resources": "2.6.1", "@opentelemetry/sdk-trace-base": "2.6.1" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-FWRZ7AWoTryYhthralHkfXUuyO3l7cRsnr49WcDio1orl2a7KxT8aDZdwQtV1adzoUvZ9Gfo+IstElghCS4zfw=="], + "@opentelemetry/exporter-trace-otlp-http": ["@opentelemetry/exporter-trace-otlp-http@0.214.0", "", { "dependencies": { "@opentelemetry/core": "2.6.1", "@opentelemetry/otlp-exporter-base": "0.214.0", "@opentelemetry/otlp-transformer": "0.214.0", "@opentelemetry/resources": "2.6.1", "@opentelemetry/sdk-trace-base": "2.6.1" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-kIN8nTBMgV2hXzV/a20BCFilPZdAIMYYJGSgfMMRm/Xa+07y5hRDS2Vm12A/z8Cdu3Sq++ZvJfElokX2rkgGgw=="], + "@opentelemetry/exporter-trace-otlp-proto": ["@opentelemetry/exporter-trace-otlp-proto@0.214.0", "", { "dependencies": { "@opentelemetry/core": "2.6.1", "@opentelemetry/otlp-exporter-base": "0.214.0", "@opentelemetry/otlp-transformer": "0.214.0", "@opentelemetry/resources": "2.6.1", "@opentelemetry/sdk-trace-base": "2.6.1" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-ON0spYWb2yAdQ9b+ItNyK0c6qdtcs+0eVR4YFJkhJL7agfT8sHFg0e5EesauSRiTHPZHiDobI92k77q0lwAmqg=="], + + "@opentelemetry/exporter-zipkin": ["@opentelemetry/exporter-zipkin@2.6.1", "", { "dependencies": { "@opentelemetry/core": "2.6.1", "@opentelemetry/resources": "2.6.1", "@opentelemetry/sdk-trace-base": "2.6.1", "@opentelemetry/semantic-conventions": "^1.29.0" }, "peerDependencies": { "@opentelemetry/api": "^1.0.0" } }, "sha512-km2/hD3inLTqtLnUAHDGz7ZP/VOyZNslrC/iN66x4jkmpckwlONW54LRPNI6fm09/musDtZga9EWsxgwnjGUlw=="], + + "@opentelemetry/instrumentation": ["@opentelemetry/instrumentation@0.214.0", "", { "dependencies": { "@opentelemetry/api-logs": "0.214.0", "import-in-the-middle": "^3.0.0", "require-in-the-middle": "^8.0.0" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-MHqEX5Dk59cqVah5LiARMACku7jXSVk9iVDWOea4x3cr7VfdByeDCURK6o1lntT1JS/Tsovw01UJrBhN3/uC5w=="], + "@opentelemetry/otlp-exporter-base": ["@opentelemetry/otlp-exporter-base@0.214.0", "", { "dependencies": { "@opentelemetry/core": "2.6.1", "@opentelemetry/otlp-transformer": "0.214.0" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-u1Gdv0/E9wP+apqWf7Wv2npXmgJtxsW2XL0TEv9FZloTZRuMBKmu8cYVXwS4Hm3q/f/3FuCnPTgiwYvIqRSpRg=="], + "@opentelemetry/otlp-grpc-exporter-base": ["@opentelemetry/otlp-grpc-exporter-base@0.214.0", "", { "dependencies": { "@grpc/grpc-js": "^1.14.3", "@opentelemetry/core": "2.6.1", "@opentelemetry/otlp-exporter-base": "0.214.0", "@opentelemetry/otlp-transformer": "0.214.0" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-IDP6zcyA24RhNZ289MP6eToIZcinlmirHjX8v3zKCQ2ZhPpt5cGwkN91tCth337lqHIgWcTy90uKRiX/SzALDw=="], + "@opentelemetry/otlp-transformer": ["@opentelemetry/otlp-transformer@0.214.0", "", { "dependencies": { "@opentelemetry/api-logs": "0.214.0", "@opentelemetry/core": "2.6.1", "@opentelemetry/resources": "2.6.1", "@opentelemetry/sdk-logs": "0.214.0", "@opentelemetry/sdk-metrics": "2.6.1", "@opentelemetry/sdk-trace-base": "2.6.1", "protobufjs": "^7.0.0" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-DSaYcuBRh6uozfsWN3R8HsN0yDhCuWP7tOFdkUOVaWD1KVJg8m4qiLUsg/tNhTLS9HUYUcwNpwL2eroLtsZZ/w=="], + "@opentelemetry/propagator-b3": ["@opentelemetry/propagator-b3@2.6.1", "", { "dependencies": { "@opentelemetry/core": "2.6.1" }, "peerDependencies": { "@opentelemetry/api": ">=1.0.0 <1.10.0" } }, "sha512-Dvz9TA6cPqIbxolSzQ5x9br6iQlqdGhVYrm+oYc7pfJ7LaVXz8F0XIqhWbnKB5YvfZ6SUmabBUUxnvHs/9uhxA=="], + + "@opentelemetry/propagator-jaeger": ["@opentelemetry/propagator-jaeger@2.6.1", "", { "dependencies": { "@opentelemetry/core": "2.6.1" }, "peerDependencies": { "@opentelemetry/api": ">=1.0.0 <1.10.0" } }, "sha512-kKFMxBcjBZAC1vBch5mtZ/dJQvcAEKWga+c+q5iGgRLPIE6Mc649zEwMaCIQCzalziMJQiyUadFYMHmELB7AFw=="], + "@opentelemetry/resources": ["@opentelemetry/resources@2.6.1", "", { "dependencies": { "@opentelemetry/core": "2.6.1", "@opentelemetry/semantic-conventions": "^1.29.0" }, "peerDependencies": { "@opentelemetry/api": ">=1.3.0 <1.10.0" } }, "sha512-lID/vxSuKWXM55XhAKNoYXu9Cutoq5hFdkbTdI/zDKQktXzcWBVhNsOkiZFTMU9UtEWuGRNe0HUgmsFldIdxVA=="], "@opentelemetry/sdk-logs": ["@opentelemetry/sdk-logs@0.214.0", "", { "dependencies": { "@opentelemetry/api-logs": "0.214.0", "@opentelemetry/core": "2.6.1", "@opentelemetry/resources": "2.6.1", "@opentelemetry/semantic-conventions": "^1.29.0" }, "peerDependencies": { "@opentelemetry/api": ">=1.4.0 <1.10.0" } }, "sha512-zf6acnScjhsaBUU22zXZ/sLWim1dfhUAbGXdMmHmNG3LfBnQ3DKsOCITb2IZwoUsNNMTogqFKBnlIPPftUgGwA=="], "@opentelemetry/sdk-metrics": ["@opentelemetry/sdk-metrics@2.6.1", "", { "dependencies": { "@opentelemetry/core": "2.6.1", "@opentelemetry/resources": "2.6.1" }, "peerDependencies": { "@opentelemetry/api": ">=1.9.0 <1.10.0" } }, "sha512-9t9hJHX15meBy2NmTJxL+NJfXmnausR2xUDvE19XQce0Qi/GBtDGamU8nS1RMbdgDmhgpm3VaOu2+fiS/SfTpQ=="], + "@opentelemetry/sdk-node": ["@opentelemetry/sdk-node@0.214.0", "", { "dependencies": { "@opentelemetry/api-logs": "0.214.0", "@opentelemetry/configuration": "0.214.0", "@opentelemetry/context-async-hooks": "2.6.1", "@opentelemetry/core": "2.6.1", "@opentelemetry/exporter-logs-otlp-grpc": "0.214.0", "@opentelemetry/exporter-logs-otlp-http": "0.214.0", "@opentelemetry/exporter-logs-otlp-proto": "0.214.0", "@opentelemetry/exporter-metrics-otlp-grpc": "0.214.0", "@opentelemetry/exporter-metrics-otlp-http": "0.214.0", "@opentelemetry/exporter-metrics-otlp-proto": "0.214.0", "@opentelemetry/exporter-prometheus": "0.214.0", "@opentelemetry/exporter-trace-otlp-grpc": "0.214.0", "@opentelemetry/exporter-trace-otlp-http": "0.214.0", "@opentelemetry/exporter-trace-otlp-proto": "0.214.0", "@opentelemetry/exporter-zipkin": "2.6.1", "@opentelemetry/instrumentation": "0.214.0", "@opentelemetry/otlp-exporter-base": "0.214.0", "@opentelemetry/propagator-b3": "2.6.1", "@opentelemetry/propagator-jaeger": "2.6.1", "@opentelemetry/resources": "2.6.1", "@opentelemetry/sdk-logs": "0.214.0", "@opentelemetry/sdk-metrics": "2.6.1", "@opentelemetry/sdk-trace-base": "2.6.1", "@opentelemetry/sdk-trace-node": "2.6.1", "@opentelemetry/semantic-conventions": "^1.29.0" }, "peerDependencies": { "@opentelemetry/api": ">=1.3.0 <1.10.0" } }, "sha512-gl2XvQBJuPjhGcw9SsnQO5qxChAPMuGRPFaD8lqtF+Cey91NgGUQ0sio2vlDFOSm3JOLzc44vL+OAfx1dXuZjg=="], + "@opentelemetry/sdk-trace-base": ["@opentelemetry/sdk-trace-base@2.6.1", "", { "dependencies": { "@opentelemetry/core": "2.6.1", "@opentelemetry/resources": "2.6.1", "@opentelemetry/semantic-conventions": "^1.29.0" }, "peerDependencies": { "@opentelemetry/api": ">=1.3.0 <1.10.0" } }, "sha512-r86ut4T1e8vNwB35CqCcKd45yzqH6/6Wzvpk2/cZB8PsPLlZFTvrh8yfOS3CYZYcUmAx4hHTZJ8AO8Dj8nrdhw=="], "@opentelemetry/sdk-trace-node": ["@opentelemetry/sdk-trace-node@2.6.1", "", { "dependencies": { "@opentelemetry/context-async-hooks": "2.6.1", "@opentelemetry/core": "2.6.1", "@opentelemetry/sdk-trace-base": "2.6.1" }, "peerDependencies": { "@opentelemetry/api": ">=1.0.0 <1.10.0" } }, "sha512-Hh2i4FwHWRFhnO2Q/p6svMxy8MPsNCG0uuzUY3glqm0rwM0nQvbTO1dXSp9OqQoTKXcQzaz9q1f65fsurmOhNw=="], @@ -2495,6 +2553,8 @@ "acorn": ["acorn@8.16.0", "", { "bin": { "acorn": "bin/acorn" } }, "sha512-UVJyE9MttOsBQIDKw1skb9nAwQuR5wuGD3+82K6JgJlm/Y+KI92oNsMNGZCYdDsVtRHSak0pcV5Dno5+4jh9sw=="], + "acorn-import-attributes": ["acorn-import-attributes@1.9.5", "", { "peerDependencies": { "acorn": "^8" } }, "sha512-n02Vykv5uA3eHGM/Z2dQrcD56kL8TyDb2p1+0P83PClMnC/nc+anbQRhIOWnSq4Ke/KvDPrY3C9hDtC/A3eHnQ=="], + "acorn-jsx": ["acorn-jsx@5.3.2", "", { "peerDependencies": { "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ=="], "acorn-walk": ["acorn-walk@8.3.2", "", {}, "sha512-cjkyv4OtNCIeqhHrfS81QWXoCBPExR/J62oyEqepVw8WaQeSqpW2uhuLPh1m9eWhDuOo/jUXVTlifvesOWp/4A=="], @@ -2777,6 +2837,8 @@ "citty": ["citty@0.1.6", "", { "dependencies": { "consola": "^3.2.3" } }, "sha512-tskPPKEs8D2KPafUypv2gxwJP8h/OaJmC82QQGGDQcHvXX43xF2VDACcJVmZ0EuSxkpO9Kc4MlrA3q0+FG58AQ=="], + "cjs-module-lexer": ["cjs-module-lexer@2.2.0", "", {}, "sha512-4bHTS2YuzUvtoLjdy+98ykbNB5jS0+07EvFNXerqZQJ89F7DI6ET7OQo/HJuW6K0aVsKA9hj9/RVb2kQVOrPDQ=="], + "classnames": ["classnames@2.3.2", "", {}, "sha512-CSbhY4cFEJRe6/GQzIk5qXZ4Jeg5pcsP7b5peFSDpffpe1cqjASH/n9UTjBwOp6XpMSTwQ8Za2K5V02ueA7Tmw=="], "clean-css": ["clean-css@5.3.3", "", { "dependencies": { "source-map": "~0.6.0" } }, "sha512-D5J+kHaVb/wKSFcyyV75uCn8fiY4sV38XJoe4CUyGQ+mOU/fMVYUdH1hJC+CJQ5uY3EnW27SbJYS4X8BiLrAFg=="], @@ -3453,6 +3515,8 @@ "immer": ["immer@11.1.4", "", {}, "sha512-XREFCPo6ksxVzP4E0ekD5aMdf8WMwmdNaz6vuvxgI40UaEiu6q3p8X52aU6GdyvLY3XXX/8R7JOTXStz/nBbRw=="], + "import-in-the-middle": ["import-in-the-middle@3.0.1", "", { "dependencies": { "acorn": "^8.15.0", "acorn-import-attributes": "^1.9.5", "cjs-module-lexer": "^2.2.0", "module-details-from-path": "^1.0.4" } }, "sha512-pYkiyXVL2Mf3pozdlDGV6NAObxQx13Ae8knZk1UJRJ6uRW/ZRmTGHlQYtrsSl7ubuE5F8CD1z+s1n4RHNuTtuA=="], + "import-local": ["import-local@3.2.0", "", { "dependencies": { "pkg-dir": "^4.2.0", "resolve-cwd": "^3.0.0" }, "bin": { "import-local-fixture": "fixtures/cli.js" } }, "sha512-2SPlun1JUPWoM6t3F0dw0FkCF/jWY8kttcY4f599GLTSjh2OCuuhdTkJQsEcZzBqbXZGKMK2OqW1oZsjtf/gQA=="], "import-meta-resolve": ["import-meta-resolve@4.2.0", "", {}, "sha512-Iqv2fzaTQN28s/FwZAoFq0ZSs/7hMAHJVX+w8PZl3cY19Pxk6jFFalxQoIfW2826i/fDLXv8IiEZRIT0lDuWcg=="], @@ -3715,6 +3779,8 @@ "lodash": ["lodash@4.18.1", "", {}, "sha512-dMInicTPVE8d1e5otfwmmjlxkZoUpiVLwyeTdUsi/Caj/gfzzblBcCE5sRHV/AsjuCmxWrte2TNGSYuCeCq+0Q=="], + "lodash.camelcase": ["lodash.camelcase@4.3.0", "", {}, "sha512-TwuEnCnxbc3rAvhf/LbG7tJUDzhqXyFnv3dtzLOPgCG/hODL7WFnsbwktkD7yUV0RrreP/l1PALq/YSg6VvjlA=="], + "lodash.defaults": ["lodash.defaults@4.2.0", "", {}, "sha512-qjxPLHd3r5DnsdGacqOMU6pb/avJzdh9tFX2ymgoZE27BmjXrNy/y4LoaiTeAb+O3gL8AfpJGtqfX/ae2leYYQ=="], "lodash.escaperegexp": ["lodash.escaperegexp@4.1.2", "", {}, "sha512-TM9YBvyC84ZxE3rgfefxUWiQKLilstD6k7PTGt6wfbtXF8ixIJLOL3VYyV/z+ZiPLsVxAsKAFVwWlWeb2Y8Yyw=="], @@ -3945,6 +4011,8 @@ "mkdirp": ["mkdirp@0.5.6", "", { "dependencies": { "minimist": "^1.2.6" }, "bin": { "mkdirp": "bin/cmd.js" } }, "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw=="], + "module-details-from-path": ["module-details-from-path@1.0.4", "", {}, "sha512-EGWKgxALGMgzvxYF1UyGTy0HXX/2vHLkw6+NvDKW2jypWbHpjQuj4UMcqQWXHERJhVGKikolT06G3bcKe4fi7w=="], + "morphdom": ["morphdom@2.7.8", "", {}, "sha512-D/fR4xgGUyVRbdMGU6Nejea1RFzYxYtyurG4Fbv2Fi/daKlWKuXGLOdXtl+3eIwL110cI2hz1ZojGICjjFLgTg=="], "motion": ["motion@12.34.5", "", { "dependencies": { "framer-motion": "^12.34.5", "tslib": "^2.4.0" }, "peerDependencies": { "@emotion/is-prop-valid": "*", "react": "^18.0.0 || ^19.0.0", "react-dom": "^18.0.0 || ^19.0.0" }, "optionalPeers": ["@emotion/is-prop-valid", "react", "react-dom"] }, "sha512-N06NLJ9IeBHeielRqIvYvjPfXuRdyTxa+9++BgpGa+hY2D7TcMkI6QzV3jaRuv0aZRXgMa7cPy9YcBUBisPzAQ=="], @@ -4429,6 +4497,8 @@ "require-from-string": ["require-from-string@2.0.2", "", {}, "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw=="], + "require-in-the-middle": ["require-in-the-middle@8.0.1", "", { "dependencies": { "debug": "^4.3.5", "module-details-from-path": "^1.0.3" } }, "sha512-QT7FVMXfWOYFbeRBF6nu+I6tr2Tf3u0q8RIEjNob/heKY/nh7drD/k7eeMFmSQgnTtCzLDcCu/XEnpW2wk4xCQ=="], + "resedit": ["resedit@1.7.2", "", { "dependencies": { "pe-library": "^0.4.1" } }, "sha512-vHjcY2MlAITJhC0eRD/Vv8Vlgmu9Sd3LX9zZvtGzU5ZImdTN3+d6e/4mnTyV8vEbyf1sgNIrWxhWlrys52OkEA=="], "reselect": ["reselect@4.1.8", "", {}, "sha512-ab9EmR80F/zQTMNeneUr4cv+jSwPJgIlvEmVwLerwrWVbpLlBuls9XHzIeTFy4cegU2NHBp3va0LKOzU5qFEYQ=="], @@ -5417,6 +5487,8 @@ "@gitlab/opencode-gitlab-auth/open": ["open@10.2.0", "", { "dependencies": { "default-browser": "^5.2.1", "define-lazy-prop": "^3.0.0", "is-inside-container": "^1.0.0", "wsl-utils": "^0.1.0" } }, "sha512-YgBpdJHPyQ2UE5x+hlSXcnejzAvD0b22U2OuAP+8OnlJT+PjWPxtgmGqKKc+RgTM63U9gN0YzrYc71R2WT/hTA=="], + "@grpc/proto-loader/yargs": ["yargs@17.7.2", "", { "dependencies": { "cliui": "^8.0.1", "escalade": "^3.1.1", "get-caller-file": "^2.0.5", "require-directory": "^2.1.1", "string-width": "^4.2.3", "y18n": "^5.0.5", "yargs-parser": "^21.1.1" } }, "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w=="], + "@happy-dom/global-registrator/@types/node": ["@types/node@22.13.9", "", { "dependencies": { "undici-types": "~6.20.0" } }, "sha512-acBjXdRJ3A6Pb3tqnw9HZmyR3Fiol3aGxRCK1x3d+6CDAMjl7I649wpSd+yNURCjbOUGu9tqtLKnTGxmK6CyGw=="], "@hey-api/json-schema-ref-parser/js-yaml": ["js-yaml@4.1.1", "", { "dependencies": { "argparse": "^2.0.1" }, "bin": { "js-yaml": "bin/js-yaml.js" } }, "sha512-qQKT4zQxXl8lLwBtHMWwaTcGfFOZviOJet3Oy/xmGk2gZH677CJM9EvtfdSkgWcATZhj/55JZ0rmy3myCT5lsA=="], @@ -6443,6 +6515,12 @@ "@expressive-code/plugin-shiki/shiki/@shikijs/types": ["@shikijs/types@3.23.0", "", { "dependencies": { "@shikijs/vscode-textmate": "^10.0.2", "@types/hast": "^3.0.4" } }, "sha512-3JZ5HXOZfYjsYSk0yPwBrkupyYSLpAE26Qc0HLghhZNGTZg/SKxXIIgoxOpmmeQP0RRSDJTk1/vPfw9tbw+jSQ=="], + "@grpc/proto-loader/yargs/cliui": ["cliui@8.0.1", "", { "dependencies": { "string-width": "^4.2.0", "strip-ansi": "^6.0.1", "wrap-ansi": "^7.0.0" } }, "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ=="], + + "@grpc/proto-loader/yargs/string-width": ["string-width@4.2.3", "", { "dependencies": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", "strip-ansi": "^6.0.1" } }, "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g=="], + + "@grpc/proto-loader/yargs/yargs-parser": ["yargs-parser@21.1.1", "", {}, "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw=="], + "@happy-dom/global-registrator/@types/node/undici-types": ["undici-types@6.20.0", "", {}, "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg=="], "@hey-api/json-schema-ref-parser/js-yaml/argparse": ["argparse@2.0.1", "", {}, "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q=="], @@ -7063,6 +7141,14 @@ "@electron/universal/minimatch/brace-expansion/balanced-match": ["balanced-match@1.0.2", "", {}, "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw=="], + "@grpc/proto-loader/yargs/cliui/strip-ansi": ["strip-ansi@6.0.1", "", { "dependencies": { "ansi-regex": "^5.0.1" } }, "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A=="], + + "@grpc/proto-loader/yargs/cliui/wrap-ansi": ["wrap-ansi@7.0.0", "", { "dependencies": { "ansi-styles": "^4.0.0", "string-width": "^4.1.0", "strip-ansi": "^6.0.0" } }, "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q=="], + + "@grpc/proto-loader/yargs/string-width/emoji-regex": ["emoji-regex@8.0.0", "", {}, "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A=="], + + "@grpc/proto-loader/yargs/string-width/strip-ansi": ["strip-ansi@6.0.1", "", { "dependencies": { "ansi-regex": "^5.0.1" } }, "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A=="], + "@jsx-email/cli/tailwindcss/chokidar/glob-parent": ["glob-parent@5.1.2", "", { "dependencies": { "is-glob": "^4.0.1" } }, "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow=="], "@jsx-email/cli/tailwindcss/chokidar/readdirp": ["readdirp@3.6.0", "", { "dependencies": { "picomatch": "^2.2.1" } }, "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA=="], @@ -7281,6 +7367,10 @@ "@electron/rebuild/yargs/string-width/strip-ansi/ansi-regex": ["ansi-regex@5.0.1", "", {}, "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ=="], + "@grpc/proto-loader/yargs/cliui/strip-ansi/ansi-regex": ["ansi-regex@5.0.1", "", {}, "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ=="], + + "@grpc/proto-loader/yargs/string-width/strip-ansi/ansi-regex": ["ansi-regex@5.0.1", "", {}, "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ=="], + "@jsx-email/cli/tailwindcss/chokidar/readdirp/picomatch": ["picomatch@2.3.2", "", {}, "sha512-V7+vQEJ06Z+c5tSye8S+nHUfI51xoXIXjHQ99cQtKUkQqqO1kO/KCJUfZXuB47h/YBlDhah2H3hdUGXn8ie0oA=="], "@sentry/bundler-plugin-core/glob/minimatch/brace-expansion/balanced-match": ["balanced-match@1.0.2", "", {}, "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw=="], diff --git a/package.json b/package.json index 4e932e71d..7c8bf06cb 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "dev:console": "ulimit -n 10240 2>/dev/null; bun run --cwd packages/console/app dev", "dev:storybook": "bun --cwd packages/storybook storybook", "lint": "oxlint", - "typecheck": "bun turbo typecheck --filter='@browser-use/browsercode-core...' --filter='@browser-use/bcode-browser'", + "typecheck": "bun turbo typecheck --filter='@browser-use/browsercode-core...' --filter='@browser-use/bcode-browser' --filter='@browser-use/bcode-laminar'", "postinstall": "bun run --cwd packages/opencode fix-node-pty", "prepare": "husky", "random": "echo 'Random script'", diff --git a/packages/bcode-browser/src/telemetry.ts b/packages/bcode-browser/src/telemetry.ts index fcb078d16..fee09c382 100644 --- a/packages/bcode-browser/src/telemetry.ts +++ b/packages/bcode-browser/src/telemetry.ts @@ -14,12 +14,20 @@ // wins; explicit empty string is respected as "no key please"), AND // - the embedded default is non-empty. // -// `applyTelemetryKey()` is invoked as a side effect on module import (last -// statement of this file). Because `packages/opencode/src/index.ts` imports -// this module before any other module that might consume the env var, the -// gate is guaranteed to run before any downstream module-load code can -// observe `LMNR_PROJECT_API_KEY` — sidestepping ESM static-import hoisting -// entirely. +// No `if (telemetryEnabled)` branches downstream — `@browser-use/bcode-laminar` +// reads `LMNR_PROJECT_API_KEY` and initializes only when present, so the gate +// here decides everything. +// +// `applyTelemetryKey()` is invoked as a side effect on module import (bottom +// of this file). `packages/opencode/src/index.ts` imports this module before +// any other import; ESM evaluates an imported module's side effects before +// continuing to the next import, so the gate is unambiguously ordered before +// any downstream module-load code that might read `LMNR_PROJECT_API_KEY` — +// sidestepping the static-import hoisting concern. + +import { mkdirSync } from "fs" +import { homedir } from "os" +import { dirname, join } from "path" declare const BCODE_DEFAULT_LMNR_KEY: string @@ -34,6 +42,35 @@ export const applyTelemetryKey = () => { // undeclared and a direct read throws ReferenceError. if (typeof BCODE_DEFAULT_LMNR_KEY === "undefined" || !BCODE_DEFAULT_LMNR_KEY) return process.env.LMNR_PROJECT_API_KEY = BCODE_DEFAULT_LMNR_KEY + showFirstRunNoticeOnce() +} + +// Industry-standard short notice: one line stating what happens and how to +// opt out. Prints once; subsequent launches stay quiet. +// +// Uses XDG_STATE_HOME / ~/.local/state on Linux, %LOCALAPPDATA% on Windows, +// ~/Library/Application Support on macOS. Resolved without importing +// @opencode-ai/core/global since this runs before that module loads. +const showFirstRunNoticeOnce = () => { + const marker = join(stateDir(), "bcode", "telemetry-notice-shown") + if (Bun.file(marker).size > 0) return + process.stderr.write( + "BrowserCode sends anonymous usage traces. Set DO_NOT_TRACK=1 to opt out.\n", + ) + try { + mkdirSync(dirname(marker), { recursive: true }) + } catch {} + Bun.write(marker, "1\n").catch(() => {}) +} + +const stateDir = () => { + if (process.platform === "win32") { + return process.env.LOCALAPPDATA ?? join(homedir(), "AppData", "Local") + } + if (process.platform === "darwin") { + return join(homedir(), "Library", "Application Support") + } + return process.env.XDG_STATE_HOME ?? join(homedir(), ".local", "state") } // Run as an import side effect: this module is imported as the very first diff --git a/packages/bcode-laminar/LICENSE b/packages/bcode-laminar/LICENSE new file mode 100644 index 000000000..bddbfc0dc --- /dev/null +++ b/packages/bcode-laminar/LICENSE @@ -0,0 +1,75 @@ + + +Apache License +Version 2.0, January 2004 +http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. + +"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: + + You must give any other recipients of the Work or Derivative Works a copy of this License; and + You must cause any modified files to carry prominent notices stating that You changed the files; and + You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and + If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. + +You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + + +APPENDIX: How to apply the Apache License to your work + +Include a copy of the Apache License, typically in a file called LICENSE, in your work, and consider also including a NOTICE file that references the License. + +To apply the Apache License to specific files in your work, attach the following boilerplate declaration, replacing the fields enclosed by brackets "[]" with your own identifying information. (Don't include the brackets!) Enclose the text in the appropriate comment syntax for the file format. We also recommend that you include a file or class name and description of purpose on the same "printed page" as the copyright notice for easier identification within third-party archives. + +Copyright 2024 LMNR AI, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/packages/bcode-laminar/VENDOR.md b/packages/bcode-laminar/VENDOR.md new file mode 100644 index 000000000..4d9718ef3 --- /dev/null +++ b/packages/bcode-laminar/VENDOR.md @@ -0,0 +1,56 @@ +# Vendor record — @browser-use/bcode-laminar + +This package is a vendored, trimmed combination of two upstream sources, both +licensed Apache-2.0. Pulled once on **2026-05-02**; we do not maintain a +recurring sync — Laminar's plugin shape changes rarely, and the OpenTelemetry +contract is stable. Re-pull only when a behavior fix or new attribute is +worth chasing. + +## Sources + +| Upstream | Commit | License | +|---|---|---| +| [`lmnr-ai/lmnr-opencode-plugin`](https://github.com/lmnr-ai/lmnr-opencode-plugin) | `bb2fceaff0d2b52161fb1c8a477a50b0b4789a0e` (v0.1.2) | Apache-2.0 | +| [`lmnr-ai/lmnr-ts`](https://github.com/lmnr-ai/lmnr-ts) (selected files from `packages/lmnr/src/opentelemetry-lib/`) | `5ebe07a6284ce0bbfebcf10bdd9d1faa04ed6c64` (v0.8.22) | Apache-2.0 | + +## File mapping + +| `src/.ts` | Upstream origin | +|---|---| +| `plugin.ts` | `lmnr-opencode-plugin/src/index.ts` | +| `processor.ts` | merged: `lmnr-opencode-plugin/src/processor.ts` + base class from `lmnr-ts/.../tracing/processor.ts` | +| `exporter.ts` | `lmnr-ts/.../tracing/exporter.ts` | +| `span.ts` | `Laminar.startSpan` extracted from `lmnr-ts/src/laminar.ts` | +| `attributes.ts` | `lmnr-ts/.../tracing/attributes.ts` (subset) | +| `compat.ts` | `lmnr-ts/.../tracing/compat.ts` | +| `state.ts` | `lmnr-opencode-plugin/src/state.ts` (dropped `sessionExternalContexts` — TS host injection isn't relevant for bcode) | +| `utils.ts` | UUID helpers from `lmnr-ts/src/utils.ts` | + +## Behavior trims (vs upstream) + +- **No `LaminarClient` "rollout sessions"** — `LMNR_ROLLOUT_SESSION_ID` branch removed. We don't use that feature. +- **No HTTP/protobuf exporter fallback** — gRPC only. Drops `@opentelemetry/exporter-trace-otlp-proto`. +- **No `parseOtelHeaders` / `OTEL_HEADERS` resolution** — we always have a Laminar API key when emitting; OTel-env paths are dead. +- **No `pino` logger** — log via `client.app.log` (opencode-managed). +- **No `loadEnv()`** — opencode loads `.env` already; second pass would surprise users. +- **No caller-side context injection (`sessionExternalContexts`)** — bcode runs the agent locally, not driven by an external TS host. +- **`Laminar.startSpan` reduced** — only the path needed for the per-turn span (sessionId + optional parentSpanContext); no `tracingLevel`, masked-input, or process-global activation stack. + +## Behavior preserved + +- `lmnr.span.path` / `lmnr.span.ids_path` ancestor stamping (Laminar UI nests by these, not by OTel parentSpanId). +- OTel SDK v1/v2 compat shim (`makeSpanOtelV2Compatible`). +- Per-`chat.message` "turn" span lifecycle, ended on `session.idle` / `session.deleted`. +- Sub-agent tagging: spans created inside the `task` tool tag descendants with `lmnr.spawning_subagent.tool_use_id`. +- gRPC bearer-token auth to `${LMNR_BASE_URL}:${LMNR_GRPC_PORT}`. + +## Maintenance protocol + +If/when we re-pull: + +1. Clone both upstreams at the new tag. +2. Diff each vendored file against its origin; bring across only behavior changes (not stylistic / build / dep churn). +3. Update the commit hashes above; bump `version` in `package.json` only if behavior changed. +4. Re-verify the smoke flow (see PR description). + +Do not introduce a `dependencies` entry on `@lmnr-ai/lmnr` or `@lmnr-ai/opencode-plugin` — vendoring is the point. diff --git a/packages/bcode-laminar/package.json b/packages/bcode-laminar/package.json new file mode 100644 index 000000000..a6391f342 --- /dev/null +++ b/packages/bcode-laminar/package.json @@ -0,0 +1,29 @@ +{ + "$schema": "https://json.schemastore.org/package.json", + "version": "0.0.0", + "name": "@browser-use/bcode-laminar", + "description": "Vendored Laminar OpenCode tracing plugin (Apache-2.0)", + "type": "module", + "license": "Apache-2.0", + "private": true, + "scripts": { + "typecheck": "tsgo --noEmit" + }, + "exports": { + ".": "./src/index.ts", + "./*": "./src/*.ts" + }, + "dependencies": { + "@opencode-ai/plugin": "workspace:*", + "@opentelemetry/api": "1.9.0", + "@opentelemetry/sdk-node": "0.214.0", + "@opentelemetry/sdk-trace-base": "2.6.1", + "@opentelemetry/core": "2.6.1", + "@opentelemetry/exporter-trace-otlp-grpc": "0.214.0", + "@grpc/grpc-js": "1.14.3" + }, + "devDependencies": { + "@tsconfig/bun": "catalog:", + "@types/bun": "catalog:" + } +} diff --git a/packages/bcode-laminar/src/attributes.ts b/packages/bcode-laminar/src/attributes.ts new file mode 100644 index 000000000..551bea5de --- /dev/null +++ b/packages/bcode-laminar/src/attributes.ts @@ -0,0 +1,13 @@ +// Vendored from lmnr-ts/packages/lmnr/src/opentelemetry-lib/tracing/attributes.ts +// Trimmed to the constants the OpenCode plugin actually uses. + +export const SPAN_TYPE = "lmnr.span.type" +export const SPAN_INPUT = "lmnr.span.input" +export const SPAN_PATH = "lmnr.span.path" +export const SPAN_IDS_PATH = "lmnr.span.ids_path" +export const PARENT_SPAN_PATH = "lmnr.span.parent_path" +export const PARENT_SPAN_IDS_PATH = "lmnr.span.parent_ids_path" +export const SPAN_INSTRUMENTATION_SOURCE = "lmnr.span.instrumentation_source" +export const SPAN_SDK_VERSION = "lmnr.span.sdk_version" +export const ASSOCIATION_PROPERTIES = "lmnr.association.properties" +export const SESSION_ID = "lmnr.association.properties.session_id" diff --git a/packages/bcode-laminar/src/compat.ts b/packages/bcode-laminar/src/compat.ts new file mode 100644 index 000000000..0b4c36680 --- /dev/null +++ b/packages/bcode-laminar/src/compat.ts @@ -0,0 +1,61 @@ +// Vendored from lmnr-ts/packages/lmnr/src/opentelemetry-lib/tracing/compat.ts +// Bridges OTel SDK v1 (parentSpanId / instrumentationLibrary) and +// v2 (parentSpanContext / instrumentationScope). Required by the Laminar +// backend, which reads v1-shaped fields off serialized spans. + +import type { SpanContext } from "@opentelemetry/api" +import type { ReadableSpan, Span as SdkSpan } from "@opentelemetry/sdk-trace-base" + +export type OTelSpanCompat = SdkSpan & + ReadableSpan & { + parentSpanId?: string + parentSpanContext?: SpanContext + instrumentationLibrary?: any + instrumentationScope?: any + } + +type OTelReadableSpanCompat = ReadableSpan & { + parentSpanId?: string + parentSpanContext?: SpanContext + instrumentationLibrary?: any + instrumentationScope?: any +} + +export const makeSpanOtelV2Compatible = (span: OTelSpanCompat | OTelReadableSpanCompat) => { + const spanAny = span as any + if (spanAny.instrumentationScope && !spanAny.instrumentationLibrary) { + Object.assign(span, { instrumentationLibrary: spanAny.instrumentationScope }) + } else if (spanAny.instrumentationLibrary && !spanAny.instrumentationScope) { + Object.assign(span, { instrumentationScope: spanAny.instrumentationLibrary }) + } + + if (spanAny.parentSpanContext && !spanAny.parentSpanId) { + Object.defineProperty(span, "parentSpanId", { + value: spanAny.parentSpanContext.spanId, + writable: true, + enumerable: true, + configurable: true, + }) + } else if (spanAny.parentSpanId && !spanAny.parentSpanContext) { + const spanContext = span.spanContext() + Object.defineProperty(span, "parentSpanContext", { + value: { + traceId: spanContext.traceId, + spanId: spanAny.parentSpanId, + traceFlags: spanContext.traceFlags, + traceState: spanContext.traceState, + isRemote: spanContext.isRemote, + }, + writable: true, + enumerable: true, + configurable: true, + }) + } +} + +export const getParentSpanId = ( + span: OTelSpanCompat | OTelReadableSpanCompat, +): string | undefined => { + const spanAny = span as any + return spanAny.parentSpanContext?.spanId ?? spanAny.parentSpanId +} diff --git a/packages/bcode-laminar/src/exporter.ts b/packages/bcode-laminar/src/exporter.ts new file mode 100644 index 000000000..7844f1ff1 --- /dev/null +++ b/packages/bcode-laminar/src/exporter.ts @@ -0,0 +1,42 @@ +// Vendored from lmnr-ts/packages/lmnr/src/opentelemetry-lib/tracing/exporter.ts. +// Trimmed to gRPC + bearer-token only (no HTTP fallback, no OTEL_HEADERS env path). + +import { Metadata } from "@grpc/grpc-js" +import type { ExportResult } from "@opentelemetry/core" +import { OTLPTraceExporter as ExporterGrpc } from "@opentelemetry/exporter-trace-otlp-grpc" +import type { ReadableSpan, SpanExporter } from "@opentelemetry/sdk-trace-base" + +import { makeSpanOtelV2Compatible } from "./compat" + +export class LaminarSpanExporter implements SpanExporter { + private exporter: SpanExporter + + constructor(options: { + apiKey: string + baseUrl: string + port: number + timeoutMillis?: number + }) { + const url = options.baseUrl.replace(/\/$/, "").replace(/:\d{1,5}$/g, "") + const metadata = new Metadata() + metadata.set("authorization", `Bearer ${options.apiKey}`) + this.exporter = new ExporterGrpc({ + url: `${url}:${options.port}`, + metadata, + timeoutMillis: options.timeoutMillis ?? 30000, + }) + } + + export(items: ReadableSpan[], resultCallback: (result: ExportResult) => void) { + items.forEach(makeSpanOtelV2Compatible) + return this.exporter.export(items, resultCallback) + } + + async shutdown() { + return this.exporter.shutdown() + } + + async forceFlush() { + return this.exporter.forceFlush?.() + } +} diff --git a/packages/bcode-laminar/src/index.ts b/packages/bcode-laminar/src/index.ts new file mode 100644 index 000000000..b50b41d53 --- /dev/null +++ b/packages/bcode-laminar/src/index.ts @@ -0,0 +1 @@ +export { LaminarPlugin } from "./plugin" diff --git a/packages/bcode-laminar/src/plugin.ts b/packages/bcode-laminar/src/plugin.ts new file mode 100644 index 000000000..9d27a5887 --- /dev/null +++ b/packages/bcode-laminar/src/plugin.ts @@ -0,0 +1,142 @@ +// LaminarPlugin — opencode-side hook wiring. +// +// Vendored and trimmed from lmnr-opencode-plugin/src/index.ts. +// Differences vs upstream: +// - No loadEnv() — opencode loads .env / .env.local already. +// - No external-context (caller-side) injection path; we don't ship a TS host. +// - log fallback is a no-op (no console.log; the TUI owns stdout). +// +// First-run notice is intentionally short and non-alarming. Industry standard +// for telemetry disclosure is one line referencing DO_NOT_TRACK; that lives in +// README and runs once on key application via the bcode-browser telemetry +// module, not here. + +import type { Plugin } from "@opencode-ai/plugin" +import { NodeSDK } from "@opentelemetry/sdk-node" + +import { OpenCodeLaminarSpanProcessor } from "./processor" +import { startTurnSpan } from "./span" +import { sessionCurrentTurnSpan, subagentSessionIds } from "./state" + +const DEFAULT_GRPC_PORT_LMNR = 8443 +const DEFAULT_GRPC_PORT_GENERIC = 443 + +const parsePort = (raw: string | undefined, fallback: number): number => { + if (!raw) return fallback + const n = Number(raw) + return Number.isInteger(n) && n > 0 && n <= 65535 ? n : fallback +} + +export const LaminarPlugin: Plugin = ({ client }) => { + const projectApiKey = process.env.LMNR_PROJECT_API_KEY + const baseUrl = process.env.LMNR_BASE_URL ?? "https://api.lmnr.ai" + const port = parsePort( + process.env.LMNR_GRPC_PORT, + baseUrl === "https://api.lmnr.ai" ? DEFAULT_GRPC_PORT_LMNR : DEFAULT_GRPC_PORT_GENERIC, + ) + // When set, every "turn" span this plugin starts is parented under the + // given Laminar span context. Used by external evaluation harnesses that + // spawn bcode as a subprocess and want the agent's traces to nest under + // their own evaluation span (one trace per task, judge + agent siblings). + // Format: JSON serialization of LaminarSpanContext (snake_case or camelCase + // keys both accepted by parseLaminarSpanContext in span.ts). + const parentSpanContext = process.env.LMNR_PARENT_SPAN_CONTEXT + + const log = (level: "debug" | "info" | "warn" | "error", message: string) => { + client.app + .log({ body: { service: "laminar", level, message } }) + .catch(() => {}) + } + + if (!projectApiKey) return Promise.resolve({}) + + const processor = new OpenCodeLaminarSpanProcessor({ + apiKey: projectApiKey, + baseUrl, + port, + log, + }) + + const sdk = new NodeSDK({ spanProcessors: [processor] }) + sdk.start() + log("info", `Laminar tracing initialized → ${baseUrl}`) + + return Promise.resolve({ + config: async (config) => { + if (!config.experimental?.openTelemetry) { + config.experimental = { ...(config.experimental ?? {}), openTelemetry: true } + } + }, + event: async ({ event }) => { + switch (event.type) { + case "session.idle": { + const sessionId = event.properties.sessionID + const span = sessionCurrentTurnSpan[sessionId] + if (span) { + span.end() + delete sessionCurrentTurnSpan[sessionId] + } + await processor.forceFlush() + break + } + case "server.instance.disposed": { + // End any turn spans still open so they're flushed before shutdown. + for (const [sessionId, span] of Object.entries(sessionCurrentTurnSpan)) { + span.end() + delete sessionCurrentTurnSpan[sessionId] + } + for (const key of Object.keys(subagentSessionIds)) delete subagentSessionIds[key] + // sdk.shutdown() drains the inner BatchSpanProcessor and exporter + // and removes the global TracerProvider; explicit processor.shutdown() + // is redundant but harmless. + await sdk.shutdown().catch(() => {}) + break + } + case "session.created": + case "session.updated": + if (event.properties.info.parentID) { + const parentId = event.properties.info.parentID + if (!subagentSessionIds[parentId]) subagentSessionIds[parentId] = new Set() + subagentSessionIds[parentId].add(event.properties.info.id) + } + break + case "session.deleted": { + const sessionId = event.properties.info.id + const span = sessionCurrentTurnSpan[sessionId] + if (span) { + span.end() + delete sessionCurrentTurnSpan[sessionId] + } + delete subagentSessionIds[sessionId] + for (const children of Object.values(subagentSessionIds)) children.delete(sessionId) + await processor.forceFlush() + break + } + } + }, + "chat.message": async (input, output) => { + const { sessionID, agent, model, messageID, variant } = input + // Skip sub-agent prompts — their parent already has a turn span. + const isSubagent = Object.values(subagentSessionIds).some((children) => + children.has(sessionID), + ) + if (isSubagent || sessionCurrentTurnSpan[sessionID]) return + + const span = startTurnSpan({ + name: "turn", + sessionId: sessionID, + parentSpanContext, + input: { + sessionID, + agent, + model, + messageID, + variant, + message: output.message, + parts: output.parts, + }, + }) + sessionCurrentTurnSpan[sessionID] = span + }, + }) +} diff --git a/packages/bcode-laminar/src/processor.ts b/packages/bcode-laminar/src/processor.ts new file mode 100644 index 000000000..170825090 --- /dev/null +++ b/packages/bcode-laminar/src/processor.ts @@ -0,0 +1,174 @@ +// Vendored span processor for the Laminar OpenCode integration. +// Folds two upstream classes into one: +// +// - `LaminarSpanProcessor` from lmnr-ts/packages/lmnr/src/opentelemetry-lib/tracing/processor.ts +// Stamps `lmnr.span.path` / `lmnr.span.ids_path` ancestor-attribute pairs +// that the Laminar UI uses to nest spans (it does NOT nest by OTel parentSpanId). +// +// - `OpenCodeLaminarSpanProcessor` from lmnr-opencode-plugin/src/processor.ts +// Re-parents AI-SDK spans onto the per-session "turn" span by reading +// `ai.telemetry.metadata.sessionId` off span attributes; tags spans created +// inside the `task` tool so sub-agent traces link back to the parent's tool call. +// +// Trims (vs. upstream LaminarSpanProcessor): +// - LMNR_ROLLOUT_SESSION_ID branch (LaminarClient sendSpanUpdate path) — unused here. +// - parseOtelHeaders / OTEL_HEADERS env path — we always have an LMNR project key. +// - `forceHttp` HTTP/protobuf exporter — gRPC only. +// - `pino` logger — opencode plugins log via `client.app.log`; the plugin passes +// in a logger callback. + +import { type Context, type Span, trace } from "@opentelemetry/api" +import { + BatchSpanProcessor, + type ReadableSpan, + type SpanProcessor, +} from "@opentelemetry/sdk-trace-base" + +import { + PARENT_SPAN_IDS_PATH, + PARENT_SPAN_PATH, + SPAN_IDS_PATH, + SPAN_INSTRUMENTATION_SOURCE, + SPAN_PATH, + SPAN_SDK_VERSION, +} from "./attributes" +import { getParentSpanId, makeSpanOtelV2Compatible, type OTelSpanCompat } from "./compat" +import { LaminarSpanExporter } from "./exporter" +import { sessionCurrentTurnSpan } from "./state" +import { otelSpanIdToUUID, type StringUUID } from "./utils" + +const SDK_VERSION = "bcode-laminar-0.1" +const SPAWNING_TOOL_NAMES = ["task"] +type LogFn = (level: "debug" | "info" | "warn" | "error", message: string) => void + +export class OpenCodeLaminarSpanProcessor implements SpanProcessor { + private inner: BatchSpanProcessor + private readonly spanIdToPath = new Map() + private readonly spanIdLists = new Map() + private readonly spawningSpanIdToToolUseId: Record = {} + private readonly log: LogFn + + constructor(options: { + apiKey: string + baseUrl: string + port: number + log?: LogFn + }) { + this.inner = new BatchSpanProcessor( + new LaminarSpanExporter({ + apiKey: options.apiKey, + baseUrl: options.baseUrl, + port: options.port, + }), + { maxExportBatchSize: 512, exportTimeoutMillis: 30000 }, + ) + this.log = options.log ?? (() => {}) + } + + forceFlush() { + return this.inner.forceFlush() + } + + shutdown() { + return this.inner.shutdown() + } + + onStart(spanArg: any, parentContext: Context): void { + const span = spanArg as OTelSpanCompat + + // 1. Re-parent AI-SDK spans onto the live "turn" span for this opencode + // session, so each turn becomes its own Laminar trace instead of a + // forest of orphan traces. + const sessionId = span.attributes?.["ai.telemetry.metadata.sessionId"] as + | string + | undefined + let ctx = parentContext + if (sessionId && typeof sessionId === "string") { + const parentSpanContext = sessionCurrentTurnSpan[sessionId]?.spanContext() + const parentSpanId = getParentSpanId(span) + if (parentSpanContext && !parentSpanId) { + ctx = trace.setSpan(ctx, trace.wrapSpanContext(parentSpanContext)) + // OTel SDK v1 (parentSpanId) and v2 (parentSpanContext) both need patching. + Object.assign(span, { parentSpanContext }) + Object.assign(span, { parentSpanId: parentSpanContext.spanId }) + const spanContext = span.spanContext() + Object.assign(spanContext, { ...spanContext, traceId: parentSpanContext.traceId }) + Object.assign(spanContext, { _spanContext: spanContext }) + } + } + + // 2. Track `task`-tool spans so any descendant sub-agent span can be + // tagged with its tool-use id (links sub-agent traces to parent). + const toolCallId = span.attributes?.["ai.toolCall.id"] as string | undefined + if (toolCallId) { + const toolCallNameAttr = span.attributes?.["ai.toolCall.name"] as string | undefined + if ( + SPAWNING_TOOL_NAMES.includes(span.name) || + (span.name === "ai.toolCall" && + toolCallNameAttr && + SPAWNING_TOOL_NAMES.includes(toolCallNameAttr)) + ) { + this.spawningSpanIdToToolUseId[otelSpanIdToUUID(span.spanContext().spanId)] = toolCallId + } + } + + // 3. Stamp Laminar's path attributes. The UI nests by these, NOT by + // OTel parentSpanId — must run for every span. + const parentPathFromAttribute = span.attributes?.[PARENT_SPAN_PATH] as string[] | undefined + const parentIdsPathFromAttribute = span.attributes?.[PARENT_SPAN_IDS_PATH] as + | StringUUID[] + | undefined + const parentSpanId = getParentSpanId(span) + const parentSpanPath = + parentPathFromAttribute ?? + (parentSpanId !== undefined ? this.spanIdToPath.get(parentSpanId) : undefined) + const parentSpanIdsPath = + parentIdsPathFromAttribute ?? + (parentSpanId !== undefined ? this.spanIdLists.get(parentSpanId) : []) + + const spanId = span.spanContext().spanId + const spanPath = parentSpanPath ? [...parentSpanPath, span.name] : [span.name] + const spanIdUuid = otelSpanIdToUUID(spanId) + const spanIdsPath = parentSpanIdsPath ? [...parentSpanIdsPath, spanIdUuid] : [spanIdUuid] + + span.setAttribute(SPAN_IDS_PATH, spanIdsPath) + span.setAttribute(SPAN_PATH, spanPath) + span.setAttribute(SPAN_INSTRUMENTATION_SOURCE, "javascript") + span.setAttribute(SPAN_SDK_VERSION, SDK_VERSION) + this.spanIdLists.set(spanId, spanIdsPath) + this.spanIdToPath.set(spanId, spanPath) + + // 4. If this span descends from a tracked spawning tool call, tag it. + if (spanIdsPath.length > 0) { + let spawningToolCallSpanId: StringUUID | undefined + for (let i = spanIdsPath.length - 1; i >= 0; i--) { + const candidate = spanIdsPath[i]! + if (this.spawningSpanIdToToolUseId[candidate] !== undefined) { + spawningToolCallSpanId = candidate + break + } + } + if (spawningToolCallSpanId) { + span.setAttributes({ + "lmnr.spawning_subagent.span_id": spawningToolCallSpanId, + "lmnr.spawning_subagent.tool_use_id": + this.spawningSpanIdToToolUseId[spawningToolCallSpanId]!, + }) + } + } + + makeSpanOtelV2Compatible(span) + this.inner.onStart(span, ctx) + } + + onEnd(span: ReadableSpan): void { + const spanId = span.spanContext().spanId + this.spanIdLists.delete(spanId) + this.spanIdToPath.delete(spanId) + // spawningSpanIdToToolUseId is keyed by UUID (matches `lmnr.span.ids_path` + // entries that the descendant scan iterates), not by the raw hex span id. + delete this.spawningSpanIdToToolUseId[otelSpanIdToUUID(spanId)] + makeSpanOtelV2Compatible(span) + this.inner.onEnd(span) + } +} diff --git a/packages/bcode-laminar/src/span.ts b/packages/bcode-laminar/src/span.ts new file mode 100644 index 000000000..9ea1ee999 --- /dev/null +++ b/packages/bcode-laminar/src/span.ts @@ -0,0 +1,93 @@ +// Minimal subset of Laminar.startSpan from +// lmnr-ts/packages/lmnr/src/laminar.ts. We only need to start a "turn" span +// per chat.message event with sessionId association, optional parent span +// context (for callers driving opencode programmatically), and an input +// payload. No tracing-level, masked-input, global-context-stack, or +// active-span machinery — opencode owns its own trace lifecycle. + +import { type Context, ROOT_CONTEXT, type Span, trace, TraceFlags } from "@opentelemetry/api" + +import { + PARENT_SPAN_IDS_PATH, + PARENT_SPAN_PATH, + SESSION_ID, + SPAN_INPUT, + SPAN_TYPE, +} from "./attributes" +import { isStringUUID, type StringUUID, uuidToOtelSpanId, uuidToOtelTraceId } from "./utils" + +const TURN_TRACER_NAME = "@browser-use/bcode-laminar" + +export const startTurnSpan = (opts: { + name: string + sessionId: string + parentSpanContext?: string + input?: unknown +}): Span => { + let ctx: Context = ROOT_CONTEXT + let parentPath: string[] | undefined + let parentIdsPath: StringUUID[] | undefined + + if (opts.parentSpanContext) { + const parsed = parseLaminarSpanContext(opts.parentSpanContext) + if (parsed) { + parentPath = parsed.spanPath + parentIdsPath = parsed.spanIdsPath + ctx = trace.setSpan( + ctx, + trace.wrapSpanContext({ + traceId: uuidToOtelTraceId(parsed.traceId), + spanId: uuidToOtelSpanId(parsed.spanId), + isRemote: parsed.isRemote, + traceFlags: TraceFlags.SAMPLED, + }), + ) + } + } + + const attributes: Record = { + [SPAN_TYPE]: "DEFAULT", + [SESSION_ID]: opts.sessionId, + ...(parentPath ? { [PARENT_SPAN_PATH]: parentPath } : {}), + ...(parentIdsPath ? { [PARENT_SPAN_IDS_PATH]: parentIdsPath } : {}), + } + if (opts.input !== undefined) attributes[SPAN_INPUT] = JSON.stringify(opts.input) + + return trace.getTracer(TURN_TRACER_NAME).startSpan(opts.name, { attributes }, ctx) +} + +type ParsedSpanContext = { + traceId: string + spanId: string + isRemote: boolean + spanPath?: string[] + spanIdsPath?: StringUUID[] +} + +const parseLaminarSpanContext = (input: string): ParsedSpanContext | undefined => { + try { + const record = JSON.parse(input) + const traceId = record.traceId ?? record.trace_id + const spanId = record.spanId ?? record.span_id + if (typeof traceId !== "string" || typeof spanId !== "string") return undefined + if (!isStringUUID(traceId) || !isStringUUID(spanId)) return undefined + const spanPath = Array.isArray(record.spanPath ?? record.span_path) + ? (record.spanPath ?? record.span_path) + : undefined + const spanIdsPathRaw = record.spanIdsPath ?? record.span_ids_path + const spanIdsPath = + Array.isArray(spanIdsPathRaw) && + spanIdsPathRaw.every((v: unknown) => typeof v === "string" && isStringUUID(v)) + ? (spanIdsPathRaw as StringUUID[]) + : undefined + return { + traceId, + spanId, + isRemote: Boolean(record.isRemote ?? record.is_remote ?? false), + spanPath, + spanIdsPath, + } + } catch { + return undefined + } +} diff --git a/packages/bcode-laminar/src/state.ts b/packages/bcode-laminar/src/state.ts new file mode 100644 index 000000000..8a3dd5f67 --- /dev/null +++ b/packages/bcode-laminar/src/state.ts @@ -0,0 +1,10 @@ +// Vendored from lmnr-opencode-plugin/src/state.ts. +// Module-level maps shared by plugin.ts and processor.ts: +// - sessionCurrentTurnSpan: session id -> live "turn" span the AI-SDK spans nest under. +// - subagentSessionIds: parent session id -> set of child (sub-agent) session ids. +// Used to skip turn-span creation for sub-agent prompts. + +import type { Span } from "@opentelemetry/api" + +export const sessionCurrentTurnSpan: Record = {} +export const subagentSessionIds: Record> = {} diff --git a/packages/bcode-laminar/src/utils.ts b/packages/bcode-laminar/src/utils.ts new file mode 100644 index 000000000..569508b50 --- /dev/null +++ b/packages/bcode-laminar/src/utils.ts @@ -0,0 +1,22 @@ +// Vendored from lmnr-ts/packages/lmnr/src/utils.ts (selected helpers). +// Laminar uses UUIDs for span/trace ids; OTel uses 16/8-byte hex strings. + +export type StringUUID = `${string}-${string}-${string}-${string}-${string}` + +const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i + +export const isStringUUID = (id: string): id is StringUUID => UUID_RE.test(id) + +export const otelSpanIdToUUID = (spanId: string): StringUUID => { + let id = spanId.toLowerCase() + if (id.startsWith("0x")) id = id.slice(2) + return id + .padStart(32, "0") + .replace( + /^([0-9a-f]{8})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{12})$/, + "$1-$2-$3-$4-$5", + ) as StringUUID +} + +export const uuidToOtelTraceId = (uuid: string): string => uuid.replace(/-/g, "") +export const uuidToOtelSpanId = (uuid: string): string => uuid.replace(/-/g, "").slice(16) diff --git a/packages/bcode-laminar/tsconfig.json b/packages/bcode-laminar/tsconfig.json new file mode 100644 index 000000000..00ef12546 --- /dev/null +++ b/packages/bcode-laminar/tsconfig.json @@ -0,0 +1,8 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "extends": "@tsconfig/bun/tsconfig.json", + "compilerOptions": { + "lib": ["ESNext", "DOM", "DOM.Iterable"], + "noUncheckedIndexedAccess": false + } +} diff --git a/packages/opencode/package.json b/packages/opencode/package.json index 9c8adc5be..459c7d7a8 100644 --- a/packages/opencode/package.json +++ b/packages/opencode/package.json @@ -103,6 +103,7 @@ "@ai-sdk/xai": "3.0.82", "@aws-sdk/credential-providers": "3.993.0", "@browser-use/bcode-browser": "workspace:*", + "@browser-use/bcode-laminar": "workspace:*", "@clack/prompts": "1.0.0-alpha.1", "@effect/opentelemetry": "catalog:", "@effect/platform-node": "catalog:", diff --git a/packages/opencode/src/plugin/index.ts b/packages/opencode/src/plugin/index.ts index 7a7f260df..61a782226 100644 --- a/packages/opencode/src/plugin/index.ts +++ b/packages/opencode/src/plugin/index.ts @@ -19,6 +19,7 @@ import { gitlabAuthPlugin as GitlabAuthPlugin } from "opencode-gitlab-auth" import { PoeAuthPlugin } from "opencode-poe-auth" import { CloudflareAIGatewayAuthPlugin, CloudflareWorkersAuthPlugin } from "./cloudflare" import { AzureAuthPlugin } from "./azure" +import { LaminarPlugin } from "@browser-use/bcode-laminar" import { Effect, Layer, Context, Stream } from "effect" import { EffectBridge } from "@/effect/bridge" import { InstanceState } from "@/effect/instance-state" @@ -64,6 +65,7 @@ const INTERNAL_PLUGINS: PluginInstance[] = [ CloudflareWorkersAuthPlugin, CloudflareAIGatewayAuthPlugin, AzureAuthPlugin, + LaminarPlugin, ] function isServerPlugin(value: unknown): value is PluginInstance {