feat: Complete zCode CLI X with Telegram bot integration

- Add full Telegram bot functionality with Z.AI API integration
- Implement 4 tools: Bash, FileEdit, WebSearch, Git
- Add 3 agents: Code Reviewer, Architect, DevOps Engineer
- Add 6 skills for common coding tasks
- Add systemd service file for 24/7 operation
- Add nginx configuration for HTTPS webhook
- Add comprehensive documentation
- Implement WebSocket server for real-time updates
- Add logging system with Winston
- Add environment validation

🤖 zCode CLI X - Agentic coder with Z.AI + Telegram integration
This commit is contained in:
admin
2026-05-05 09:01:26 +00:00
Unverified
parent 4a7035dd92
commit 875c7f9b91
24688 changed files with 3224957 additions and 221 deletions

View File

@@ -0,0 +1,2 @@
export declare function hexToBinary(hexStr: string): Uint8Array;
//# sourceMappingURL=hex-to-binary.d.ts.map

View File

@@ -0,0 +1,31 @@
"use strict";
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.hexToBinary = void 0;
function intValue(charCode) {
// 0-9
if (charCode >= 48 && charCode <= 57) {
return charCode - 48;
}
// a-f
if (charCode >= 97 && charCode <= 102) {
return charCode - 87;
}
// A-F
return charCode - 55;
}
function hexToBinary(hexStr) {
const buf = new Uint8Array(hexStr.length / 2);
let offset = 0;
for (let i = 0; i < hexStr.length; i += 2) {
const hi = intValue(hexStr.charCodeAt(i));
const lo = intValue(hexStr.charCodeAt(i + 1));
buf[offset++] = (hi << 4) | lo;
}
return buf;
}
exports.hexToBinary = hexToBinary;
//# sourceMappingURL=hex-to-binary.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"hex-to-binary.js","sourceRoot":"","sources":["../../../src/common/hex-to-binary.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,SAAS,QAAQ,CAAC,QAAgB;IAChC,MAAM;IACN,IAAI,QAAQ,IAAI,EAAE,IAAI,QAAQ,IAAI,EAAE,EAAE;QACpC,OAAO,QAAQ,GAAG,EAAE,CAAC;KACtB;IAED,MAAM;IACN,IAAI,QAAQ,IAAI,EAAE,IAAI,QAAQ,IAAI,GAAG,EAAE;QACrC,OAAO,QAAQ,GAAG,EAAE,CAAC;KACtB;IAED,MAAM;IACN,OAAO,QAAQ,GAAG,EAAE,CAAC;AACvB,CAAC;AAED,SAAgB,WAAW,CAAC,MAAc;IACxC,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC9C,IAAI,MAAM,GAAG,CAAC,CAAC;IAEf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE;QACzC,MAAM,EAAE,GAAG,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1C,MAAM,EAAE,GAAG,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC9C,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC;KAChC;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAXD,kCAWC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nfunction intValue(charCode: number): number {\n // 0-9\n if (charCode >= 48 && charCode <= 57) {\n return charCode - 48;\n }\n\n // a-f\n if (charCode >= 97 && charCode <= 102) {\n return charCode - 87;\n }\n\n // A-F\n return charCode - 55;\n}\n\nexport function hexToBinary(hexStr: string): Uint8Array {\n const buf = new Uint8Array(hexStr.length / 2);\n let offset = 0;\n\n for (let i = 0; i < hexStr.length; i += 2) {\n const hi = intValue(hexStr.charCodeAt(i));\n const lo = intValue(hexStr.charCodeAt(i + 1));\n buf[offset++] = (hi << 4) | lo;\n }\n\n return buf;\n}\n"]}

View File

