Skip to content

Commit 512754b

Browse files
authored
Merge branch 'main' into feat/remote-control-relay-key
2 parents 55217b6 + 455f290 commit 512754b

5 files changed

Lines changed: 8 additions & 73 deletions

File tree

apps/pythinker-code/src/utils/region.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ export interface PythinkerRegionProfile {
99
readonly telemetryEndpoint: string;
1010
}
1111

12+
// Pythinker runs a single telemetry host, so every region reports to it.
13+
const TELEMETRY_ENDPOINT = 'https://telemetry-logs.pythinker.com/v1/event';
14+
1215
const PROFILES: Record<PythinkerRegion, PythinkerRegionProfile> = {
1316
'mainland-cn': {
14-
telemetryEndpoint: 'https://telemetry-logs.pythinker.com/v1/event',
17+
telemetryEndpoint: TELEMETRY_ENDPOINT,
1518
},
1619
global: {
17-
telemetryEndpoint: 'https://telemetry-logs.pythinker.ai/v1/event',
20+
telemetryEndpoint: TELEMETRY_ENDPOINT,
1821
},
1922
};
2023

packages/agent-core-v2/src/app/telemetry/cloudAppender.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ export class CloudAppender implements ITelemetryAppender {
8484
storage: options.storage,
8585
deviceId: options.deviceId,
8686
endpoint: options.endpoint,
87-
homeDir: options.bootstrap.homeDir,
88-
readMarker:
89-
(options.bootstrap.getEnv('PYTHINKER_CODE_REGION_MARKER') ??
90-
process.env['PYTHINKER_CODE_REGION_MARKER']) !== 'off',
9187
getAccessToken: options.getAccessToken,
9288
fetchImpl: options.fetchImpl,
9389
retryBackoffsMs: options.retryBackoffsMs,

packages/agent-core-v2/src/app/telemetry/cloudTransport.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { randomBytes } from 'node:crypto';
2-
import { readFileSync } from 'node:fs';
3-
import { join } from 'node:path';
42

53
import { isAbortError } from '#/_base/utils/abort';
64
import type { IFileSystemStorageService } from '#/persistence/interface/storage';
@@ -33,8 +31,6 @@ export interface CloudTransportOptions {
3331
readonly storage: IFileSystemStorageService;
3432
readonly deviceId: string;
3533
readonly endpoint?: string;
36-
readonly homeDir?: string;
37-
readonly readMarker?: boolean;
3834
readonly getAccessToken?: () => string | null | Promise<string | null>;
3935
readonly fetchImpl?: typeof fetch;
4036
readonly retryBackoffsMs?: readonly number[];
@@ -50,25 +46,13 @@ export const DISK_EVENT_MAX_AGE_MS = 7 * 24 * 60 * 60 * 1000;
5046
export const RETRY_BACKOFFS_MS = [1_000, 4_000, 16_000] as const;
5147

5248
const DEFAULT_REQUEST_TIMEOUT_MS = 10_000;
53-
const GLOBAL_TELEMETRY_ENDPOINT = 'https://telemetry-logs.pythinker.ai/v1/event';
5449
const TELEMETRY_SCOPE = 'telemetry';
5550
const FAILED_PREFIX = 'failed_';
5651
const JSONL_SUFFIX = '.jsonl';
5752

5853
const textEncoder = new TextEncoder();
5954
const textDecoder = new TextDecoder();
6055

61-
function defaultTelemetryEndpoint(homeDir?: string, readMarker = true): string {
62-
if (!readMarker || homeDir === undefined) return TELEMETRY_ENDPOINT;
63-
try {
64-
return readFileSync(join(homeDir, 'region'), 'utf8').trim() === 'global'
65-
? GLOBAL_TELEMETRY_ENDPOINT
66-
: TELEMETRY_ENDPOINT;
67-
} catch {
68-
return TELEMETRY_ENDPOINT;
69-
}
70-
}
71-
7256
export class CloudTransport {
7357
private readonly storage: IFileSystemStorageService;
7458
private readonly deviceId: string;
@@ -83,7 +67,7 @@ export class CloudTransport {
8367
constructor(options: CloudTransportOptions) {
8468
this.storage = options.storage;
8569
this.deviceId = options.deviceId;
86-
this.endpoint = options.endpoint ?? defaultTelemetryEndpoint(options.homeDir, options.readMarker);
70+
this.endpoint = options.endpoint ?? TELEMETRY_ENDPOINT;
8771
this.getAccessToken = options.getAccessToken ?? null;
8872
this.fetchImpl = options.fetchImpl ?? globalThis.fetch.bind(globalThis);
8973
this.retryBackoffsMs = options.retryBackoffsMs ?? RETRY_BACKOFFS_MS;

packages/agent-core-v2/test/app/telemetry/cloudAppender.test.ts

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ describe('CloudAppender', () => {
111111
expect(typeof event?.['timestamp']).toBe('number');
112112
});
113113

114-
it('reads the install marker from the bootstrapped home for the default endpoint', async () => {
114+
it('reports to the single telemetry host whatever the install marker says', async () => {
115115
writeFileSync(join(homeDir, 'region'), 'global\n');
116116
const requests: CapturedRequest[] = [];
117117
const appender = new CloudAppender(
@@ -127,58 +127,10 @@ describe('CloudAppender', () => {
127127
appender.track('tool.call', { name: 'bash' });
128128
await appender.flush();
129129

130-
expect(requests).toHaveLength(1);
131-
expect(requests[0]?.url).toBe('https://telemetry-logs.pythinker.ai/v1/event');
132-
});
133-
134-
it('honors the marker opt-out from the bootstrap env bag (no process.env needed)', async () => {
135-
writeFileSync(join(homeDir, 'region'), 'global\n');
136-
const requests: CapturedRequest[] = [];
137-
const appender = new CloudAppender(
138-
baseOptions({
139-
homeDir,
140-
bootstrapEnv: { PYTHINKER_CODE_REGION_MARKER: 'off' },
141-
fetchImpl: makeFetch((req) => {
142-
requests.push(req);
143-
return okResponse();
144-
}),
145-
}),
146-
);
147-
148-
appender.track('tool.call', { name: 'bash' });
149-
await appender.flush();
150-
151130
expect(requests).toHaveLength(1);
152131
expect(requests[0]?.url).toBe('https://telemetry-logs.pythinker.com/v1/event');
153132
});
154133

155-
it('honors PYTHINKER_CODE_REGION_MARKER=off so embedded servers ignore the install marker', async () => {
156-
writeFileSync(join(homeDir, 'region'), 'global\n');
157-
const savedMarkerFlag = process.env['PYTHINKER_CODE_REGION_MARKER'];
158-
process.env['PYTHINKER_CODE_REGION_MARKER'] = 'off';
159-
try {
160-
const requests: CapturedRequest[] = [];
161-
const appender = new CloudAppender(
162-
baseOptions({
163-
homeDir,
164-
fetchImpl: makeFetch((req) => {
165-
requests.push(req);
166-
return okResponse();
167-
}),
168-
}),
169-
);
170-
171-
appender.track('tool.call', { name: 'bash' });
172-
await appender.flush();
173-
174-
expect(requests).toHaveLength(1);
175-
expect(requests[0]?.url).toBe('https://telemetry-logs.pythinker.com/v1/event');
176-
} finally {
177-
if (savedMarkerFlag === undefined) delete process.env['PYTHINKER_CODE_REGION_MARKER'];
178-
else process.env['PYTHINKER_CODE_REGION_MARKER'] = savedMarkerFlag;
179-
}
180-
});
181-
182134
it('applies setContext sessionId and model updates to subsequent events', async () => {
183135
const requests: CapturedRequest[] = [];
184136
const appender = new CloudAppender(

packages/agent-gateway/test/setup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ process.env['PYTHINKER_CODE_EXPERIMENTAL_SEARCH_WORKER'] = 'false';
1010
process.env['PYTHINKER_CODE_EXPERIMENTAL_PERSISTENCE_MINIDB_READMODEL'] = 'false';
1111

1212
const realFetch = globalThis.fetch.bind(globalThis);
13-
const TELEMETRY_HOSTS = new Set(['telemetry-logs.pythinker.com', 'telemetry-logs.pythinker.ai']);
13+
const TELEMETRY_HOSTS = new Set(['telemetry-logs.pythinker.com']);
1414
globalThis.fetch = ((input: string | URL | Request, init?: RequestInit) => {
1515
const url = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url;
1616
if (TELEMETRY_HOSTS.has(new URL(url).hostname)) {

0 commit comments

Comments
 (0)