@portel/photon 1.21.0 → 1.22.1
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/ag-ui/adapter.d.ts +4 -1
- package/dist/ag-ui/adapter.d.ts.map +1 -1
- package/dist/ag-ui/adapter.js +33 -3
- package/dist/ag-ui/adapter.js.map +1 -1
- package/dist/ag-ui/types.d.ts +12 -0
- package/dist/ag-ui/types.d.ts.map +1 -1
- package/dist/auto-ui/beam/routes/api-config.d.ts +1 -1
- package/dist/auto-ui/beam/routes/api-config.d.ts.map +1 -1
- package/dist/auto-ui/beam/routes/api-config.js +79 -1
- package/dist/auto-ui/beam/routes/api-config.js.map +1 -1
- package/dist/auto-ui/streamable-http-transport.d.ts.map +1 -1
- package/dist/auto-ui/streamable-http-transport.js +24 -2
- package/dist/auto-ui/streamable-http-transport.js.map +1 -1
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +3 -3
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli.d.ts +4 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +11 -1
- package/dist/cli.js.map +1 -1
- package/dist/daemon/protocol.d.ts +1 -1
- package/dist/daemon/protocol.d.ts.map +1 -1
- package/dist/daemon/protocol.js +1 -0
- package/dist/daemon/protocol.js.map +1 -1
- package/dist/daemon/server.js +8 -0
- package/dist/daemon/server.js.map +1 -1
- package/dist/loader.d.ts +14 -0
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +247 -28
- package/dist/loader.js.map +1 -1
- package/dist/server.d.ts +7 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +67 -37
- package/dist/server.js.map +1 -1
- package/dist/shared/error-handler.d.ts +1 -0
- package/dist/shared/error-handler.d.ts.map +1 -1
- package/dist/shared/error-handler.js +68 -10
- package/dist/shared/error-handler.js.map +1 -1
- package/dist/shared/logger.d.ts.map +1 -1
- package/dist/shared/logger.js +34 -0
- package/dist/shared/logger.js.map +1 -1
- package/dist/telemetry/context.d.ts +24 -0
- package/dist/telemetry/context.d.ts.map +1 -0
- package/dist/telemetry/context.js +17 -0
- package/dist/telemetry/context.js.map +1 -0
- package/dist/telemetry/logs.d.ts +38 -0
- package/dist/telemetry/logs.d.ts.map +1 -0
- package/dist/telemetry/logs.js +108 -0
- package/dist/telemetry/logs.js.map +1 -0
- package/dist/telemetry/metrics.d.ts +71 -0
- package/dist/telemetry/metrics.d.ts.map +1 -0
- package/dist/telemetry/metrics.js +184 -0
- package/dist/telemetry/metrics.js.map +1 -0
- package/dist/telemetry/otel.d.ts +20 -1
- package/dist/telemetry/otel.d.ts.map +1 -1
- package/dist/telemetry/otel.js +79 -2
- package/dist/telemetry/otel.js.map +1 -1
- package/dist/telemetry/sdk.d.ts +49 -0
- package/dist/telemetry/sdk.d.ts.map +1 -0
- package/dist/telemetry/sdk.js +110 -0
- package/dist/telemetry/sdk.js.map +1 -0
- package/package.json +2 -2
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAuBnE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAG5E,OAAO,EAAgB,MAAM,EAAE,aAAa,EAAY,MAAM,oBAAoB,CAAC;AAanF,OAAO,EAGL,KAAK,yBAAyB,EAC/B,MAAM,sBAAsB,CAAC;AAc9B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,MAAM,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,GAAG;IAIvD,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAIzC,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAM7D;;;OAGG;IACH,OAAO,CAAC,WAAW;IA2CnB;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAgC7B;;;;;OAKG;YACW,uBAAuB;IAqDrC;;OAEG;YACW,qBAAqB;IA2BnC;;OAEG;YACW,wBAAwB;IAoFtC;;OAEG;IACG,KAAK;IA+GX;;OAEG;YACW,UAAU;IAsBxB;;OAEG;YACW,QAAQ;IA6ftB;;OAEG;YACW,cAAc;IAiC5B;;OAEG;YACW,iBAAiB;IAK/B;;OAEG;YACW,mBAAmB;IAiFjC;;OAEG;YACW,gBAAgB;IAgC9B;;;OAGG;IACH,OAAO,CAAC,oBAAoB;IA+C5B;;OAEG;IACG,IAAI;IA4CV,OAAO,CAAC,mBAAmB;IA+B3B,OAAO,CAAC,kBAAkB;YAqBZ,qBAAqB;IAyBnC,OAAO,CAAC,gBAAgB;IAOxB;;OAEG;IACH,OAAO,CAAC,kBAAkB,CAAK;IAC/B,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAK;IACzC,OAAO,CAAC,kBAAkB,CAAC,CAAiB;IAEtC,MAAM;IAgGZ;;;OAGG;YACW,kBAAkB;CAyBjC"}
|
package/dist/server.js
CHANGED
|
@@ -11,9 +11,9 @@ import { CallToolRequestSchema, ListToolsRequestSchema, ListPromptsRequestSchema
|
|
|
11
11
|
import { readText } from './shared/io.js';
|
|
12
12
|
import { createServer } from 'node:http';
|
|
13
13
|
import * as path from 'node:path';
|
|
14
|
+
import * as crypto from 'node:crypto';
|
|
14
15
|
import { URL } from 'node:url';
|
|
15
16
|
import { PhotonLoader } from './loader.js';
|
|
16
|
-
import { generateExecutionId } from '@portel/photon-core';
|
|
17
17
|
import { createSDKMCPClientFactory } from '@portel/photon-core';
|
|
18
18
|
import { PHOTON_VERSION } from './version.js';
|
|
19
19
|
import { createLogger } from './shared/logger.js';
|
|
@@ -276,6 +276,8 @@ export class PhotonServer {
|
|
|
276
276
|
clientCapabilitiesLogged = false;
|
|
277
277
|
/** Client capability detection and negotiation */
|
|
278
278
|
capabilityNegotiator = new CapabilityNegotiator();
|
|
279
|
+
/** Write queue for serialized STDIO notifications (prevents interleaving from concurrent generators) */
|
|
280
|
+
_notifyQueue = Promise.resolve();
|
|
279
281
|
/** Compatibility alias for tests that seed raw capabilities directly on PhotonServer */
|
|
280
282
|
rawClientCapabilities = this.capabilityNegotiator.rawClientCapabilities;
|
|
281
283
|
/** Resource listing, reading, and asset serving */
|
|
@@ -429,6 +431,15 @@ export class PhotonServer {
|
|
|
429
431
|
capabilities: JSON.stringify(capabilities),
|
|
430
432
|
});
|
|
431
433
|
}
|
|
434
|
+
/**
|
|
435
|
+
* Send a notification through the STDIO write queue.
|
|
436
|
+
* Serializes writes so concurrent generators don't interleave JSON on stdout.
|
|
437
|
+
*/
|
|
438
|
+
queueNotification(notification) {
|
|
439
|
+
this._notifyQueue = this._notifyQueue
|
|
440
|
+
.then(() => this.server?.notification(notification))
|
|
441
|
+
.catch(() => { });
|
|
442
|
+
}
|
|
432
443
|
/**
|
|
433
444
|
* Create an MCP-aware input provider for generator ask yields
|
|
434
445
|
*
|
|
@@ -876,10 +887,12 @@ export class PhotonServer {
|
|
|
876
887
|
// Forward channel events to daemon for cross-process pub/sub
|
|
877
888
|
this.channelManager.publishIfChannel(emit);
|
|
878
889
|
// Forward emit yields as MCP progress notifications to STDIO client
|
|
890
|
+
// All notifications go through queueNotification to prevent interleaving
|
|
891
|
+
// when concurrent generators write to the same stdout pipe
|
|
879
892
|
if (emit?.emit === 'progress') {
|
|
880
893
|
const rawValue = typeof emit.value === 'number' ? emit.value : 0;
|
|
881
894
|
const progress = rawValue <= 1 ? rawValue * 100 : rawValue;
|
|
882
|
-
|
|
895
|
+
this.queueNotification({
|
|
883
896
|
method: 'notifications/progress',
|
|
884
897
|
params: {
|
|
885
898
|
progressToken: `progress_${toolName}`,
|
|
@@ -890,7 +903,7 @@ export class PhotonServer {
|
|
|
890
903
|
});
|
|
891
904
|
}
|
|
892
905
|
else if (emit?.emit === 'status') {
|
|
893
|
-
|
|
906
|
+
this.queueNotification({
|
|
894
907
|
method: 'notifications/progress',
|
|
895
908
|
params: {
|
|
896
909
|
progressToken: `progress_${toolName}`,
|
|
@@ -901,7 +914,7 @@ export class PhotonServer {
|
|
|
901
914
|
});
|
|
902
915
|
}
|
|
903
916
|
else if (emit?.emit === 'log') {
|
|
904
|
-
|
|
917
|
+
this.queueNotification({
|
|
905
918
|
method: 'notifications/message',
|
|
906
919
|
params: {
|
|
907
920
|
level: emit.level || 'info',
|
|
@@ -910,38 +923,26 @@ export class PhotonServer {
|
|
|
910
923
|
});
|
|
911
924
|
}
|
|
912
925
|
else if (emit?.emit === 'render') {
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
}),
|
|
925
|
-
},
|
|
926
|
-
});
|
|
927
|
-
}
|
|
928
|
-
catch {
|
|
929
|
-
// Client may not support logging capability — silently skip
|
|
930
|
-
}
|
|
926
|
+
this.queueNotification({
|
|
927
|
+
method: 'notifications/message',
|
|
928
|
+
params: {
|
|
929
|
+
level: 'info',
|
|
930
|
+
data: JSON.stringify({
|
|
931
|
+
_render: true,
|
|
932
|
+
format: emit.format,
|
|
933
|
+
value: emit.value,
|
|
934
|
+
}),
|
|
935
|
+
},
|
|
936
|
+
});
|
|
931
937
|
}
|
|
932
938
|
else if (emit?.emit === 'render:clear') {
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
});
|
|
941
|
-
}
|
|
942
|
-
catch {
|
|
943
|
-
// Client may not support logging capability — silently skip
|
|
944
|
-
}
|
|
939
|
+
this.queueNotification({
|
|
940
|
+
method: 'notifications/message',
|
|
941
|
+
params: {
|
|
942
|
+
level: 'info',
|
|
943
|
+
data: JSON.stringify({ _render: true, clear: true }),
|
|
944
|
+
},
|
|
945
|
+
});
|
|
945
946
|
}
|
|
946
947
|
};
|
|
947
948
|
const tool = this.mcp.tools.find((t) => t.name === toolName);
|
|
@@ -1090,7 +1091,9 @@ export class PhotonServer {
|
|
|
1090
1091
|
const { name: toolName, arguments: args } = request.params;
|
|
1091
1092
|
const tool = this.mcp.tools.find((t) => t.name === toolName);
|
|
1092
1093
|
if (tool?.isAsync) {
|
|
1093
|
-
|
|
1094
|
+
// Generate a W3C-compatible OTel trace ID (32 hex chars = 128-bit)
|
|
1095
|
+
const traceId = crypto.randomBytes(16).toString('hex');
|
|
1096
|
+
const executionId = traceId;
|
|
1094
1097
|
const inputProvider = this.createMCPInputProvider();
|
|
1095
1098
|
const outputHandler = (emit) => {
|
|
1096
1099
|
this.channelManager.publishIfChannel(emit);
|
|
@@ -1151,19 +1154,24 @@ export class PhotonServer {
|
|
|
1151
1154
|
}
|
|
1152
1155
|
};
|
|
1153
1156
|
this.loader
|
|
1154
|
-
.executeTool(this.mcp, toolName, args || {}, { inputProvider, outputHandler })
|
|
1157
|
+
.executeTool(this.mcp, toolName, args || {}, { inputProvider, outputHandler, traceId })
|
|
1155
1158
|
.catch((error) => {
|
|
1156
1159
|
this.log('error', `Async tool ${toolName} failed`, {
|
|
1157
1160
|
executionId,
|
|
1158
1161
|
error: getErrorMessage(error),
|
|
1159
1162
|
});
|
|
1160
1163
|
});
|
|
1164
|
+
// Build W3C traceparent: 00-{traceId}-{spanId}-01
|
|
1165
|
+
const spanId = crypto.randomBytes(8).toString('hex');
|
|
1166
|
+
const traceparent = `00-${traceId}-${spanId}-01`;
|
|
1161
1167
|
return {
|
|
1162
1168
|
content: [
|
|
1163
1169
|
{
|
|
1164
1170
|
type: 'text',
|
|
1165
1171
|
text: JSON.stringify({
|
|
1166
1172
|
executionId,
|
|
1173
|
+
_traceId: traceId,
|
|
1174
|
+
_traceparent: traceparent,
|
|
1167
1175
|
status: 'running',
|
|
1168
1176
|
photon: this.mcp.name,
|
|
1169
1177
|
method: toolName,
|
|
@@ -1316,7 +1324,7 @@ export class PhotonServer {
|
|
|
1316
1324
|
* Provides structured, actionable error messages
|
|
1317
1325
|
*/
|
|
1318
1326
|
formatError(error, toolName, args) {
|
|
1319
|
-
const { text, errorType
|
|
1327
|
+
const { text, errorType, retryable } = formatToolError(toolName, error);
|
|
1320
1328
|
// Add dev-mode extras
|
|
1321
1329
|
let devExtras = '';
|
|
1322
1330
|
if (this.options.devMode && Object.keys(args || {}).length > 0) {
|
|
@@ -1330,6 +1338,17 @@ export class PhotonServer {
|
|
|
1330
1338
|
if (this.options.devMode && error.stack) {
|
|
1331
1339
|
this.log('debug', error.stack);
|
|
1332
1340
|
}
|
|
1341
|
+
// Emit structured error metadata in addition to the human-readable text
|
|
1342
|
+
// so MCP clients can make typed retry decisions without parsing prose.
|
|
1343
|
+
// `_meta.photon` is the non-standard extension namespace; `structuredContent`
|
|
1344
|
+
// is the MCP-spec field for machine-readable result data.
|
|
1345
|
+
const structured = {
|
|
1346
|
+
error: {
|
|
1347
|
+
type: errorType,
|
|
1348
|
+
retryable,
|
|
1349
|
+
message: getErrorMessage(error),
|
|
1350
|
+
},
|
|
1351
|
+
};
|
|
1333
1352
|
return {
|
|
1334
1353
|
content: [
|
|
1335
1354
|
{
|
|
@@ -1338,6 +1357,8 @@ export class PhotonServer {
|
|
|
1338
1357
|
},
|
|
1339
1358
|
],
|
|
1340
1359
|
isError: true,
|
|
1360
|
+
structuredContent: structured,
|
|
1361
|
+
_meta: { photon: structured.error },
|
|
1341
1362
|
};
|
|
1342
1363
|
}
|
|
1343
1364
|
/**
|
|
@@ -1622,6 +1643,15 @@ export class PhotonServer {
|
|
|
1622
1643
|
*/
|
|
1623
1644
|
async startStdio() {
|
|
1624
1645
|
const transport = new StdioServerTransport();
|
|
1646
|
+
// Wrap transport.send with a write mutex to prevent concurrent generators
|
|
1647
|
+
// from interleaving JSON-RPC messages on stdout
|
|
1648
|
+
const originalSend = transport.send.bind(transport);
|
|
1649
|
+
let writeChain = Promise.resolve();
|
|
1650
|
+
transport.send = (message) => {
|
|
1651
|
+
const p = writeChain.then(() => originalSend(message)).catch(() => { });
|
|
1652
|
+
writeChain = p;
|
|
1653
|
+
return p;
|
|
1654
|
+
};
|
|
1625
1655
|
this.capabilityNegotiator.interceptTransportForRawCapabilities(transport, this.server, (msg) => this.channelManager.interceptPermissionRequest(msg));
|
|
1626
1656
|
await this.server.connect(transport);
|
|
1627
1657
|
this.log('info', `Server started: ${this.mcp.name}`);
|