@@ -0,0 +1,66 @@
/** Properties of a Resource. */
export interface Resource {
/** Resource attributes */
attributes: IKeyValue[];
/** Resource droppedAttributesCount */
droppedAttributesCount: number;
/** Resource schemaUrl */
schemaUrl?: string;
}
/** Properties of an InstrumentationScope. */
export interface IInstrumentationScope {
/** InstrumentationScope name */
name: string;
/** InstrumentationScope version */
version?: string;
/** InstrumentationScope attributes */
attributes?: IKeyValue[];
/** InstrumentationScope droppedAttributesCount */
droppedAttributesCount?: number;
}
/** Properties of a KeyValue. */
export interface IKeyValue {
/** KeyValue key */
key: string;
/** KeyValue value */
value: IAnyValue;
}
/** Properties of an AnyValue. */
export interface IAnyValue {
/** AnyValue stringValue */
stringValue?: string | null;
/** AnyValue boolValue */
boolValue?: boolean | null;
/** AnyValue intValue */
intValue?: number | null;
/** AnyValue doubleValue */
doubleValue?: number | null;
/** AnyValue arrayValue */
arrayValue?: IArrayValue;
/** AnyValue kvlistValue */
kvlistValue?: IKeyValueList;
/** AnyValue bytesValue */
bytesValue?: Uint8Array | string;
}
/** Properties of an ArrayValue. */
export interface IArrayValue {
/** ArrayValue values */
values: IAnyValue[];
}
/** Properties of a KeyValueList. */
export interface IKeyValueList {
/** KeyValueList values */
values: IKeyValue[];
}
export interface LongBits {
low: number;
high: number;
}
export type Fixed64 = LongBits | string | number;
export interface OtlpEncodingOptions {
/** Convert trace and span IDs to hex strings. */
useHex?: boolean;
/** Convert HrTime to 2 part 64 bit values. */
useLongBits?: boolean;
}
//# sourceMappingURL=internal-types.d.ts.map

View File

@@ -0,0 +1,7 @@
"use strict";
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=internal-types.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"internal-types.js","sourceRoot":"","sources":["../../../src/common/internal-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/** Properties of a Resource. */\nexport interface Resource {\n /** Resource attributes */\n attributes: IKeyValue[];\n\n /** Resource droppedAttributesCount */\n droppedAttributesCount: number;\n\n /** Resource schemaUrl */\n schemaUrl?: string;\n}\n\n/** Properties of an InstrumentationScope. */\nexport interface IInstrumentationScope {\n /** InstrumentationScope name */\n name: string;\n\n /** InstrumentationScope version */\n version?: string;\n\n /** InstrumentationScope attributes */\n attributes?: IKeyValue[];\n\n /** InstrumentationScope droppedAttributesCount */\n droppedAttributesCount?: number;\n}\n\n/** Properties of a KeyValue. */\nexport interface IKeyValue {\n /** KeyValue key */\n key: string;\n\n /** KeyValue value */\n value: IAnyValue;\n}\n\n/** Properties of an AnyValue. */\nexport interface IAnyValue {\n /** AnyValue stringValue */\n stringValue?: string | null;\n\n /** AnyValue boolValue */\n boolValue?: boolean | null;\n\n /** AnyValue intValue */\n intValue?: number | null;\n\n /** AnyValue doubleValue */\n doubleValue?: number | null;\n\n /** AnyValue arrayValue */\n arrayValue?: IArrayValue;\n\n /** AnyValue kvlistValue */\n kvlistValue?: IKeyValueList;\n\n /** AnyValue bytesValue */\n bytesValue?: Uint8Array | string;\n}\n\n/** Properties of an ArrayValue. */\nexport interface IArrayValue {\n /** ArrayValue values */\n values: IAnyValue[];\n}\n\n/** Properties of a KeyValueList. */\nexport interface IKeyValueList {\n /** KeyValueList values */\n values: IKeyValue[];\n}\n\nexport interface LongBits {\n low: number;\n high: number;\n}\n\nexport type Fixed64 = LongBits | string | number;\n\nexport interface OtlpEncodingOptions {\n /** Convert trace and span IDs to hex strings. */\n useHex?: boolean;\n /** Convert HrTime to 2 part 64 bit values. */\n useLongBits?: boolean;\n}\n"]}

View File

@@ -0,0 +1,11 @@
import type { IAnyValue, IInstrumentationScope, IKeyValue, Resource } from './internal-types';
import type { Attributes } from '@opentelemetry/api';
import type { InstrumentationScope } from '@opentelemetry/core';
import type { Resource as ISdkResource } from '@opentelemetry/resources';
import type { Encoder } from './utils';
export declare function createResource(resource: ISdkResource, encoder: Encoder): Resource;
export declare function createInstrumentationScope(scope: InstrumentationScope): IInstrumentationScope;
export declare function toAttributes(attributes: Attributes, encoder: Encoder): IKeyValue[];
export declare function toKeyValue(key: string, value: unknown, encoder: Encoder): IKeyValue;
export declare function toAnyValue(value: unknown, encoder: Encoder): IAnyValue;
//# sourceMappingURL=internal.d.ts.map

View File

