@portel/photon 1.31.2 → 1.32.2

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.
@@ -25,9 +25,16 @@ export interface RequestContext {
25
25
  * `this.callerCwd`.
26
26
  */
27
27
  cwd?: string;
28
+ /**
29
+ * Resolved PHOTON_DIR for the currently loading/executing photon.
30
+ * In the single in-process daemon, several PHOTON_DIRs can execute
31
+ * concurrently, so this must be async-local rather than process-global.
32
+ */
33
+ photonDir?: string;
28
34
  /** Wall-clock start of the tool call. */
29
35
  startedAt: number;
30
36
  }
31
37
  export declare function runWithRequestContext<T>(ctx: RequestContext, fn: () => T): T;
32
38
  export declare function getRequestContext(): RequestContext | undefined;
39
+ export declare function runWithPhotonDir<T>(photonDir: string, fn: () => T): T;
33
40
  //# sourceMappingURL=context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/telemetry/context.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEtD,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,qEAAqE;IACrE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,8EAA8E;IAC9E,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,2CAA2C;IAC3C,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB;;;;;;;OAOG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,yCAAyC;IACzC,SAAS,EAAE,MAAM,CAAC;CACnB;AAID,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,GAAG,EAAE,cAAc,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAE5E;AAED,wBAAgB,iBAAiB,IAAI,cAAc,GAAG,SAAS,CAE9D"}
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/telemetry/context.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEtD,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,qEAAqE;IACrE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,8EAA8E;IAC9E,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,2CAA2C;IAC3C,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB;;;;;;;OAOG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yCAAyC;IACzC,SAAS,EAAE,MAAM,CAAC;CACnB;AAyDD,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,GAAG,EAAE,cAAc,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAE5E;AAED,wBAAgB,iBAAiB,IAAI,cAAc,GAAG,SAAS,CAE9D;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAerE"}
@@ -8,10 +8,81 @@
8
8
  */
9
9
  import { AsyncLocalStorage } from 'node:async_hooks';
10
10
  const storage = new AsyncLocalStorage();
11
+ let envProxyInstalled = false;
12
+ /**
13
+ * Expose PHOTON_DIR through AsyncLocalStorage for legacy/user code that reads
14
+ * `process.env.PHOTON_DIR` directly. Node's process.env object cannot define
15
+ * accessor properties, but process.env itself can be replaced with a Proxy.
16
+ *
17
+ * This is intentionally narrow: every other env key keeps native semantics.
18
+ * Writes to PHOTON_DIR still update the backing env for CLI/test code; daemon
19
+ * load/execution reads prefer the async-local photonDir when present.
20
+ */
21
+ function installPhotonDirEnvProxy() {
22
+ if (envProxyInstalled)
23
+ return;
24
+ envProxyInstalled = true;
25
+ const backing = process.env;
26
+ process.env = new Proxy(backing, {
27
+ get(target, prop, receiver) {
28
+ if (prop === 'PHOTON_DIR') {
29
+ return storage.getStore()?.photonDir ?? Reflect.get(target, prop, receiver);
30
+ }
31
+ return Reflect.get(target, prop, receiver);
32
+ },
33
+ has(target, prop) {
34
+ if (prop === 'PHOTON_DIR' && storage.getStore()?.photonDir)
35
+ return true;
36
+ return Reflect.has(target, prop);
37
+ },
38
+ ownKeys(target) {
39
+ const keys = Reflect.ownKeys(target);
40
+ return storage.getStore()?.photonDir && !keys.includes('PHOTON_DIR')
41
+ ? [...keys, 'PHOTON_DIR']
42
+ : keys;
43
+ },
44
+ getOwnPropertyDescriptor(target, prop) {
45
+ if (prop === 'PHOTON_DIR' && storage.getStore()?.photonDir) {
46
+ return {
47
+ configurable: true,
48
+ enumerable: true,
49
+ writable: true,
50
+ value: storage.getStore()?.photonDir,
51
+ };
52
+ }
53
+ return Reflect.getOwnPropertyDescriptor(target, prop);
54
+ },
55
+ set(target, prop, value, receiver) {
56
+ return Reflect.set(target, prop, value, receiver);
57
+ },
58
+ deleteProperty(target, prop) {
59
+ return Reflect.deleteProperty(target, prop);
60
+ },
61
+ });
62
+ }
63
+ installPhotonDirEnvProxy();
11
64
  export function runWithRequestContext(ctx, fn) {
12
65
  return storage.run(ctx, fn);
13
66
  }
