@cline/core 0.0.64 → 0.0.65
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/extensions/tools/definitions.d.ts +21 -3
- package/dist/extensions/tools/index.d.ts +8 -3
- package/dist/extensions/tools/team/delegated-agent.d.ts +1 -1
- package/dist/extensions/tools/types.d.ts +7 -0
- package/dist/hub/daemon/entry.js +157 -157
- package/dist/hub/index.js +154 -154
- package/dist/index.js +155 -155
- package/dist/runtime/orchestration/session-runtime-orchestrator.d.ts +7 -0
- package/dist/services/telemetry/core-events.d.ts +10 -0
- package/dist/services/telemetry/index.js +1 -1
- package/package.json +4 -4
|
@@ -157,6 +157,13 @@ export declare class SessionRuntime {
|
|
|
157
157
|
continue(userMessage?: string, userImages?: string[], userFiles?: string[]): Promise<AgentResult>;
|
|
158
158
|
private composeSystemPrompt;
|
|
159
159
|
private executeRun;
|
|
160
|
+
/**
|
|
161
|
+
* Retry a run once when it failed with an auth-like error and the host
|
|
162
|
+
* refreshed credentials via `config.onAuthError`. The failed attempt's
|
|
163
|
+
* trail is already persisted to the conversation store, so the retry
|
|
164
|
+
* continues from where the stream died instead of replaying the run.
|
|
165
|
+
*/
|
|
166
|
+
private executeRunWithAuthRetry;
|
|
160
167
|
private executeRunInternal;
|
|
161
168
|
/**
|
|
162
169
|
* Initialize the contribution registry once per session. Runs
|
|
@@ -30,6 +30,7 @@ export declare const CORE_TELEMETRY_EVENTS: {
|
|
|
30
30
|
readonly AUTH_FAILED: "user.auth_failed";
|
|
31
31
|
readonly AUTH_LOGGED_OUT: "user.auth_logged_out";
|
|
32
32
|
readonly AUTH_REFRESH_SOFT_FAILURE: "user.auth_refresh_soft_failure";
|
|
33
|
+
readonly AUTH_RUN_RETRY: "user.auth_run_retry";
|
|
33
34
|
readonly PROVIDER_CONFIGURED: "user.provider_configured";
|
|
34
35
|
readonly TELEMETRY_OPT_OUT: "user.opt_out";
|
|
35
36
|
};
|
|
@@ -134,6 +135,15 @@ export declare function captureAuthRefreshSoftFailure(telemetry: ITelemetryServi
|
|
|
134
135
|
errorName?: string;
|
|
135
136
|
tokenExpired?: boolean;
|
|
136
137
|
}): void;
|
|
138
|
+
/**
|
|
139
|
+
* Fires when a run failed with an auth-like error, credentials were
|
|
140
|
+
* refreshed, and the run was retried once. `recovered: true` means the retry
|
|
141
|
+
* completed — a run that would previously have surfaced a raw provider 401
|
|
142
|
+
* (e.g. a teammate stranded on a spawn-time token snapshot past its TTL).
|
|
143
|
+
*/
|
|
144
|
+
export declare function captureAuthRunRetry(telemetry: ITelemetryService | undefined, provider?: string, details?: {
|
|
145
|
+
recovered?: boolean;
|
|
146
|
+
}): void;
|
|
137
147
|
/**
|
|
138
148
|
* Fires when the user finishes configuring a "bring your own provider"
|
|
139
149
|
* (API-key based) provider during onboarding or via settings.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as j,mkdirSync as L,readFileSync as R,writeFileSync as U}from"node:fs";import{resolve as W}from"node:path";import{resolveSessionDataDir as F}from"@cline/shared/storage";import{nanoid as H}from"nanoid";import*as J from"node-machine-id";var V="machine-id";function u(e){let t=e?.trim();if(t)return t;let a=x();if(a)return a;return I()}function $(){let e=J;return e.machineIdSync??e.default?.machineIdSync}function x(){try{let e=$();if(!e)return;return e().trim()||void 0}catch{return}}function I(){let e=F(),t=W(e,V);try{if(j(t)){let i=R(t,"utf8").trim();if(i.length>0)return i}}catch{}let a=`cl-${H()}`;try{L(e,{recursive:!0}),U(t,a,"utf8")}catch{}return a}class b{name;metadata;meter;logger;enabled;distinctId;commonProperties;counters=new Map;histograms=new Map;gauges=new Map;gaugeValues=new Map;meterProvider;loggerProvider;constructor(e){this.name=e.name??"OpenTelemetryAdapter",this.metadata={...e.metadata},this.meterProvider=e.meterProvider,this.loggerProvider=e.loggerProvider,this.meter=e.meterProvider?.getMeter("cline")??null,this.logger=e.loggerProvider?.getLogger("cline")??null,this.enabled=e.enabled??!0,this.distinctId=e.distinctId,this.commonProperties=e.commonProperties?{...e.commonProperties}:{}}emit(e,t){if(!this.isEnabled())return;this.emitLog(e,t,!1)}emitRequired(e,t){this.emitLog(e,t,!0)}recordCounter(e,t,a,i,l=!1){if(!this.meter||!l&&!this.isEnabled())return;let r=this.counters.get(e);if(!r)r=this.meter.createCounter(e,i?{description:i}:void 0),this.counters.set(e,r);r.add(t,this.flattenProperties(this.buildAttributes(a)))}recordHistogram(e,t,a,i,l=!1){if(!this.meter||!l&&!this.isEnabled())return;let r=this.histograms.get(e);if(!r)r=this.meter.createHistogram(e,i?{description:i}:void 0),this.histograms.set(e,r);r.record(t,this.flattenProperties(this.buildAttributes(a)))}recordGauge(e,t,a,i,l=!1){if(!this.meter||!l&&!this.isEnabled())return;let r=this.buildAttributes(a),s=JSON.stringify(r),g=this.gaugeValues.get(e);if(t===null){if(g){if(g.delete(s),g.size===0)this.gaugeValues.delete(e),this.gauges.delete(e)}return}let n=g;if(!n)n=new Map,this.gaugeValues.set(e,n);if(!this.gauges.has(e)){let d=this.meter.createObservableGauge(e,i?{description:i}:void 0);d.addCallback((c)=>{for(let A of this.snapshotGaugeSeries(e))c.observe(A.value,this.flattenProperties(A.attributes))}),this.gauges.set(e,d)}n.set(s,{value:t,attributes:r})}isEnabled(){return typeof this.enabled==="function"?this.enabled():this.enabled}setDistinctId(e){this.distinctId=e}setCommonProperties(e){this.commonProperties={...e}}updateCommonProperties(e){this.commonProperties={...this.commonProperties,...e}}async flush(){await Promise.all([this.meterProvider?.forceFlush?.(),this.loggerProvider?.forceFlush?.()])}async dispose(){await Promise.all([this.meterProvider?.shutdown?.(),this.loggerProvider?.shutdown?.()])}emitLog(e,t,a){if(!this.logger)return;let i=this.flattenProperties(this.buildAttributes(t,a));this.logger.emit({severityText:"INFO",body:e,attributes:i})}buildAttributes(e,t=!1){return{...this.commonProperties,...this.metadata,...e,...this.distinctId?{distinct_id:this.distinctId}:{},...t?{_required:!0}:{}}}snapshotGaugeSeries(e){let t=this.gaugeValues.get(e);if(!t)return[];return Array.from(t.values(),(a)=>({value:a.value,attributes:a.attributes?{...a.attributes}:void 0}))}flattenProperties(e,t="",a=new WeakSet,i=0){if(!e)return{};let l={},r=100,s=10;for(let[g,n]of Object.entries(e)){if(g==="__proto__"||g==="constructor"||g==="prototype")continue;let d=t?`${t}.${g}`:g;if(n===null||n===void 0){l[d]=String(n);continue}if(Array.isArray(n)){let c=n.length>r?n.slice(0,r):n;try{l[d]=JSON.stringify(c)}catch{l[d]="[UnserializableArray]"}if(n.length>r)l[`${d}_truncated`]=!0,l[`${d}_original_length`]=n.length;continue}if(typeof n==="object"){if(n instanceof Date){l[d]=n.toISOString();continue}if(n instanceof Error){l[d]=n.message;continue}if(a.has(n)){l[d]="[Circular]";continue}if(i>=s){l[d]="[MaxDepthExceeded]";continue}a.add(n),Object.assign(l,this.flattenProperties(n,d,a,i+1));continue}if(B(n)){l[d]=n;continue}try{l[d]=JSON.stringify(n)}catch{l[d]=String(n)}}return l}}function B(e){return typeof e==="string"||typeof e==="number"||typeof e==="boolean"}import{metrics as Y,trace as D}from"@opentelemetry/api";import{logs as q}from"@opentelemetry/api-logs";import{OTLPLogExporter as p}from"@opentelemetry/exporter-logs-otlp-http";import{OTLPMetricExporter as ee}from"@opentelemetry/exporter-metrics-otlp-http";import{OTLPTraceExporter as te}from"@opentelemetry/exporter-trace-otlp-http";import{resourceFromAttributes as ae}from"@opentelemetry/resources";import{BatchLogRecordProcessor as le,ConsoleLogRecordExporter as ie,LoggerProvider as re}from"@opentelemetry/sdk-logs";import{ConsoleMetricExporter as ne,MeterProvider as de,PeriodicExportingMetricReader as C}from"@opentelemetry/sdk-metrics";import{BatchSpanProcessor as se,ConsoleSpanExporter as ge,SimpleSpanProcessor as fe}from"@opentelemetry/sdk-trace-base";import{NodeTracerProvider as ue}from"@opentelemetry/sdk-trace-node";import{ATTR_SERVICE_NAME as be,ATTR_SERVICE_VERSION as oe}from"@opentelemetry/semantic-conventions";import{mkdirSync as Re,readFileSync as N,statSync as K,writeFileSync as Ue}from"node:fs";import{resolveGlobalSettingsPath as Q}from"@cline/shared/storage";import{z as f}from"zod";import{AGENT_UNEXPECTED_REASONING_TOKENS_EVENT as Ce,captureAgentUnexpectedReasoningTokens as we,SDK_ERROR_TELEMETRY_EVENT as ze}from"@cline/shared";var O=f.preprocess((e)=>Array.isArray(e)?e.filter((t)=>typeof t==="string").map((t)=>t.trim()).filter(Boolean):void 0,f.array(f.string()).optional()).transform((e)=>{if(!e)return;let t=[...new Set(e)].sort((a,i)=>a.localeCompare(i));return t.length>0?t:void 0}),Z=f.enum(["basic","agentic"]).catch("basic"),v=f.object({telemetryOptOut:f.boolean().default(!1).catch(!1),autoUpdateEnabled:f.boolean().default(!0).catch(!0),compactionStrategy:Z.optional(),disabledTools:O.optional(),disabledPlugins:O.optional()}).strip().transform((e)=>{let t={autoUpdateEnabled:e.autoUpdateEnabled,telemetryOptOut:e.telemetryOptOut};if(e.compactionStrategy)t.compactionStrategy=e.compactionStrategy;if(e.disabledTools?.length)t.disabledTools=e.disabledTools;if(e.disabledPlugins?.length)t.disabledPlugins=e.disabledPlugins;return t});function o(){return v.parse({})}var h;function _(e){if(e.disabledTools)Object.freeze(e.disabledTools);if(e.disabledPlugins)Object.freeze(e.disabledPlugins);return Object.freeze(e)}function k(e){let t;try{t=N(e,"utf8")}catch{return o()}try{let a=v.safeParse(JSON.parse(t));return a.success?a.data:o()}catch{return o()}}function E(){let e=Q(),t=K(e,{throwIfNoEntry:!1}),a=t?.mtimeMs??0,i=t?.size??0,l=h;if(l&&l.path===e&&l.mtimeMs===a&&l.size===i)return l;let r=_(t?k(e):o());return h={path:e,mtimeMs:a,size:i,value:r},h}function X(){return E().value}function G(){return X().telemetryOptOut}class P{name;logger;enabled;constructor(e={}){this.name=e.name??"TelemetryLoggerSink",this.logger=e.logger,this.enabled=e.enabled??!0}emit(e,t){if(!this.isEnabled())return;this.logger?.log("telemetry.event",{telemetrySink:this.name,event:e,properties:t})}emitRequired(e,t){this.logger?.log("telemetry.required_event",{telemetrySink:this.name,severity:"warn",event:e,properties:t})}recordCounter(e,t,a,i,l){if(!l&&!this.isEnabled())return;this.logger?.debug("telemetry.metric",{telemetrySink:this.name,instrument:"counter",name:e,value:t,attributes:a,description:i,required:l===!0})}recordHistogram(e,t,a,i,l){if(!l&&!this.isEnabled())return;this.logger?.debug("telemetry.metric",{telemetrySink:this.name,instrument:"histogram",name:e,value:t,attributes:a,description:i,required:l===!0})}recordGauge(e,t,a,i,l){if(!l&&!this.isEnabled())return;this.logger?.debug("telemetry.metric",{telemetrySink:this.name,instrument:"gauge",name:e,value:t,attributes:a,description:i,required:l===!0})}isEnabled(){return typeof this.enabled==="function"?this.enabled():this.enabled}async flush(){}async dispose(){}}class m{adapters;metadata;distinctId;commonProperties;constructor(e={}){if(this.adapters=[...e.adapters??[]],e.logger)this.adapters.push(new P({logger:e.logger}));this.metadata={...e.metadata??{}},this.distinctId=e.distinctId,this.commonProperties={...e.commonProperties??{}}}addAdapter(e){this.adapters.push(e)}setDistinctId(e){this.distinctId=e}setMetadata(e){this.metadata={...e}}updateMetadata(e){this.metadata={...this.metadata,...e}}setCommonProperties(e){this.commonProperties={...e}}updateCommonProperties(e){this.commonProperties={...this.commonProperties,...e}}isEnabled(){return this.adapters.some((e)=>e.isEnabled())}capture(e){let t=this.buildAttributes(e.properties);for(let a of this.adapters)a.emit(e.event,t)}captureRequired(e,t){let a=this.buildAttributes(t);for(let i of this.adapters)i.emitRequired(e,a)}recordCounter(e,t,a,i,l=!1){let r=this.buildAttributes(a);for(let s of this.adapters)s.recordCounter(e,t,r,i,l)}recordHistogram(e,t,a,i,l=!1){let r=this.buildAttributes(a);for(let s of this.adapters)s.recordHistogram(e,t,r,i,l)}recordGauge(e,t,a,i,l=!1){let r=this.buildAttributes(a);for(let s of this.adapters)s.recordGauge(e,t,r,i,l)}async flush(){await Promise.all(this.adapters.map((e)=>e.flush()))}async dispose(){await Promise.all(this.adapters.map((e)=>e.dispose()))}buildAttributes(e){return{...this.commonProperties,...e,...this.metadata,...this.distinctId?{distinct_id:this.distinctId}:{}}}}class w{distinctId;metadata;commonProperties;constructor(e={}){this.distinctId=e.distinctId,this.metadata={...e.metadata??{}},this.commonProperties={...e.commonProperties??{}}}setDistinctId(e){this.distinctId=e}setMetadata(e){this.metadata={...e}}updateMetadata(e){this.metadata={...this.metadata,...e}}setCommonProperties(e){this.commonProperties={...e}}updateCommonProperties(e){this.commonProperties={...this.commonProperties,...e}}isEnabled(){return!1}capture(e){this.resolveProperties(e.properties)}captureRequired(e,t){this.resolveProperties(t)}recordCounter(){}recordHistogram(){}recordGauge(){}async flush(){}async dispose(){}resolveProperties(e){return{...this.commonProperties,...e,...this.metadata,...this.distinctId?{distinct_id:this.distinctId}:{}}}}class T{meterProvider;loggerProvider;tracerProvider;options;constructor(e={}){this.options=e;let t=ae({[be]:e.serviceName??"cline",...e.serviceVersion?{[oe]:e.serviceVersion}:{}});if(this.meterProvider=this.createMeterProvider(t),this.loggerProvider=this.createLoggerProvider(t),this.tracerProvider=this.createTracerProvider(t),this.meterProvider)Y.setGlobalMeterProvider(this.meterProvider);if(this.loggerProvider)q.setGlobalLoggerProvider(this.loggerProvider);if(this.tracerProvider)this.tracerProvider.register()}getTracer(e="cline",t){return D.getTracer(e,t??this.options.serviceVersion)}createAdapter(e){return new b({...e,meterProvider:this.meterProvider,loggerProvider:this.loggerProvider})}createTelemetryService(e){let t=this.createAdapter({name:e.name,enabled:this.options.enabled,metadata:e.metadata});return new m({...e,adapters:[t],distinctId:u(e.distinctId)})}async forceFlush(){await Promise.all([this.meterProvider?.forceFlush?.(),this.loggerProvider?.forceFlush?.(),this.tracerProvider?.forceFlush?.()])}async dispose(){await Promise.all([this.meterProvider?.shutdown?.(),this.loggerProvider?.shutdown?.(),this.tracerProvider?.shutdown?.()])}createMeterProvider(e){let t=y(this.options.metricsExporter);if(t.length===0)return null;let a=Math.max(1000,this.options.metricExportIntervalMs??this.options.metricExportInterval??60000),i=Math.min(30000,Math.floor(a*0.8)),l=t.map((r)=>Pe(r,{endpoint:this.options.otlpEndpoint,headers:this.options.otlpHeaders,insecure:this.options.otlpInsecure??!1,protocol:"http/json",interval:a,timeout:i})).filter((r)=>r!==null);if(l.length===0)return null;return new de({resource:e,readers:l})}createTracerProvider(e){let t=y(this.options.tracesExporter);if(t.length===0)return null;let a=this.options.otlpTracesEndpoint??this.options.otlpEndpoint,i=this.options.otlpTracesHeaders??this.options.otlpHeaders,l=[];for(let r of t){let s=he(r,{endpoint:a,headers:i,insecure:this.options.otlpInsecure??!1,protocol:"http/json"});if(s)l.push(s)}if(l.length===0)return null;return new ue({resource:e,spanProcessors:l})}createLoggerProvider(e){let t=y(this.options.logsExporter);if(t.length===0)return null;let a=t.map((i)=>{let l=ce(i,{endpoint:this.options.otlpEndpoint,headers:this.options.otlpHeaders,insecure:this.options.otlpInsecure??!1,protocol:"http/json"});if(!l)return null;return new le(l,{maxQueueSize:this.options.logMaxQueueSize??2048,maxExportBatchSize:this.options.logBatchSize??512,scheduledDelayMillis:this.options.logBatchTimeoutMs??this.options.logBatchTimeout??5000})}).filter((i)=>i!==null);if(a.length===0)return null;return new re({resource:e,processors:a})}}function z(e){let t=new T(e),a=t.createTelemetryService(e);return a.captureRequired("telemetry.provider_created",{provider:"opentelemetry",enabled:e.enabled??!0,logsExporter:Array.isArray(e.logsExporter)?e.logsExporter.join(","):e.logsExporter,metricsExporter:Array.isArray(e.metricsExporter)?e.metricsExporter.join(","):e.metricsExporter,tracesExporter:Array.isArray(e.tracesExporter)?e.tracesExporter.join(","):e.tracesExporter,otlpProtocol:e.otlpProtocol,hasOtlpEndpoint:Boolean(e.otlpEndpoint),serviceName:e.serviceName,serviceVersion:e.serviceVersion}),{provider:t,telemetry:a}}function M(e){if(G())return{telemetry:new w(e)};if(e.enabled!==!0)return{telemetry:new m({...e,distinctId:u(e.distinctId)})};return z(e)}function me(e){let{telemetry:t,provider:a}=M(e);return{telemetry:t,provider:a,flush:async()=>{let r=a;if(r&&typeof r.forceFlush==="function")try{await r.forceFlush()}catch{}},dispose:async()=>{await Promise.allSettled([t.dispose(),a?.dispose()])}}}function y(e){if(!e)return[];return(Array.isArray(e)?e:e.split(",")).map((a)=>a.trim()).filter((a)=>a==="console"||a==="otlp")}function ce(e,t){if(e==="console")return new ie;if(!t.endpoint)return null;let a=S(t.endpoint,"/v1/logs");return new p({url:a,headers:t.headers})}function he(e,t){if(e==="console")return new fe(new ge);if(!t.endpoint)return null;let a=S(t.endpoint,"/v1/traces");return new se(new te({url:a,headers:t.headers}))}function Pe(e,t){if(e==="console")return new C({exporter:new ne,exportIntervalMillis:t.interval,exportTimeoutMillis:t.timeout});if(!t.endpoint)return null;let a=S(t.endpoint,"/v1/metrics");return new C({exporter:new ee({url:a,headers:t.headers}),exportIntervalMillis:t.interval,exportTimeoutMillis:t.timeout})}function S(e,t){let a=new URL(e),i=a.pathname.endsWith("/")?a.pathname.slice(0,-1):a.pathname;return a.pathname=i.endsWith(t)?i:`${i}${t}`,a.toString()}export{u as resolveCoreDistinctId,z as createOpenTelemetryTelemetryService,M as createConfiguredTelemetryService,me as createConfiguredTelemetryHandle,T as OpenTelemetryProvider,b as OpenTelemetryAdapter};
|
|
1
|
+
import{existsSync as j,mkdirSync as L,readFileSync as R,writeFileSync as U}from"node:fs";import{resolve as W}from"node:path";import{resolveSessionDataDir as F}from"@cline/shared/storage";import{nanoid as H}from"nanoid";import*as J from"node-machine-id";var V="machine-id";function u(e){let t=e?.trim();if(t)return t;let a=x();if(a)return a;return I()}function $(){let e=J;return e.machineIdSync??e.default?.machineIdSync}function x(){try{let e=$();if(!e)return;return e().trim()||void 0}catch{return}}function I(){let e=F(),t=W(e,V);try{if(j(t)){let i=R(t,"utf8").trim();if(i.length>0)return i}}catch{}let a=`cl-${H()}`;try{L(e,{recursive:!0}),U(t,a,"utf8")}catch{}return a}class b{name;metadata;meter;logger;enabled;distinctId;commonProperties;counters=new Map;histograms=new Map;gauges=new Map;gaugeValues=new Map;meterProvider;loggerProvider;constructor(e){this.name=e.name??"OpenTelemetryAdapter",this.metadata={...e.metadata},this.meterProvider=e.meterProvider,this.loggerProvider=e.loggerProvider,this.meter=e.meterProvider?.getMeter("cline")??null,this.logger=e.loggerProvider?.getLogger("cline")??null,this.enabled=e.enabled??!0,this.distinctId=e.distinctId,this.commonProperties=e.commonProperties?{...e.commonProperties}:{}}emit(e,t){if(!this.isEnabled())return;this.emitLog(e,t,!1)}emitRequired(e,t){this.emitLog(e,t,!0)}recordCounter(e,t,a,i,l=!1){if(!this.meter||!l&&!this.isEnabled())return;let r=this.counters.get(e);if(!r)r=this.meter.createCounter(e,i?{description:i}:void 0),this.counters.set(e,r);r.add(t,this.flattenProperties(this.buildAttributes(a)))}recordHistogram(e,t,a,i,l=!1){if(!this.meter||!l&&!this.isEnabled())return;let r=this.histograms.get(e);if(!r)r=this.meter.createHistogram(e,i?{description:i}:void 0),this.histograms.set(e,r);r.record(t,this.flattenProperties(this.buildAttributes(a)))}recordGauge(e,t,a,i,l=!1){if(!this.meter||!l&&!this.isEnabled())return;let r=this.buildAttributes(a),d=JSON.stringify(r),g=this.gaugeValues.get(e);if(t===null){if(g){if(g.delete(d),g.size===0)this.gaugeValues.delete(e),this.gauges.delete(e)}return}let n=g;if(!n)n=new Map,this.gaugeValues.set(e,n);if(!this.gauges.has(e)){let s=this.meter.createObservableGauge(e,i?{description:i}:void 0);s.addCallback((c)=>{for(let A of this.snapshotGaugeSeries(e))c.observe(A.value,this.flattenProperties(A.attributes))}),this.gauges.set(e,s)}n.set(d,{value:t,attributes:r})}isEnabled(){return typeof this.enabled==="function"?this.enabled():this.enabled}setDistinctId(e){this.distinctId=e}setCommonProperties(e){this.commonProperties={...e}}updateCommonProperties(e){this.commonProperties={...this.commonProperties,...e}}async flush(){await Promise.all([this.meterProvider?.forceFlush?.(),this.loggerProvider?.forceFlush?.()])}async dispose(){await Promise.all([this.meterProvider?.shutdown?.(),this.loggerProvider?.shutdown?.()])}emitLog(e,t,a){if(!this.logger)return;let i=this.flattenProperties(this.buildAttributes(t,a));this.logger.emit({severityText:"INFO",body:e,attributes:i})}buildAttributes(e,t=!1){return{...this.commonProperties,...this.metadata,...e,...this.distinctId?{distinct_id:this.distinctId}:{},...t?{_required:!0}:{}}}snapshotGaugeSeries(e){let t=this.gaugeValues.get(e);if(!t)return[];return Array.from(t.values(),(a)=>({value:a.value,attributes:a.attributes?{...a.attributes}:void 0}))}flattenProperties(e,t="",a=new WeakSet,i=0){if(!e)return{};let l={},r=100,d=10;for(let[g,n]of Object.entries(e)){if(g==="__proto__"||g==="constructor"||g==="prototype")continue;let s=t?`${t}.${g}`:g;if(n===null||n===void 0){l[s]=String(n);continue}if(Array.isArray(n)){let c=n.length>r?n.slice(0,r):n;try{l[s]=JSON.stringify(c)}catch{l[s]="[UnserializableArray]"}if(n.length>r)l[`${s}_truncated`]=!0,l[`${s}_original_length`]=n.length;continue}if(typeof n==="object"){if(n instanceof Date){l[s]=n.toISOString();continue}if(n instanceof Error){l[s]=n.message;continue}if(a.has(n)){l[s]="[Circular]";continue}if(i>=d){l[s]="[MaxDepthExceeded]";continue}a.add(n),Object.assign(l,this.flattenProperties(n,s,a,i+1));continue}if(B(n)){l[s]=n;continue}try{l[s]=JSON.stringify(n)}catch{l[s]=String(n)}}return l}}function B(e){return typeof e==="string"||typeof e==="number"||typeof e==="boolean"}import{metrics as Y,trace as D}from"@opentelemetry/api";import{logs as q}from"@opentelemetry/api-logs";import{OTLPLogExporter as p}from"@opentelemetry/exporter-logs-otlp-http";import{OTLPMetricExporter as ee}from"@opentelemetry/exporter-metrics-otlp-http";import{OTLPTraceExporter as te}from"@opentelemetry/exporter-trace-otlp-http";import{resourceFromAttributes as ae}from"@opentelemetry/resources";import{BatchLogRecordProcessor as le,ConsoleLogRecordExporter as ie,LoggerProvider as re}from"@opentelemetry/sdk-logs";import{ConsoleMetricExporter as ne,MeterProvider as se,PeriodicExportingMetricReader as C}from"@opentelemetry/sdk-metrics";import{BatchSpanProcessor as de,ConsoleSpanExporter as ge,SimpleSpanProcessor as fe}from"@opentelemetry/sdk-trace-base";import{NodeTracerProvider as ue}from"@opentelemetry/sdk-trace-node";import{ATTR_SERVICE_NAME as be,ATTR_SERVICE_VERSION as oe}from"@opentelemetry/semantic-conventions";import{mkdirSync as Re,readFileSync as N,statSync as K,writeFileSync as Ue}from"node:fs";import{resolveGlobalSettingsPath as Q}from"@cline/shared/storage";import{z as f}from"zod";import{AGENT_UNEXPECTED_REASONING_TOKENS_EVENT as Ce,captureAgentUnexpectedReasoningTokens as we,SDK_ERROR_TELEMETRY_EVENT as ze}from"@cline/shared";var O=f.preprocess((e)=>Array.isArray(e)?e.filter((t)=>typeof t==="string").map((t)=>t.trim()).filter(Boolean):void 0,f.array(f.string()).optional()).transform((e)=>{if(!e)return;let t=[...new Set(e)].sort((a,i)=>a.localeCompare(i));return t.length>0?t:void 0}),Z=f.enum(["basic","agentic"]).catch("basic"),v=f.object({telemetryOptOut:f.boolean().default(!1).catch(!1),autoUpdateEnabled:f.boolean().default(!0).catch(!0),compactionStrategy:Z.optional(),disabledTools:O.optional(),disabledPlugins:O.optional()}).strip().transform((e)=>{let t={autoUpdateEnabled:e.autoUpdateEnabled,telemetryOptOut:e.telemetryOptOut};if(e.compactionStrategy)t.compactionStrategy=e.compactionStrategy;if(e.disabledTools?.length)t.disabledTools=e.disabledTools;if(e.disabledPlugins?.length)t.disabledPlugins=e.disabledPlugins;return t});function o(){return v.parse({})}var h;function _(e){if(e.disabledTools)Object.freeze(e.disabledTools);if(e.disabledPlugins)Object.freeze(e.disabledPlugins);return Object.freeze(e)}function k(e){let t;try{t=N(e,"utf8")}catch{return o()}try{let a=v.safeParse(JSON.parse(t));return a.success?a.data:o()}catch{return o()}}function E(){let e=Q(),t=K(e,{throwIfNoEntry:!1}),a=t?.mtimeMs??0,i=t?.size??0,l=h;if(l&&l.path===e&&l.mtimeMs===a&&l.size===i)return l;let r=_(t?k(e):o());return h={path:e,mtimeMs:a,size:i,value:r},h}function X(){return E().value}function G(){return X().telemetryOptOut}class P{name;logger;enabled;constructor(e={}){this.name=e.name??"TelemetryLoggerSink",this.logger=e.logger,this.enabled=e.enabled??!0}emit(e,t){if(!this.isEnabled())return;this.logger?.log("telemetry.event",{telemetrySink:this.name,event:e,properties:t})}emitRequired(e,t){this.logger?.log("telemetry.required_event",{telemetrySink:this.name,severity:"warn",event:e,properties:t})}recordCounter(e,t,a,i,l){if(!l&&!this.isEnabled())return;this.logger?.debug("telemetry.metric",{telemetrySink:this.name,instrument:"counter",name:e,value:t,attributes:a,description:i,required:l===!0})}recordHistogram(e,t,a,i,l){if(!l&&!this.isEnabled())return;this.logger?.debug("telemetry.metric",{telemetrySink:this.name,instrument:"histogram",name:e,value:t,attributes:a,description:i,required:l===!0})}recordGauge(e,t,a,i,l){if(!l&&!this.isEnabled())return;this.logger?.debug("telemetry.metric",{telemetrySink:this.name,instrument:"gauge",name:e,value:t,attributes:a,description:i,required:l===!0})}isEnabled(){return typeof this.enabled==="function"?this.enabled():this.enabled}async flush(){}async dispose(){}}class m{adapters;metadata;distinctId;commonProperties;constructor(e={}){if(this.adapters=[...e.adapters??[]],e.logger)this.adapters.push(new P({logger:e.logger}));this.metadata={...e.metadata??{}},this.distinctId=e.distinctId,this.commonProperties={...e.commonProperties??{}}}addAdapter(e){this.adapters.push(e)}setDistinctId(e){this.distinctId=e}setMetadata(e){this.metadata={...e}}updateMetadata(e){this.metadata={...this.metadata,...e}}setCommonProperties(e){this.commonProperties={...e}}updateCommonProperties(e){this.commonProperties={...this.commonProperties,...e}}isEnabled(){return this.adapters.some((e)=>e.isEnabled())}capture(e){let t=this.buildAttributes(e.properties);for(let a of this.adapters)a.emit(e.event,t)}captureRequired(e,t){let a=this.buildAttributes(t);for(let i of this.adapters)i.emitRequired(e,a)}recordCounter(e,t,a,i,l=!1){let r=this.buildAttributes(a);for(let d of this.adapters)d.recordCounter(e,t,r,i,l)}recordHistogram(e,t,a,i,l=!1){let r=this.buildAttributes(a);for(let d of this.adapters)d.recordHistogram(e,t,r,i,l)}recordGauge(e,t,a,i,l=!1){let r=this.buildAttributes(a);for(let d of this.adapters)d.recordGauge(e,t,r,i,l)}async flush(){await Promise.all(this.adapters.map((e)=>e.flush()))}async dispose(){await Promise.all(this.adapters.map((e)=>e.dispose()))}buildAttributes(e){return{...this.commonProperties,...e,...this.metadata,...this.distinctId?{distinct_id:this.distinctId}:{}}}}class w{distinctId;metadata;commonProperties;constructor(e={}){this.distinctId=e.distinctId,this.metadata={...e.metadata??{}},this.commonProperties={...e.commonProperties??{}}}setDistinctId(e){this.distinctId=e}setMetadata(e){this.metadata={...e}}updateMetadata(e){this.metadata={...this.metadata,...e}}setCommonProperties(e){this.commonProperties={...e}}updateCommonProperties(e){this.commonProperties={...this.commonProperties,...e}}isEnabled(){return!1}capture(e){this.resolveProperties(e.properties)}captureRequired(e,t){this.resolveProperties(t)}recordCounter(){}recordHistogram(){}recordGauge(){}async flush(){}async dispose(){}resolveProperties(e){return{...this.commonProperties,...e,...this.metadata,...this.distinctId?{distinct_id:this.distinctId}:{}}}}class T{meterProvider;loggerProvider;tracerProvider;options;constructor(e={}){this.options=e;let t=ae({[be]:e.serviceName??"cline",...e.serviceVersion?{[oe]:e.serviceVersion}:{}});if(this.meterProvider=this.createMeterProvider(t),this.loggerProvider=this.createLoggerProvider(t),this.tracerProvider=this.createTracerProvider(t),this.meterProvider)Y.setGlobalMeterProvider(this.meterProvider);if(this.loggerProvider)q.setGlobalLoggerProvider(this.loggerProvider);if(this.tracerProvider)this.tracerProvider.register()}getTracer(e="cline",t){return D.getTracer(e,t??this.options.serviceVersion)}createAdapter(e){return new b({...e,meterProvider:this.meterProvider,loggerProvider:this.loggerProvider})}createTelemetryService(e){let t=this.createAdapter({name:e.name,enabled:this.options.enabled,metadata:e.metadata});return new m({...e,adapters:[t],distinctId:u(e.distinctId)})}async forceFlush(){await Promise.all([this.meterProvider?.forceFlush?.(),this.loggerProvider?.forceFlush?.(),this.tracerProvider?.forceFlush?.()])}async dispose(){await Promise.all([this.meterProvider?.shutdown?.(),this.loggerProvider?.shutdown?.(),this.tracerProvider?.shutdown?.()])}createMeterProvider(e){let t=y(this.options.metricsExporter);if(t.length===0)return null;let a=Math.max(1000,this.options.metricExportIntervalMs??this.options.metricExportInterval??60000),i=Math.min(30000,Math.floor(a*0.8)),l=t.map((r)=>Pe(r,{endpoint:this.options.otlpEndpoint,headers:this.options.otlpHeaders,insecure:this.options.otlpInsecure??!1,protocol:"http/json",interval:a,timeout:i})).filter((r)=>r!==null);if(l.length===0)return null;return new se({resource:e,readers:l})}createTracerProvider(e){let t=y(this.options.tracesExporter);if(t.length===0)return null;let a=this.options.otlpTracesEndpoint??this.options.otlpEndpoint,i=this.options.otlpTracesHeaders??this.options.otlpHeaders,l=[];for(let r of t){let d=he(r,{endpoint:a,headers:i,insecure:this.options.otlpInsecure??!1,protocol:"http/json"});if(d)l.push(d)}if(l.length===0)return null;return new ue({resource:e,spanProcessors:l})}createLoggerProvider(e){let t=y(this.options.logsExporter);if(t.length===0)return null;let a=t.map((i)=>{let l=ce(i,{endpoint:this.options.otlpEndpoint,headers:this.options.otlpHeaders,insecure:this.options.otlpInsecure??!1,protocol:"http/json"});if(!l)return null;return new le(l,{maxQueueSize:this.options.logMaxQueueSize??2048,maxExportBatchSize:this.options.logBatchSize??512,scheduledDelayMillis:this.options.logBatchTimeoutMs??this.options.logBatchTimeout??5000})}).filter((i)=>i!==null);if(a.length===0)return null;return new re({resource:e,processors:a})}}function z(e){let t=new T(e),a=t.createTelemetryService(e);return a.captureRequired("telemetry.provider_created",{provider:"opentelemetry",enabled:e.enabled??!0,logsExporter:Array.isArray(e.logsExporter)?e.logsExporter.join(","):e.logsExporter,metricsExporter:Array.isArray(e.metricsExporter)?e.metricsExporter.join(","):e.metricsExporter,tracesExporter:Array.isArray(e.tracesExporter)?e.tracesExporter.join(","):e.tracesExporter,otlpProtocol:e.otlpProtocol,hasOtlpEndpoint:Boolean(e.otlpEndpoint),serviceName:e.serviceName,serviceVersion:e.serviceVersion}),{provider:t,telemetry:a}}function M(e){if(G())return{telemetry:new w(e)};if(e.enabled!==!0)return{telemetry:new m({...e,distinctId:u(e.distinctId)})};return z(e)}function me(e){let{telemetry:t,provider:a}=M(e);return{telemetry:t,provider:a,flush:async()=>{let r=a;if(r&&typeof r.forceFlush==="function")try{await r.forceFlush()}catch{}},dispose:async()=>{await Promise.allSettled([t.dispose(),a?.dispose()])}}}function y(e){if(!e)return[];return(Array.isArray(e)?e:e.split(",")).map((a)=>a.trim()).filter((a)=>a==="console"||a==="otlp")}function ce(e,t){if(e==="console")return new ie;if(!t.endpoint)return null;let a=S(t.endpoint,"/v1/logs");return new p({url:a,headers:t.headers})}function he(e,t){if(e==="console")return new fe(new ge);if(!t.endpoint)return null;let a=S(t.endpoint,"/v1/traces");return new de(new te({url:a,headers:t.headers}))}function Pe(e,t){if(e==="console")return new C({exporter:new ne,exportIntervalMillis:t.interval,exportTimeoutMillis:t.timeout});if(!t.endpoint)return null;let a=S(t.endpoint,"/v1/metrics");return new C({exporter:new ee({url:a,headers:t.headers}),exportIntervalMillis:t.interval,exportTimeoutMillis:t.timeout})}function S(e,t){let a=new URL(e),i=a.pathname.endsWith("/")?a.pathname.slice(0,-1):a.pathname;return a.pathname=i.endsWith(t)?i:`${i}${t}`,a.toString()}export{u as resolveCoreDistinctId,z as createOpenTelemetryTelemetryService,M as createConfiguredTelemetryService,me as createConfiguredTelemetryHandle,T as OpenTelemetryProvider,b as OpenTelemetryAdapter};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cline/core",
|
|
3
3
|
"description": "Cline Core SDK for Node Runtime",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.65",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/cline/cline",
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
"test:watch": "vitest --config vitest.config.ts"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@cline/agents": "0.0.
|
|
52
|
-
"@cline/shared": "0.0.
|
|
53
|
-
"@cline/llms": "0.0.
|
|
51
|
+
"@cline/agents": "0.0.65",
|
|
52
|
+
"@cline/shared": "0.0.65",
|
|
53
|
+
"@cline/llms": "0.0.65",
|
|
54
54
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
55
55
|
"@opentelemetry/api": "^1.9.0",
|
|
56
56
|
"@opentelemetry/api-logs": "^0.214.0",
|