@@ -0,0 +1,67 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toAnyValue = exports.toKeyValue = exports.toAttributes = exports.createInstrumentationScope = exports.createResource = void 0;
function createResource(resource, encoder) {
const result = {
attributes: toAttributes(resource.attributes, encoder),
droppedAttributesCount: 0,
};
const schemaUrl = resource.schemaUrl;
if (schemaUrl && schemaUrl !== '')
result.schemaUrl = schemaUrl;
return result;
}
exports.createResource = createResource;
function createInstrumentationScope(scope) {
return {
name: scope.name,
version: scope.version,
};
}
exports.createInstrumentationScope = createInstrumentationScope;
function toAttributes(attributes, encoder) {
return Object.keys(attributes).map(key => toKeyValue(key, attributes[key], encoder));
}
exports.toAttributes = toAttributes;
function toKeyValue(key, value, encoder) {
return {
key: key,
value: toAnyValue(value, encoder),
};
}
exports.toKeyValue = toKeyValue;
function toAnyValue(value, encoder) {
const t = typeof value;
if (t === 'string')
return { stringValue: value };
if (t === 'number') {
if (!Number.isInteger(value))
return { doubleValue: value };
return { intValue: value };
}
if (t === 'boolean')
return { boolValue: value };
if (value instanceof Uint8Array)
return { bytesValue: encoder.encodeUint8Array(value) };
if (Array.isArray(value)) {
const values = new Array(value.length);
for (let i = 0; i < value.length; i++) {
values[i] = toAnyValue(value[i], encoder);
}
return { arrayValue: { values } };
}
if (t === 'object' && value != null) {
const keys = Object.keys(value);
const values = new Array(keys.length);
for (let i = 0; i < keys.length; i++) {
values[i] = {
key: keys[i],
value: toAnyValue(value[keys[i]], encoder),
};
}
return { kvlistValue: { values } };
}
return {};
}
exports.toAnyValue = toAnyValue;
//# sourceMappingURL=internal.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/common/internal.ts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,CAAC;AACZ,CAAC;AA9BD,gCA8BC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type {\n IAnyValue,\n IInstrumentationScope,\n IKeyValue,\n Resource,\n} from './internal-types';\nimport type { Attributes } from '@opentelemetry/api';\nimport type { InstrumentationScope } from '@opentelemetry/core';\nimport type { Resource as ISdkResource } from '@opentelemetry/resources';\nimport type { Encoder } from './utils';\n\nexport function createResource(\n resource: ISdkResource,\n encoder: Encoder\n): Resource {\n const result: Resource = {\n attributes: toAttributes(resource.attributes, encoder),\n droppedAttributesCount: 0,\n };\n\n const schemaUrl = resource.schemaUrl;\n if (schemaUrl && schemaUrl !== '') result.schemaUrl = schemaUrl;\n\n return result;\n}\n\nexport function createInstrumentationScope(\n scope: InstrumentationScope\n): IInstrumentationScope {\n return {\n name: scope.name,\n version: scope.version,\n };\n}\n\nexport function toAttributes(\n attributes: Attributes,\n encoder: Encoder\n): IKeyValue[] {\n return Object.keys(attributes).map(key =>\n toKeyValue(key, attributes[key], encoder)\n );\n}\n\nexport function toKeyValue(\n key: string,\n value: unknown,\n encoder: Encoder\n): IKeyValue {\n return {\n key: key,\n value: toAnyValue(value, encoder),\n };\n}\n\nexport function toAnyValue(value: unknown, encoder: Encoder): IAnyValue {\n const t = typeof value;\n if (t === 'string') return { stringValue: value as string };\n if (t === 'number') {\n if (!Number.isInteger(value)) return { doubleValue: value as number };\n return { intValue: value as number };\n }\n if (t === 'boolean') return { boolValue: value as boolean };\n if (value instanceof Uint8Array)\n return { bytesValue: encoder.encodeUint8Array(value) };\n if (Array.isArray(value)) {\n const values: IAnyValue[] = new Array(value.length);\n for (let i = 0; i < value.length; i++) {\n values[i] = toAnyValue(value[i], encoder);\n }\n return { arrayValue: { values } };\n }\n if (t === 'object' && value != null) {\n const keys = Object.keys(value);\n const values: IKeyValue[] = new Array(keys.length);\n for (let i = 0; i < keys.length; i++) {\n values[i] = {\n key: keys[i],\n value: toAnyValue((value as Record<string, unknown>)[keys[i]], encoder),\n };\n }\n return { kvlistValue: { values } };\n }\n\n return {};\n}\n"]}

View File

@@ -0,0 +1,8 @@
import type * as protobuf from 'protobufjs';
export interface ExportType<T, R = T & {
toJSON: () => unknown;
}> {
encode(message: T, writer?: protobuf.Writer): protobuf.Writer;
decode(reader: protobuf.Reader | Uint8Array, length?: number): R;
}
//# sourceMappingURL=protobuf-export-type.d.ts.map

