@prefactor/core 0.3.0 → 0.3.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.
- package/dist/client.d.ts +16 -9
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +12 -0
- package/dist/client.js.map +1 -1
- package/dist/index.cjs +189 -6
- package/dist/index.cjs.map +8 -6
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +189 -6
- package/dist/index.js.map +8 -6
- package/dist/tool-schema.d.ts +16 -0
- package/dist/tool-schema.d.ts.map +1 -0
- package/dist/tool-schema.js +152 -0
- package/dist/tool-schema.js.map +1 -0
- package/dist/transport/http/agent-instance-client.d.ts.map +1 -1
- package/dist/transport/http/agent-instance-client.js +6 -3
- package/dist/transport/http/agent-instance-client.js.map +1 -1
- package/dist/transport/http/agent-span-client.d.ts.map +1 -1
- package/dist/transport/http/agent-span-client.js +3 -1
- package/dist/transport/http/agent-span-client.js.map +1 -1
- package/dist/transport/http/idempotency.d.ts +2 -0
- package/dist/transport/http/idempotency.d.ts.map +1 -0
- package/dist/transport/http/idempotency.js +11 -0
- package/dist/transport/http/idempotency.js.map +1 -0
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export type MiddlewareLike = unknown;
|
|
|
22
22
|
/**
|
|
23
23
|
* Provider integration contract for Prefactor SDK clients.
|
|
24
24
|
*/
|
|
25
|
-
export interface PrefactorProvider {
|
|
25
|
+
export interface PrefactorProvider<TMiddleware = MiddlewareLike> {
|
|
26
26
|
/**
|
|
27
27
|
* Creates provider middleware bound to the core runtime services.
|
|
28
28
|
*
|
|
@@ -31,11 +31,18 @@ export interface PrefactorProvider {
|
|
|
31
31
|
* @param config - Resolved SDK configuration.
|
|
32
32
|
* @returns Provider middleware consumed by upstream frameworks.
|
|
33
33
|
*/
|
|
34
|
-
createMiddleware(tracer: Tracer, agentManager: AgentInstanceManager, config: Config):
|
|
34
|
+
createMiddleware(tracer: Tracer, agentManager: AgentInstanceManager, config: Config): TMiddleware;
|
|
35
35
|
/**
|
|
36
36
|
* Optional provider-level cleanup hook invoked during client shutdown.
|
|
37
37
|
*/
|
|
38
38
|
shutdown?: () => void | Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Normalizes a user- or provider-authored agent schema before core registers it.
|
|
41
|
+
*
|
|
42
|
+
* @param agentSchema - Authored agent schema configuration.
|
|
43
|
+
* @returns Normalized schema, or `undefined` to leave the input unchanged.
|
|
44
|
+
*/
|
|
45
|
+
normalizeAgentSchema?: (agentSchema: Record<string, unknown>) => Record<string, unknown> | undefined;
|
|
39
46
|
/**
|
|
40
47
|
* Provides a default agent schema when a user does not supply one.
|
|
41
48
|
*
|
|
@@ -43,7 +50,7 @@ export interface PrefactorProvider {
|
|
|
43
50
|
*/
|
|
44
51
|
getDefaultAgentSchema?: () => Record<string, unknown> | undefined;
|
|
45
52
|
}
|
|
46
|
-
export declare class PrefactorClient {
|
|
53
|
+
export declare class PrefactorClient<TMiddleware = MiddlewareLike> {
|
|
47
54
|
private readonly core;
|
|
48
55
|
private readonly middleware;
|
|
49
56
|
private readonly provider;
|
|
@@ -54,7 +61,7 @@ export declare class PrefactorClient {
|
|
|
54
61
|
* @param middleware - Provider middleware returned by the integration.
|
|
55
62
|
* @param provider - Provider used to construct the client.
|
|
56
63
|
*/
|
|
57
|
-
constructor(core: CoreRuntime, middleware:
|
|
64
|
+
constructor(core: CoreRuntime, middleware: TMiddleware, provider: PrefactorProvider<TMiddleware>);
|
|
58
65
|
/**
|
|
59
66
|
* Returns the runtime tracer used by this client.
|
|
60
67
|
*
|
|
@@ -66,7 +73,7 @@ export declare class PrefactorClient {
|
|
|
66
73
|
*
|
|
67
74
|
* @returns Provider middleware object.
|
|
68
75
|
*/
|
|
69
|
-
getMiddleware():
|
|
76
|
+
getMiddleware(): TMiddleware;
|
|
70
77
|
/**
|
|
71
78
|
* Runs a function within a manually-created span.
|
|
72
79
|
*
|
|
@@ -87,9 +94,9 @@ export declare class PrefactorClient {
|
|
|
87
94
|
/**
|
|
88
95
|
* Options for initializing the global Prefactor client.
|
|
89
96
|
*/
|
|
90
|
-
export interface PrefactorOptions {
|
|
97
|
+
export interface PrefactorOptions<TMiddleware = MiddlewareLike> {
|
|
91
98
|
/** Provider integration used to create middleware and defaults. */
|
|
92
|
-
provider: PrefactorProvider
|
|
99
|
+
provider: PrefactorProvider<TMiddleware>;
|
|
93
100
|
/** Optional HTTP configuration overrides for the runtime config. */
|
|
94
101
|
httpConfig?: Config['httpConfig'];
|
|
95
102
|
}
|
|
@@ -101,11 +108,11 @@ export interface PrefactorOptions {
|
|
|
101
108
|
* @param options - Initialization options.
|
|
102
109
|
* @returns Global Prefactor client instance.
|
|
103
110
|
*/
|
|
104
|
-
export declare function init(options: PrefactorOptions): PrefactorClient
|
|
111
|
+
export declare function init<TMiddleware = MiddlewareLike>(options: PrefactorOptions<TMiddleware>): PrefactorClient<TMiddleware>;
|
|
105
112
|
/**
|
|
106
113
|
* Returns the currently initialized global Prefactor client, if any.
|
|
107
114
|
*
|
|
108
115
|
* @returns Active global client or `null`.
|
|
109
116
|
*/
|
|
110
|
-
export declare function getClient(): PrefactorClient | null;
|
|
117
|
+
export declare function getClient(): PrefactorClient<MiddlewareLike> | null;
|
|
111
118
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAIlD;;GAEG;AACH,MAAM,WAAW,iBAAi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AAC,CA0D9B;AAED;;;;GAIG;AACF,wBAAgB,SAAS,IAAI,eAAe,CAAC,cAAc,CAAC,GAAG,IAAI,CAElE"}
|
package/dist/client.js
CHANGED
|
@@ -99,6 +99,18 @@ export function init(options) {
|
|
|
99
99
|
},
|
|
100
100
|
};
|
|
101
101
|
}
|
|
102
|
+
if (finalConfig.httpConfig?.agentSchema) {
|
|
103
|
+
const normalizedSchema = options.provider.normalizeAgentSchema?.(finalConfig.httpConfig.agentSchema);
|
|
104
|
+
if (normalizedSchema) {
|
|
105
|
+
finalConfig = {
|
|
106
|
+
...finalConfig,
|
|
107
|
+
httpConfig: {
|
|
108
|
+
...finalConfig.httpConfig,
|
|
109
|
+
agentSchema: normalizedSchema,
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
102
114
|
const core = createCore(finalConfig);
|
|
103
115
|
const httpConfig = finalConfig.httpConfig;
|
|
104
116
|
if (httpConfig?.agentSchema) {
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAuDtD,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CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;QACzE,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,UAAU,CAAC,GAAG,CAAC,GAAG,cAAc,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;QACrD,CAAC;QACD,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -33,7 +33,9 @@ __export(exports_src, {
|
|
|
33
33
|
truncateString: () => truncateString,
|
|
34
34
|
shutdown: () => shutdown,
|
|
35
35
|
serializeValue: () => serializeValue,
|
|
36
|
+
resolveMappedSpanType: () => resolveMappedSpanType,
|
|
36
37
|
registerShutdownHandler: () => registerShutdownHandler,
|
|
38
|
+
normalizeAgentToolSchemas: () => normalizeAgentToolSchemas,
|
|
37
39
|
init: () => init,
|
|
38
40
|
getLogger: () => getLogger,
|
|
39
41
|
getClient: () => getClient,
|
|
@@ -570,6 +572,18 @@ function configureLogging() {
|
|
|
570
572
|
}
|
|
571
573
|
}
|
|
572
574
|
|
|
575
|
+
// packages/core/src/transport/http/idempotency.ts
|
|
576
|
+
var MAX_KEY_LENGTH = 64;
|
|
577
|
+
function ensureIdempotencyKey(key) {
|
|
578
|
+
if (key === undefined) {
|
|
579
|
+
return crypto.randomUUID();
|
|
580
|
+
}
|
|
581
|
+
if (key.length > MAX_KEY_LENGTH) {
|
|
582
|
+
throw new Error(`idempotency_key must be ≤${MAX_KEY_LENGTH} characters, got ${key.length}`);
|
|
583
|
+
}
|
|
584
|
+
return key;
|
|
585
|
+
}
|
|
586
|
+
|
|
573
587
|
// packages/core/src/transport/http/agent-instance-client.ts
|
|
574
588
|
class AgentInstanceClient {
|
|
575
589
|
httpClient;
|
|
@@ -579,19 +593,21 @@ class AgentInstanceClient {
|
|
|
579
593
|
register(payload) {
|
|
580
594
|
return this.httpClient.request("/api/v1/agent_instance/register", {
|
|
581
595
|
method: "POST",
|
|
582
|
-
body: payload
|
|
596
|
+
body: { ...payload, idempotency_key: ensureIdempotencyKey(payload.idempotency_key) }
|
|
583
597
|
});
|
|
584
598
|
}
|
|
585
599
|
start(agentInstanceId, options) {
|
|
600
|
+
const opts = options ?? {};
|
|
586
601
|
return this.httpClient.request(`/api/v1/agent_instance/${agentInstanceId}/start`, {
|
|
587
602
|
method: "POST",
|
|
588
|
-
body:
|
|
603
|
+
body: { ...opts, idempotency_key: ensureIdempotencyKey(opts.idempotency_key) }
|
|
589
604
|
});
|
|
590
605
|
}
|
|
591
606
|
finish(agentInstanceId, options) {
|
|
607
|
+
const opts = options ?? {};
|
|
592
608
|
return this.httpClient.request(`/api/v1/agent_instance/${agentInstanceId}/finish`, {
|
|
593
609
|
method: "POST",
|
|
594
|
-
body:
|
|
610
|
+
body: { ...opts, idempotency_key: ensureIdempotencyKey(opts.idempotency_key) }
|
|
595
611
|
});
|
|
596
612
|
}
|
|
597
613
|
}
|
|
@@ -738,7 +754,7 @@ class AgentSpanClient {
|
|
|
738
754
|
create(payload) {
|
|
739
755
|
return this.httpClient.request("/api/v1/agent_spans", {
|
|
740
756
|
method: "POST",
|
|
741
|
-
body: payload
|
|
757
|
+
body: { ...payload, idempotency_key: ensureIdempotencyKey(payload.idempotency_key) }
|
|
742
758
|
});
|
|
743
759
|
}
|
|
744
760
|
async finish(spanId, timestamp, options = {}) {
|
|
@@ -747,7 +763,8 @@ class AgentSpanClient {
|
|
|
747
763
|
method: "POST",
|
|
748
764
|
body: {
|
|
749
765
|
timestamp,
|
|
750
|
-
...options
|
|
766
|
+
...options,
|
|
767
|
+
idempotency_key: ensureIdempotencyKey(options.idempotency_key)
|
|
751
768
|
}
|
|
752
769
|
});
|
|
753
770
|
} catch (error) {
|
|
@@ -1208,6 +1225,18 @@ function init(options) {
|
|
|
1208
1225
|
}
|
|
1209
1226
|
};
|
|
1210
1227
|
}
|
|
1228
|
+
if (finalConfig.httpConfig?.agentSchema) {
|
|
1229
|
+
const normalizedSchema = options.provider.normalizeAgentSchema?.(finalConfig.httpConfig.agentSchema);
|
|
1230
|
+
if (normalizedSchema) {
|
|
1231
|
+
finalConfig = {
|
|
1232
|
+
...finalConfig,
|
|
1233
|
+
httpConfig: {
|
|
1234
|
+
...finalConfig.httpConfig,
|
|
1235
|
+
agentSchema: normalizedSchema
|
|
1236
|
+
}
|
|
1237
|
+
};
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1211
1240
|
const core = createCore(finalConfig);
|
|
1212
1241
|
const httpConfig = finalConfig.httpConfig;
|
|
1213
1242
|
if (httpConfig?.agentSchema) {
|
|
@@ -1243,6 +1272,160 @@ function normalizeValue2(value) {
|
|
|
1243
1272
|
}
|
|
1244
1273
|
return value;
|
|
1245
1274
|
}
|
|
1275
|
+
// packages/core/src/tool-schema.ts
|
|
1276
|
+
var logger2 = getLogger("tool-schema");
|
|
1277
|
+
function normalizeAgentToolSchemas(agentSchema, {
|
|
1278
|
+
defaultAgentSchema,
|
|
1279
|
+
providerName
|
|
1280
|
+
}) {
|
|
1281
|
+
const toolSchemas = extractToolSchemas(agentSchema, providerName);
|
|
1282
|
+
return {
|
|
1283
|
+
agentSchema: mergeWithDefaultAgentSchema(stripToolSchemas(agentSchema), defaultAgentSchema),
|
|
1284
|
+
toolSchemas,
|
|
1285
|
+
toolSpanTypes: buildToolSpanTypes(toolSchemas)
|
|
1286
|
+
};
|
|
1287
|
+
}
|
|
1288
|
+
function resolveMappedSpanType(toolName, toolSpanTypes, defaultSpanType) {
|
|
1289
|
+
return toolSpanTypes?.[toolName] ?? defaultSpanType;
|
|
1290
|
+
}
|
|
1291
|
+
function extractToolSchemas(agentSchema, providerName) {
|
|
1292
|
+
const rawToolSchemas = getRawToolSchemas(agentSchema);
|
|
1293
|
+
if (!rawToolSchemas) {
|
|
1294
|
+
return;
|
|
1295
|
+
}
|
|
1296
|
+
const toolSchemas = {};
|
|
1297
|
+
const toolBySpanType = new Map;
|
|
1298
|
+
for (const [toolName, rawConfig] of Object.entries(rawToolSchemas)) {
|
|
1299
|
+
const parsedToolSchema = parseToolSchemaConfig(toolName, rawConfig, providerName, toolBySpanType);
|
|
1300
|
+
if (!parsedToolSchema) {
|
|
1301
|
+
continue;
|
|
1302
|
+
}
|
|
1303
|
+
toolSchemas[toolName] = parsedToolSchema;
|
|
1304
|
+
}
|
|
1305
|
+
return Object.keys(toolSchemas).length > 0 ? toolSchemas : undefined;
|
|
1306
|
+
}
|
|
1307
|
+
function getRawToolSchemas(agentSchema) {
|
|
1308
|
+
if (!agentSchema || typeof agentSchema !== "object" || Array.isArray(agentSchema)) {
|
|
1309
|
+
return;
|
|
1310
|
+
}
|
|
1311
|
+
const rawToolSchemas = agentSchema.toolSchemas;
|
|
1312
|
+
if (rawToolSchemas === undefined) {
|
|
1313
|
+
return;
|
|
1314
|
+
}
|
|
1315
|
+
if (!rawToolSchemas || typeof rawToolSchemas !== "object" || Array.isArray(rawToolSchemas)) {
|
|
1316
|
+
logger2.warn("Ignoring invalid agentSchema.toolSchemas: expected an object keyed by tool name.");
|
|
1317
|
+
return;
|
|
1318
|
+
}
|
|
1319
|
+
return rawToolSchemas;
|
|
1320
|
+
}
|
|
1321
|
+
function parseToolSchemaConfig(toolName, rawConfig, providerName, toolBySpanType) {
|
|
1322
|
+
if (!rawConfig || typeof rawConfig !== "object" || Array.isArray(rawConfig)) {
|
|
1323
|
+
logger2.warn(`Invalid agentSchema.toolSchemas.${toolName}: expected an object with spanType and inputSchema.`);
|
|
1324
|
+
return;
|
|
1325
|
+
}
|
|
1326
|
+
const config = rawConfig;
|
|
1327
|
+
if (typeof config.spanType !== "string") {
|
|
1328
|
+
logger2.warn(`Invalid agentSchema.toolSchemas.${toolName}.spanType: expected a non-empty string.`);
|
|
1329
|
+
return;
|
|
1330
|
+
}
|
|
1331
|
+
const inputSchema = assertValidInputSchema(toolName, config.inputSchema);
|
|
1332
|
+
if (!inputSchema) {
|
|
1333
|
+
return;
|
|
1334
|
+
}
|
|
1335
|
+
const normalizedSpanType = normalizeUniqueToolSpanType(toolName, config.spanType, providerName, toolBySpanType);
|
|
1336
|
+
if (!normalizedSpanType) {
|
|
1337
|
+
return;
|
|
1338
|
+
}
|
|
1339
|
+
return {
|
|
1340
|
+
spanType: normalizedSpanType,
|
|
1341
|
+
inputSchema
|
|
1342
|
+
};
|
|
1343
|
+
}
|
|
1344
|
+
function assertValidInputSchema(toolName, inputSchema) {
|
|
1345
|
+
if (!inputSchema || typeof inputSchema !== "object" || Array.isArray(inputSchema)) {
|
|
1346
|
+
logger2.warn(`Invalid agentSchema.toolSchemas.${toolName}.inputSchema: expected an object.`);
|
|
1347
|
+
return;
|
|
1348
|
+
}
|
|
1349
|
+
return inputSchema;
|
|
1350
|
+
}
|
|
1351
|
+
function normalizeUniqueToolSpanType(toolName, spanType, providerName, toolBySpanType) {
|
|
1352
|
+
const normalizedSpanType = normalizeToolSpanType(spanType, toolName, providerName);
|
|
1353
|
+
if (!normalizedSpanType) {
|
|
1354
|
+
return;
|
|
1355
|
+
}
|
|
1356
|
+
const conflictingTool = toolBySpanType.get(normalizedSpanType);
|
|
1357
|
+
if (conflictingTool && conflictingTool !== toolName) {
|
|
1358
|
+
logger2.warn(`Invalid agentSchema.toolSchemas.${toolName}.spanType: normalized span type "${normalizedSpanType}" conflicts with "${conflictingTool}".`);
|
|
1359
|
+
return;
|
|
1360
|
+
}
|
|
1361
|
+
toolBySpanType.set(normalizedSpanType, toolName);
|
|
1362
|
+
return normalizedSpanType;
|
|
1363
|
+
}
|
|
1364
|
+
function buildToolSpanTypes(toolSchemas) {
|
|
1365
|
+
if (!toolSchemas) {
|
|
1366
|
+
return;
|
|
1367
|
+
}
|
|
1368
|
+
return Object.fromEntries(Object.entries(toolSchemas).map(([toolName, config]) => [toolName, config.spanType]));
|
|
1369
|
+
}
|
|
1370
|
+
function cloneRecord(value) {
|
|
1371
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
1372
|
+
return {};
|
|
1373
|
+
}
|
|
1374
|
+
return { ...value };
|
|
1375
|
+
}
|
|
1376
|
+
function stripToolSchemas(baseSchema) {
|
|
1377
|
+
if (!baseSchema || typeof baseSchema !== "object" || Array.isArray(baseSchema)) {
|
|
1378
|
+
return baseSchema;
|
|
1379
|
+
}
|
|
1380
|
+
const { toolSchemas: _, ...rest } = baseSchema;
|
|
1381
|
+
return rest;
|
|
1382
|
+
}
|
|
1383
|
+
function mergeWithDefaultAgentSchema(baseSchema, defaultAgentSchema) {
|
|
1384
|
+
if (!baseSchema) {
|
|
1385
|
+
return defaultAgentSchema;
|
|
1386
|
+
}
|
|
1387
|
+
return {
|
|
1388
|
+
...defaultAgentSchema,
|
|
1389
|
+
...baseSchema,
|
|
1390
|
+
span_schemas: {
|
|
1391
|
+
...cloneRecord(defaultAgentSchema.span_schemas),
|
|
1392
|
+
...cloneRecord(baseSchema.span_schemas)
|
|
1393
|
+
},
|
|
1394
|
+
span_result_schemas: {
|
|
1395
|
+
...cloneRecord(defaultAgentSchema.span_result_schemas),
|
|
1396
|
+
...cloneRecord(baseSchema.span_result_schemas)
|
|
1397
|
+
}
|
|
1398
|
+
};
|
|
1399
|
+
}
|
|
1400
|
+
function normalizeToolSpanType(spanType, toolName, providerName) {
|
|
1401
|
+
const trimmedSpanType = spanType.trim();
|
|
1402
|
+
if (trimmedSpanType.length === 0) {
|
|
1403
|
+
logger2.warn(`Invalid agentSchema.toolSchemas.${toolName}.spanType: expected a non-empty string.`);
|
|
1404
|
+
return;
|
|
1405
|
+
}
|
|
1406
|
+
const providerToolPrefix = `${providerName}:tool:`;
|
|
1407
|
+
if (trimmedSpanType.startsWith(providerToolPrefix)) {
|
|
1408
|
+
const suffix2 = trimmedSpanType.slice(providerToolPrefix.length).replace(/^:+/, "");
|
|
1409
|
+
if (suffix2.length === 0) {
|
|
1410
|
+
logger2.warn(`Invalid agentSchema.toolSchemas.${toolName}.spanType: expected a non-empty suffix after normalization.`);
|
|
1411
|
+
return;
|
|
1412
|
+
}
|
|
1413
|
+
return `${providerName}:tool:${suffix2}`;
|
|
1414
|
+
}
|
|
1415
|
+
let suffix = trimmedSpanType;
|
|
1416
|
+
if (suffix.startsWith(`${providerName}:`)) {
|
|
1417
|
+
suffix = suffix.slice(`${providerName}:`.length);
|
|
1418
|
+
}
|
|
1419
|
+
if (suffix.startsWith("tool:")) {
|
|
1420
|
+
suffix = suffix.slice("tool:".length);
|
|
1421
|
+
}
|
|
1422
|
+
suffix = suffix.replace(/^:+/, "");
|
|
1423
|
+
if (suffix.length === 0) {
|
|
1424
|
+
logger2.warn(`Invalid agentSchema.toolSchemas.${toolName}.spanType: expected a non-empty suffix after normalization.`);
|
|
1425
|
+
return;
|
|
1426
|
+
}
|
|
1427
|
+
return `${providerName}:tool:${suffix}`;
|
|
1428
|
+
}
|
|
1246
1429
|
// packages/core/src/utils/serialization.ts
|
|
1247
1430
|
function truncateString(value, maxLength) {
|
|
1248
1431
|
if (value.length <= maxLength) {
|
|
@@ -1277,4 +1460,4 @@ function serializeValue(value, maxLength = 1e4) {
|
|
|
1277
1460
|
}
|
|
1278
1461
|
}
|
|
1279
1462
|
|
|
1280
|
-
//# debugId=
|
|
1463
|
+
//# debugId=BAAD2927981B351B64756E2164756E21
|