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,64 @@
/** Properties of a Resource. */
export interface IResource {
/** Resource attributes */
attributes: IKeyValue[];
/** Resource droppedAttributesCount */
droppedAttributesCount: number;
}
/** 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;
}
/** 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 declare 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,17 @@
/*
* Copyright The OpenTelemetry Authors
*
* 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
*
* https://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.
*/
export {};
//# 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;;;;;;;;;;;;;;GAcG","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/** Properties of a Resource. */\nexport interface IResource {\n /** Resource attributes */\n attributes: IKeyValue[];\n\n /** Resource droppedAttributesCount */\n droppedAttributesCount: number;\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;\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,10 @@
import type { IAnyValue, IInstrumentationScope, IKeyValue, IResource } from './internal-types';
import { Attributes } from '@opentelemetry/api';
import { InstrumentationScope } from '@opentelemetry/core';
import { IResource as ISdkResource } from '@opentelemetry/resources';
export declare function createResource(resource: ISdkResource): IResource;
export declare function createInstrumentationScope(scope: InstrumentationScope): IInstrumentationScope;
export declare function toAttributes(attributes: Attributes): IKeyValue[];
export declare function toKeyValue(key: string, value: unknown): IKeyValue;
export declare function toAnyValue(value: unknown): IAnyValue;
//# sourceMappingURL=internal.d.ts.map

View File

@@ -0,0 +1,64 @@
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
export function createResource(resource) {
return {
attributes: toAttributes(resource.attributes),
droppedAttributesCount: 0,
};
}
export function createInstrumentationScope(scope) {
return {
name: scope.name,
version: scope.version,
};
}
export function toAttributes(attributes) {
return Object.keys(attributes).map(function (key) { return toKeyValue(key, attributes[key]); });
}
export function toKeyValue(key, value) {
return {
key: key,
value: toAnyValue(value),
};
}
export function toAnyValue(value) {
var 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: value };
if (Array.isArray(value))
return { arrayValue: { values: value.map(toAnyValue) } };
if (t === 'object' && value != null)
return {
kvlistValue: {
values: Object.entries(value).map(function (_a) {
var _b = __read(_a, 2), k = _b[0], v = _b[1];
return toKeyValue(k, v);
}),
},
};
return {};
}
//# sourceMappingURL=internal.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/common/internal.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAyBA,MAAM,UAAU,cAAc,CAAC,QAAsB;IACnD,OAAO;QACL,UAAU,EAAE,YAAY,CAAC,QAAQ,CAAC,UAAU,CAAC;QAC7C,sBAAsB,EAAE,CAAC;KAC1B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,0BAA0B,CACxC,KAA2B;IAE3B,OAAO;QACL,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,OAAO,EAAE,KAAK,CAAC,OAAO;KACvB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,UAAsB;IACjD,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,UAAA,GAAG,IAAI,OAAA,UAAU,CAAC,GAAG,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,EAAhC,CAAgC,CAAC,CAAC;AAC9E,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,GAAW,EAAE,KAAc;IACpD,OAAO;QACL,GAAG,EAAE,GAAG;QACR,KAAK,EAAE,UAAU,CAAC,KAAK,CAAC;KACzB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,IAAM,CAAC,GAAG,OAAO,KAAK,CAAC;IACvB,IAAI,CAAC,KAAK,QAAQ;QAAE,OAAO,EAAE,WAAW,EAAE,KAAe,EAAE,CAAC;IAC5D,IAAI,CAAC,KAAK,QAAQ,EAAE;QAClB,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC;YAAE,OAAO,EAAE,WAAW,EAAE,KAAe,EAAE,CAAC;QACtE,OAAO,EAAE,QAAQ,EAAE,KAAe,EAAE,CAAC;KACtC;IACD,IAAI,CAAC,KAAK,SAAS;QAAE,OAAO,EAAE,SAAS,EAAE,KAAgB,EAAE,CAAC;IAC5D,IAAI,KAAK,YAAY,UAAU;QAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;IAC9D,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACtB,OAAO,EAAE,UAAU,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,EAAE,CAAC;IAC3D,IAAI,CAAC,KAAK,QAAQ,IAAI,KAAK,IAAI,IAAI;QACjC,OAAO;YACL,WAAW,EAAE;gBACX,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,KAAe,CAAC,CAAC,GAAG,CAAC,UAAC,EAAM;wBAAN,KAAA,aAAM,EAAL,CAAC,QAAA,EAAE,CAAC,QAAA;oBAChD,OAAA,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC;gBAAhB,CAAgB,CACjB;aACF;SACF,CAAC;IAEJ,OAAO,EAAE,CAAC;AACZ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport type {\n IAnyValue,\n IInstrumentationScope,\n IKeyValue,\n IResource,\n} from './internal-types';\nimport { Attributes } from '@opentelemetry/api';\nimport { InstrumentationScope } from '@opentelemetry/core';\nimport { IResource as ISdkResource } from '@opentelemetry/resources';\n\nexport function createResource(resource: ISdkResource): IResource {\n return {\n attributes: toAttributes(resource.attributes),\n droppedAttributesCount: 0,\n };\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(attributes: Attributes): IKeyValue[] {\n return Object.keys(attributes).map(key => toKeyValue(key, attributes[key]));\n}\n\nexport function toKeyValue(key: string, value: unknown): IKeyValue {\n return {\n key: key,\n value: toAnyValue(value),\n };\n}\n\nexport function toAnyValue(value: unknown): 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) return { bytesValue: value };\n if (Array.isArray(value))\n return { arrayValue: { values: value.map(toAnyValue) } };\n if (t === 'object' && value != null)\n return {\n kvlistValue: {\n values: Object.entries(value as object).map(([k, v]) =>\n toKeyValue(k, v)\n ),\n },\n };\n\n return {};\n}\n"]}