View File

@@ -0,0 +1,7 @@
"use strict";
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=protobuf-export-type.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"protobuf-export-type.js","sourceRoot":"","sources":["../../../../src/common/protobuf/protobuf-export-type.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type * as protobuf from 'protobufjs';\n\nexport interface ExportType<T, R = T & { toJSON: () => unknown }> {\n encode(message: T, writer?: protobuf.Writer): protobuf.Writer;\n decode(reader: protobuf.Reader | Uint8Array, length?: number): R;\n}\n"]}

View File

@@ -0,0 +1,27 @@
import type { Fixed64, LongBits } from './internal-types';
import type { HrTime } from '@opentelemetry/api';
export declare function hrTimeToNanos(hrTime: HrTime): bigint;
export declare function toLongBits(value: bigint): LongBits;
export declare function encodeAsLongBits(hrTime: HrTime): LongBits;
export declare function encodeAsString(hrTime: HrTime): string;
export type HrTimeEncodeFunction = (hrTime: HrTime) => Fixed64;
export type SpanContextEncodeFunction = (spanContext: string) => string | Uint8Array;
export type OptionalSpanContextEncodeFunction = (spanContext: string | undefined) => string | Uint8Array | undefined;
export type Uint8ArrayEncodeFunction = (value: Uint8Array) => string | Uint8Array;
export interface Encoder {
encodeHrTime: HrTimeEncodeFunction;
encodeSpanContext: SpanContextEncodeFunction;
encodeOptionalSpanContext: OptionalSpanContextEncodeFunction;
encodeUint8Array: Uint8ArrayEncodeFunction;
}
/**
* Encoder for protobuf format.
* Uses { high, low } timestamps and binary for span/trace IDs, leaves Uint8Array attributes as-is.
*/
export declare const PROTOBUF_ENCODER: Encoder;
/**
* Encoder for JSON format.
* Uses string timestamps, hex for span/trace IDs, and base64 for Uint8Array.
*/
export declare const JSON_ENCODER: Encoder;
//# sourceMappingURL=utils.d.ts.map

View File