14
67
  export function getRequestContext() {
15
68
  return storage.getStore();
16
69
  }
70
+ export function runWithPhotonDir(photonDir, fn) {
71
+ const existing = storage.getStore();
72
+ const ctx = {
73
+ photon: existing?.photon ?? '__load__',
74
+ tool: existing?.tool ?? '__load__',
75
+ photonDir,
76
+ startedAt: existing?.startedAt ?? Date.now(),
77
+ };
78
+ if (existing?.traceId !== undefined)
79
+ ctx.traceId = existing.traceId;
80
+ if (existing?.parentTraceparent !== undefined)
81
+ ctx.parentTraceparent = existing.parentTraceparent;
82
+ if (existing?.caller !== undefined)
83
+ ctx.caller = existing.caller;
84
+ if (existing?.cwd !== undefined)
85
+ ctx.cwd = existing.cwd;
86
+ return storage.run(ctx, fn);
87
+ }
17
88
  //# sourceMappingURL=context.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/telemetry/context.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAyBrD,MAAM,OAAO,GAAG,IAAI,iBAAiB,EAAkB,CAAC;AAExD,MAAM,UAAU,qBAAqB,CAAI,GAAmB,EAAE,EAAW;IACvE,OAAO,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,iBAAiB;IAC/B,OAAO,OAAO,CAAC,QAAQ,EAAE,CAAC;AAC5B,CAAC"}
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/telemetry/context.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AA+BrD,MAAM,OAAO,GAAG,IAAI,iBAAiB,EAAkB,CAAC;AACxD,IAAI,iBAAiB,GAAG,KAAK,CAAC;AAE9B;;;;;;;;GAQG;AACH,SAAS,wBAAwB;IAC/B,IAAI,iBAAiB;QAAE,OAAO;IAC9B,iBAAiB,GAAG,IAAI,CAAC;IACzB,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC;IAC5B,OAAO,CAAC,GAAG,GAAG,IAAI,KAAK,CAAC,OAAO,EAAE;QAC/B,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ;YACxB,IAAI,IAAI,KAAK,YAAY,EAAE,CAAC;gBAC1B,OAAO,OAAO,CAAC,QAAQ,EAAE,EAAE,SAAS,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;YAC9E,CAAC;YACD,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC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M,UAAU,qBAAqB,CAAI,GAAmB,EAAE,EAAW;IACvE,OAAO,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,iBAAiB;IAC/B,OAAO,OAAO,CAAC,QAAQ,EAAE,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAI,SAAiB,EAAE,EAAW;IAChE,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IACpC,MAAM,GAAG,GAAmB;QAC1B,MAAM,EAAE,QAAQ,EAAE,MAAM,IAAI,UAAU;QACtC,IAAI,EAAE,QAAQ,EAAE,IAAI,IAAI,UAAU;QAClC,SAAS;QACT,SAAS,EAAE,QAAQ,EAAE,SAAS,IAAI,IAAI,CAAC,GAAG,EAAE;KAC7C,CAAC;IAEF,IAAI,QAAQ,EAAE,OAAO,KAAK,SAAS;QAAE,GAAG,CAAC,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;IACpE,IAAI,QAAQ,EAAE,iBAAiB,KAAK,SAAS;QAAE,GAAG,CAAC,iBAAiB,GAAG,QAAQ,CAAC,iBAAiB,CAAC;IAClG,IAAI,QAAQ,EAAE,MAAM,KAAK,SAAS;QAAE,GAAG,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;IACjE,IAAI,QAAQ,EAAE,GAAG,KAAK,SAAS;QAAE,GAAG,CAAC,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC;IAExD,OAAO,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;AAC9B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portel/photon",
3
- "version": "1.31.2",
3
+ "version": "1.32.2",
4
4
  "description": "You focus on the business logic. We'll enable the rest. Build MCP servers and CLI tools in a single TypeScript file.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",