View File

@@ -0,0 +1,8 @@
import * 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,17 @@
/*
* Copyright The OpenTelemetry Authors
*
* 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
*
* https://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.
*/
export {};
//# 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;;;;;;;;;;;;;;GAcG","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport * 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,16 @@
import type { OtlpEncodingOptions, Fixed64, LongBits } from './internal-types';
import { 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 declare type HrTimeEncodeFunction = (hrTime: HrTime) => Fixed64;
export declare type SpanContextEncodeFunction = (spanContext: string) => string | Uint8Array;
export declare type OptionalSpanContextEncodeFunction = (spanContext: string | undefined) => string | Uint8Array | undefined;
export interface Encoder {
encodeHrTime: HrTimeEncodeFunction;
encodeSpanContext: SpanContextEncodeFunction;
encodeOptionalSpanContext: OptionalSpanContextEncodeFunction;
}
export declare function getOtlpEncoder(options?: OtlpEncodingOptions): Encoder;
//# sourceMappingURL=utils.d.ts.map

View File

@@ -0,0 +1,61 @@
/*
* Copyright The OpenTelemetry Authors
*
* 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
*
* https://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.
*/
import { hexToBinary, hrTimeToNanoseconds } from '@opentelemetry/core';
export function hrTimeToNanos(hrTime) {
var NANOSECONDS = BigInt(1000000000);
return BigInt(hrTime[0]) * NANOSECONDS + BigInt(hrTime[1]);
}
export function toLongBits(value) {
var low = Number(BigInt.asUintN(32, value));
var high = Number(BigInt.asUintN(32, value >> BigInt(32)));
return { low: low, high: high };
}
export function encodeAsLongBits(hrTime) {
var nanos = hrTimeToNanos(hrTime);
return toLongBits(nanos);
}
export function encodeAsString(hrTime) {
var nanos = hrTimeToNanos(hrTime);
return nanos.toString();
}
var encodeTimestamp = typeof BigInt !== 'undefined' ? encodeAsString : hrTimeToNanoseconds;
function identity(value) {
return value;
}
function optionalHexToBinary(str) {
if (str === undefined)
return undefined;
return hexToBinary(str);
}
var DEFAULT_ENCODER = {
encodeHrTime: encodeAsLongBits,
encodeSpanContext: hexToBinary,
encodeOptionalSpanContext: optionalHexToBinary,
};
export function getOtlpEncoder(options) {
var _a, _b;
if (options === undefined) {
return DEFAULT_ENCODER;
}
var useLongBits = (_a = options.useLongBits) !== null && _a !== void 0 ? _a : true;
var useHex = (_b = options.useHex) !== null && _b !== void 0 ? _b : false;
return {
encodeHrTime: useLongBits ? encodeAsLongBits : encodeTimestamp,
encodeSpanContext: useHex ? identity : hexToBinary,
encodeOptionalSpanContext: useHex ? identity : optionalHexToBinary,
};
}
//# sourceMappingURL=utils.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/common/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAEvE,MAAM,UAAU,aAAa,CAAC,MAAc;IAC1C,IAAM,WAAW,GAAG,MAAM,CAAC,UAAa,CAAC,CAAC;IAC1C,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7D,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,IAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC;IAC9C,IAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,KAAK,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC7D,OAAO,EAAE,GAAG,KAAA,EAAE,IAAI,MAAA,EAAE,CAAC;AACvB,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,MAAc;IAC7C,IAAM,KAAK,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IACpC,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,MAAc;IAC3C,IAAM,KAAK,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IACpC,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;AAC1B,CAAC;AAED,IAAM,eAAe,GACnB,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,mBAAmB,CAAC;AAgBvE,SAAS,QAAQ,CAAI,KAAQ;IAC3B,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,mBAAmB,CAAC,GAAuB;IAClD,IAAI,GAAG,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACxC,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC;AAC1B,CAAC;AAED,IAAM,eAAe,GAAY;IAC/B,YAAY,EAAE,gBAAgB;IAC9B,iBAAiB,EAAE,WAAW;IAC9B,yBAAyB,EAAE,mBAAmB;CAC/C,CAAC;AAEF,MAAM,UAAU,cAAc,CAAC,OAA6B;;IAC1D,IAAI,OAAO,KAAK,SAAS,EAAE;QACzB,OAAO,eAAe,CAAC;KACxB;IAED,IAAM,WAAW,GAAG,MAAA,OAAO,CAAC,WAAW,mCAAI,IAAI,CAAC;IAChD,IAAM,MAAM,GAAG,MAAA,OAAO,CAAC,MAAM,mCAAI,KAAK,CAAC;IACvC,OAAO;QACL,YAAY,EAAE,WAAW,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,eAAe;QAC9D,iBAAiB,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW;QAClD,yBAAyB,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,mBAAmB;KACnE,CAAC;AACJ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { OtlpEncodingOptions, Fixed64, LongBits } from './internal-types';\nimport { HrTime } from '@opentelemetry/api';\nimport { hexToBinary, hrTimeToNanoseconds } from '@opentelemetry/core';\n\nexport function hrTimeToNanos(hrTime: HrTime): bigint {\n const NANOSECONDS = BigInt(1_000_000_000);\n return BigInt(hrTime[0]) * NANOSECONDS + BigInt(hrTime[1]);\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;\n\nexport interface Encoder {\n encodeHrTime: HrTimeEncodeFunction;\n encodeSpanContext: SpanContextEncodeFunction;\n encodeOptionalSpanContext: OptionalSpanContextEncodeFunction;\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\nconst DEFAULT_ENCODER: Encoder = {\n encodeHrTime: encodeAsLongBits,\n encodeSpanContext: hexToBinary,\n encodeOptionalSpanContext: optionalHexToBinary,\n};\n\nexport function getOtlpEncoder(options?: OtlpEncodingOptions): Encoder {\n if (options === undefined) {\n return DEFAULT_ENCODER;\n }\n\n const useLongBits = options.useLongBits ?? true;\n const useHex = options.useHex ?? false;\n return {\n encodeHrTime: useLongBits ? encodeAsLongBits : encodeTimestamp,\n encodeSpanContext: useHex ? identity : hexToBinary,\n encodeOptionalSpanContext: useHex ? identity : optionalHexToBinary,\n };\n}\n"]}