@@ -0,0 +1,71 @@
"use strict";
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.JSON_ENCODER = exports.PROTOBUF_ENCODER = exports.encodeAsString = exports.encodeAsLongBits = exports.toLongBits = exports.hrTimeToNanos = void 0;
const core_1 = require("@opentelemetry/core");
const hex_to_binary_1 = require("./hex-to-binary");
function hrTimeToNanos(hrTime) {
const NANOSECONDS = BigInt(1000000000);
return (BigInt(Math.trunc(hrTime[0])) * NANOSECONDS + BigInt(Math.trunc(hrTime[1])));
}
exports.hrTimeToNanos = hrTimeToNanos;
function toLongBits(value) {
const low = Number(BigInt.asUintN(32, value));
const high = Number(BigInt.asUintN(32, value >> BigInt(32)));
return { low, high };
}
exports.toLongBits = toLongBits;
function encodeAsLongBits(hrTime) {
const nanos = hrTimeToNanos(hrTime);
return toLongBits(nanos);
}
exports.encodeAsLongBits = encodeAsLongBits;
function encodeAsString(hrTime) {
const nanos = hrTimeToNanos(hrTime);
return nanos.toString();
}
exports.encodeAsString = encodeAsString;
const encodeTimestamp = typeof BigInt !== 'undefined' ? encodeAsString : core_1.hrTimeToNanoseconds;
function identity(value) {
return value;
}
function optionalHexToBinary(str) {
if (str === undefined)
return undefined;
return (0, hex_to_binary_1.hexToBinary)(str);
}
/**
* Encoder for protobuf format.
* Uses { high, low } timestamps and binary for span/trace IDs, leaves Uint8Array attributes as-is.
*/
exports.PROTOBUF_ENCODER = {
encodeHrTime: encodeAsLongBits,
encodeSpanContext: hex_to_binary_1.hexToBinary,
encodeOptionalSpanContext: optionalHexToBinary,
encodeUint8Array: identity,
};
/**
* Encoder for JSON format.
* Uses string timestamps, hex for span/trace IDs, and base64 for Uint8Array.
*/
exports.JSON_ENCODER = {
encodeHrTime: encodeTimestamp,
encodeSpanContext: identity,
encodeOptionalSpanContext: identity,
encodeUint8Array: (bytes) => {
if (typeof Buffer !== 'undefined') {
return Buffer.from(bytes).toString('base64');
}
// implementation note: not using spread operator and passing to
// btoa to avoid stack overflow on large Uint8Arrays
const chars = new Array(bytes.length);
for (let i = 0; i < bytes.length; i++) {
chars[i] = String.fromCharCode(bytes[i]);
}
return btoa(chars.join(''));
},
};
//# sourceMappingURL=utils.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/common/utils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH,8CAA0D;AAC1D,mDAA8C;AAE9C,SAAgB,aAAa,CAAC,MAAc;IAC1C,MAAM,WAAW,GAAG,MAAM,CAAC,UAAa,CAAC,CAAC;IAC1C,OAAO,CACL,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAC5E,CAAC;AACJ,CAAC;AALD,sCAKC;AAED,SAAgB,UAAU,CAAC,KAAa;IACtC,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC;IAC9C,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,KAAK,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC7D,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;AACvB,CAAC;AAJD,gCAIC;AAED,SAAgB,gBAAgB,CAAC,MAAc;IAC7C,MAAM,KAAK,GAA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EAAE,EAAE;YACrC,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;SAC1C;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;IAC9B,CAAC;CACF,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Fixed64, LongBits } from './internal-types';\nimport type { HrTime } from '@opentelemetry/api';\nimport { hrTimeToNanoseconds } from '@opentelemetry/core';\nimport { hexToBinary } from './hex-to-binary';\n\nexport function hrTimeToNanos(hrTime: HrTime): bigint {\n const NANOSECONDS = BigInt(1_000_000_000);\n return (\n BigInt(Math.trunc(hrTime[0])) * NANOSECONDS + BigInt(Math.trunc(hrTime[1]))\n );\n}\n\nexport function toLongBits(value: bigint): LongBits {\n const low = Number(BigInt.asUintN(32, value));\n const high = Number(BigInt.asUintN(32, value >> BigInt(32)));\n return { low, high };\n}\n\nexport function encodeAsLongBits(hrTime: HrTime): LongBits {\n const nanos = hrTimeToNanos(hrTime);\n return toLongBits(nanos);\n}\n\nexport function encodeAsString(hrTime: HrTime): string {\n const nanos = hrTimeToNanos(hrTime);\n return nanos.toString();\n}\n\nconst encodeTimestamp =\n typeof BigInt !== 'undefined' ? encodeAsString : hrTimeToNanoseconds;\n\nexport type HrTimeEncodeFunction = (hrTime: HrTime) => Fixed64;\nexport type SpanContextEncodeFunction = (\n spanContext: string\n) => string | Uint8Array;\nexport type OptionalSpanContextEncodeFunction = (\n spanContext: string | undefined\n) => string | Uint8Array | undefined;\nexport type Uint8ArrayEncodeFunction = (\n value: Uint8Array\n) => string | Uint8Array;\n\nexport interface Encoder {\n encodeHrTime: HrTimeEncodeFunction;\n encodeSpanContext: SpanContextEncodeFunction;\n encodeOptionalSpanContext: OptionalSpanContextEncodeFunction;\n encodeUint8Array: Uint8ArrayEncodeFunction;\n}\n\nfunction identity<T>(value: T): T {\n return value;\n}\n\nfunction optionalHexToBinary(str: string | undefined): Uint8Array | undefined {\n if (str === undefined) return undefined;\n return hexToBinary(str);\n}\n\n/**\n * Encoder for protobuf format.\n * Uses { high, low } timestamps and binary for span/trace IDs, leaves Uint8Array attributes as-is.\n */\nexport const PROTOBUF_ENCODER: Encoder = {\n encodeHrTime: encodeAsLongBits,\n encodeSpanContext: hexToBinary,\n encodeOptionalSpanContext: optionalHexToBinary,\n encodeUint8Array: identity,\n};\n\n/**\n * Encoder for JSON format.\n * Uses string timestamps, hex for span/trace IDs, and base64 for Uint8Array.\n */\nexport const JSON_ENCODER: Encoder = {\n encodeHrTime: encodeTimestamp,\n encodeSpanContext: identity,\n encodeOptionalSpanContext: identity,\n encodeUint8Array: (bytes: Uint8Array): string => {\n if (typeof Buffer !== 'undefined') {\n return Buffer.from(bytes).toString('base64');\n }\n\n // implementation note: not using spread operator and passing to\n // btoa to avoid stack overflow on large Uint8Arrays\n const chars = new Array(bytes.length);\n for (let i = 0; i < bytes.length; i++) {\n chars[i] = String.fromCharCode(bytes[i]);\n }\n return btoa(chars.join(''));\n },\n};\n"]}