@prefactor/core 0.3.1 → 0.3.3
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 +22 -9
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +23 -4
- package/dist/client.js.map +1 -1
- package/dist/create-core.d.ts +6 -1
- package/dist/create-core.d.ts.map +1 -1
- package/dist/create-core.js +5 -2
- package/dist/create-core.js.map +1 -1
- package/dist/index.cjs +214 -10
- package/dist/index.cjs.map +10 -7
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +214 -10
- package/dist/index.js.map +10 -7
- 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/http-client.d.ts +3 -0
- package/dist/transport/http/http-client.d.ts.map +1 -1
- package/dist/transport/http/http-client.js +7 -1
- package/dist/transport/http/http-client.js.map +1 -1
- package/dist/transport/http/sdk-request-header.d.ts +5 -0
- package/dist/transport/http/sdk-request-header.d.ts.map +1 -0
- package/dist/transport/http/sdk-request-header.js +26 -0
- package/dist/transport/http/sdk-request-header.js.map +1 -0
- package/dist/transport/http.d.ts +2 -0
- package/dist/transport/http.d.ts.map +1 -1
- package/dist/transport/http.js +4 -2
- package/dist/transport/http.js.map +1 -1
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +4 -0
- package/dist/version.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,24 @@ 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
|
+
* Returns the SDK header entry to append to HTTP requests created by the core runtime.
|
|
41
|
+
*
|
|
42
|
+
* @returns Adapter-specific SDK identifier, or `undefined` to use the core header only.
|
|
43
|
+
*/
|
|
44
|
+
getSdkHeaderEntry?: () => string | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Normalizes a user- or provider-authored agent schema before core registers it.
|
|
47
|
+
*
|
|
48
|
+
* @param agentSchema - Authored agent schema configuration.
|
|
49
|
+
* @returns Normalized schema, or `undefined` to leave the input unchanged.
|
|
50
|
+
*/
|
|
51
|
+
normalizeAgentSchema?: (agentSchema: Record<string, unknown>) => Record<string, unknown> | undefined;
|
|
39
52
|
/**
|
|
40
53
|
* Provides a default agent schema when a user does not supply one.
|
|
41
54
|
*
|
|
@@ -43,7 +56,7 @@ export interface PrefactorProvider {
|
|
|
43
56
|
*/
|
|
44
57
|
getDefaultAgentSchema?: () => Record<string, unknown> | undefined;
|
|
45
58
|
}
|
|
46
|
-
export declare class PrefactorClient {
|
|
59
|
+
export declare class PrefactorClient<TMiddleware = MiddlewareLike> {
|
|
47
60
|
private readonly core;
|
|
48
61
|
private readonly middleware;
|
|
49
62
|
private readonly provider;
|
|
@@ -54,7 +67,7 @@ export declare class PrefactorClient {
|
|
|
54
67
|
* @param middleware - Provider middleware returned by the integration.
|
|
55
68
|
* @param provider - Provider used to construct the client.
|
|
56
69
|
*/
|
|
57
|
-
constructor(core: CoreRuntime, middleware:
|
|
70
|
+
constructor(core: CoreRuntime, middleware: TMiddleware, provider: PrefactorProvider<TMiddleware>);
|
|
58
71
|
/**
|
|
59
72
|
* Returns the runtime tracer used by this client.
|
|
60
73
|
*
|
|
@@ -66,7 +79,7 @@ export declare class PrefactorClient {
|
|
|
66
79
|
*
|
|
67
80
|
* @returns Provider middleware object.
|
|
68
81
|
*/
|
|
69
|
-
getMiddleware():
|
|
82
|
+
getMiddleware(): TMiddleware;
|
|
70
83
|
/**
|
|
71
84
|
* Runs a function within a manually-created span.
|
|
72
85
|
*
|
|
@@ -87,9 +100,9 @@ export declare class PrefactorClient {
|
|
|
87
100
|
/**
|
|
88
101
|
* Options for initializing the global Prefactor client.
|
|
89
102
|
*/
|
|
90
|
-
export interface PrefactorOptions {
|
|
103
|
+
export interface PrefactorOptions<TMiddleware = MiddlewareLike> {
|
|
91
104
|
/** Provider integration used to create middleware and defaults. */
|
|
92
|
-
provider: PrefactorProvider
|
|
105
|
+
provider: PrefactorProvider<TMiddleware>;
|
|
93
106
|
/** Optional HTTP configuration overrides for the runtime config. */
|
|
94
107
|
httpConfig?: Config['httpConfig'];
|
|
95
108
|
}
|
|
@@ -101,11 +114,11 @@ export interface PrefactorOptions {
|
|
|
101
114
|
* @param options - Initialization options.
|
|
102
115
|
* @returns Global Prefactor client instance.
|
|
103
116
|
*/
|
|
104
|
-
export declare function init(options: PrefactorOptions): PrefactorClient
|
|
117
|
+
export declare function init<TMiddleware = MiddlewareLike>(options: PrefactorOptions<TMiddleware>): PrefactorClient<TMiddleware>;
|
|
105
118
|
/**
|
|
106
119
|
* Returns the currently initialized global Prefactor client, if any.
|
|
107
120
|
*
|
|
108
121
|
* @returns Active global client or `null`.
|
|
109
122
|
*/
|
|
110
|
-
export declare function getClient(): PrefactorClient | null;
|
|
123
|
+
export declare function getClient(): PrefactorClient<MiddlewareLike> | null;
|
|
111
124
|
//# 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,iBAAiB;IAChC,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,8CAA8C;IAC9C,QAAQ,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,kDAAkD;IAClD,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,CAAC;AAErC;;GAEG;AACH,MAAM,WAAW,iBAAiB;
|
|
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,iBAAiB;IAChC,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,8CAA8C;IAC9C,QAAQ,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO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AAG,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAa7E;;;;;;OAMG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAShC;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB,CAAC,WAAW,GAAG,cAAc;IAC5D,mEAAmE;IACnE,QAAQ,EAAE,iBAAiB,CAAC,WAAW,CAAC,CAAC;IACzC,oEAAoE;IACpE,UAAU,CAAC,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;CACnC;AAED;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,WAAW,GAAG,cAAc,EAC/C,OAAO,EAAE,gBAAgB,CAAC,WAAW,CAAC,GACrC,eAAe,CAAC,WAAW,CAAC,CA6D9B;AAED;;;;GAIG;AACH,wBAAgB,SAAS,IAAI,eAAe,CAAC,cAAc,CAAC,GAAG,IAAI,CAElE"}
|
package/dist/client.js
CHANGED
|
@@ -78,7 +78,8 @@ export class PrefactorClient {
|
|
|
78
78
|
* @returns Global Prefactor client instance.
|
|
79
79
|
*/
|
|
80
80
|
export function init(options) {
|
|
81
|
-
const
|
|
81
|
+
const sdkHeaderEntry = options.provider.getSdkHeaderEntry?.();
|
|
82
|
+
const nextInitKey = buildInitKey(options, sdkHeaderEntry);
|
|
82
83
|
if (prefactorClient) {
|
|
83
84
|
if (prefactorInitKey !== nextInitKey) {
|
|
84
85
|
throw new Error('Prefactor is already initialized with a different provider or configuration. ' +
|
|
@@ -99,7 +100,21 @@ export function init(options) {
|
|
|
99
100
|
},
|
|
100
101
|
};
|
|
101
102
|
}
|
|
102
|
-
|
|
103
|
+
if (finalConfig.httpConfig?.agentSchema) {
|
|
104
|
+
const normalizedSchema = options.provider.normalizeAgentSchema?.(finalConfig.httpConfig.agentSchema);
|
|
105
|
+
if (normalizedSchema) {
|
|
106
|
+
finalConfig = {
|
|
107
|
+
...finalConfig,
|
|
108
|
+
httpConfig: {
|
|
109
|
+
...finalConfig.httpConfig,
|
|
110
|
+
agentSchema: normalizedSchema,
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const core = createCore(finalConfig, {
|
|
116
|
+
sdkHeaderEntry,
|
|
117
|
+
});
|
|
103
118
|
const httpConfig = finalConfig.httpConfig;
|
|
104
119
|
if (httpConfig?.agentSchema) {
|
|
105
120
|
core.agentManager.registerSchema(httpConfig.agentSchema);
|
|
@@ -117,9 +132,13 @@ export function init(options) {
|
|
|
117
132
|
export function getClient() {
|
|
118
133
|
return prefactorClient;
|
|
119
134
|
}
|
|
120
|
-
function buildInitKey(options) {
|
|
135
|
+
function buildInitKey(options, sdkHeaderEntry) {
|
|
121
136
|
const providerType = options.provider.constructor?.name ?? 'anonymous-provider';
|
|
122
|
-
return
|
|
137
|
+
return stableStringify({
|
|
138
|
+
providerType,
|
|
139
|
+
httpConfig: options.httpConfig ?? null,
|
|
140
|
+
sdkHeaderEntry: sdkHeaderEntry ?? null,
|
|
141
|
+
});
|
|
123
142
|
}
|
|
124
143
|
function stableStringify(value) {
|
|
125
144
|
return JSON.stringify(normalizeValue(value));
|
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,YAA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,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACvC,MAAM,UAAU,GAA4B,EAAE,CAAC;QAC/C,MAAM,WAAW,GAAG,KAAgC,CAAC;QACrD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,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/create-core.d.ts
CHANGED
|
@@ -9,11 +9,16 @@ export type CoreRuntime = {
|
|
|
9
9
|
/** Gracefully shuts down the runtime and flushes transport work. */
|
|
10
10
|
shutdown: () => Promise<void>;
|
|
11
11
|
};
|
|
12
|
+
export type CreateCoreOptions = {
|
|
13
|
+
/** Optional adapter identifier appended ahead of the core SDK header. */
|
|
14
|
+
sdkHeaderEntry?: string;
|
|
15
|
+
};
|
|
12
16
|
/**
|
|
13
17
|
* Creates a fully initialized core runtime from validated SDK configuration.
|
|
14
18
|
*
|
|
15
19
|
* @param config - Resolved SDK configuration.
|
|
20
|
+
* @param options - Optional runtime construction options.
|
|
16
21
|
* @returns Runtime containing tracer, agent manager, and shutdown function.
|
|
17
22
|
*/
|
|
18
|
-
export declare function createCore(config: Config): CoreRuntime;
|
|
23
|
+
export declare function createCore(config: Config, options?: CreateCoreOptions): CoreRuntime;
|
|
19
24
|
//# sourceMappingURL=create-core.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-core.d.ts","sourceRoot":"","sources":["../src/create-core.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAI1C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG7C,MAAM,MAAM,WAAW,GAAG;IACxB,qDAAqD;IACrD,MAAM,EAAE,MAAM,CAAC;IAEf,0EAA0E;IAC1E,YAAY,EAAE,oBAAoB,CAAC;IAEnC,oEAAoE;IACpE,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/B,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"create-core.d.ts","sourceRoot":"","sources":["../src/create-core.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAI1C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG7C,MAAM,MAAM,WAAW,GAAG;IACxB,qDAAqD;IACrD,MAAM,EAAE,MAAM,CAAC;IAEf,0EAA0E;IAC1E,YAAY,EAAE,oBAAoB,CAAC;IAEnC,oEAAoE;IACpE,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,yEAAyE;IACzE,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB,GAAG,WAAW,CAoCvF"}
|
package/dist/create-core.js
CHANGED
|
@@ -9,14 +9,17 @@ import { HttpTransport } from './transport/http.js';
|
|
|
9
9
|
* Creates a fully initialized core runtime from validated SDK configuration.
|
|
10
10
|
*
|
|
11
11
|
* @param config - Resolved SDK configuration.
|
|
12
|
+
* @param options - Optional runtime construction options.
|
|
12
13
|
* @returns Runtime containing tracer, agent manager, and shutdown function.
|
|
13
14
|
*/
|
|
14
|
-
export function createCore(config) {
|
|
15
|
+
export function createCore(config, options = {}) {
|
|
15
16
|
if (!config.httpConfig) {
|
|
16
17
|
throw new Error('HTTP transport requires httpConfig to be provided in configuration');
|
|
17
18
|
}
|
|
18
19
|
const httpConfig = HttpTransportConfigSchema.parse(config.httpConfig);
|
|
19
|
-
const transport =
|
|
20
|
+
const transport = options.sdkHeaderEntry === undefined
|
|
21
|
+
? new HttpTransport(httpConfig)
|
|
22
|
+
: new HttpTransport(httpConfig, options.sdkHeaderEntry);
|
|
20
23
|
let partition;
|
|
21
24
|
if (config.httpConfig.agentId) {
|
|
22
25
|
try {
|
package/dist/create-core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-core.js","sourceRoot":"","sources":["../src/create-core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAkB,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAEnE,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"create-core.js","sourceRoot":"","sources":["../src/create-core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAkB,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAEnE,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,eAAe,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QAC1B,oBAAoB,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC,CAAC;IACF,MAAM,OAAO,GAAgB,EAAE,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAC;IAChE,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAC9B,OAAO,OAAO,CAAC;AACjB,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,
|
|
@@ -621,6 +623,32 @@ function calculateRetryDelay(attempt, config, random = Math.random) {
|
|
|
621
623
|
return Math.round(baseDelay * jitterMultiplier);
|
|
622
624
|
}
|
|
623
625
|
|
|
626
|
+
// packages/core/src/version.ts
|
|
627
|
+
var PACKAGE_NAME = "@prefactor/core";
|
|
628
|
+
var PACKAGE_VERSION = "0.3.3";
|
|
629
|
+
|
|
630
|
+
// packages/core/src/transport/http/sdk-request-header.ts
|
|
631
|
+
var DEFAULT_SDK_REQUEST_HEADER = formatSdkHeaderEntry(PACKAGE_NAME, PACKAGE_VERSION);
|
|
632
|
+
function buildSdkRequestHeader(...entries) {
|
|
633
|
+
const parts = [
|
|
634
|
+
...entries.filter((entry) => Boolean(entry)).map((entry) => normalizeSdkHeaderEntry(entry)),
|
|
635
|
+
DEFAULT_SDK_REQUEST_HEADER
|
|
636
|
+
];
|
|
637
|
+
return Array.from(new Set(parts)).join(" ");
|
|
638
|
+
}
|
|
639
|
+
function normalizeSdkHeaderEntry(entry) {
|
|
640
|
+
const atIndex = entry.lastIndexOf("@");
|
|
641
|
+
if (atIndex <= 0) {
|
|
642
|
+
return entry;
|
|
643
|
+
}
|
|
644
|
+
const packageName = entry.slice(0, atIndex);
|
|
645
|
+
const version = entry.slice(atIndex + 1);
|
|
646
|
+
return version ? `${packageName}@${version}` : packageName;
|
|
647
|
+
}
|
|
648
|
+
function formatSdkHeaderEntry(packageName, version) {
|
|
649
|
+
return `${packageName}@${version}`;
|
|
650
|
+
}
|
|
651
|
+
|
|
624
652
|
// packages/core/src/transport/http/http-client.ts
|
|
625
653
|
class HttpClientError extends Error {
|
|
626
654
|
url;
|
|
@@ -646,11 +674,13 @@ class HttpClient {
|
|
|
646
674
|
fetchFn;
|
|
647
675
|
sleep;
|
|
648
676
|
random;
|
|
649
|
-
|
|
677
|
+
sdkHeader;
|
|
678
|
+
constructor(config, dependencies = {}, sdkHeaderEntry) {
|
|
650
679
|
this.config = config;
|
|
651
680
|
this.fetchFn = dependencies.fetchFn ?? fetch;
|
|
652
681
|
this.sleep = dependencies.sleep ?? ((delayMs) => new Promise((resolve) => setTimeout(resolve, delayMs)));
|
|
653
682
|
this.random = dependencies.random ?? Math.random;
|
|
683
|
+
this.sdkHeader = sdkHeaderEntry ? buildSdkRequestHeader(sdkHeaderEntry) : DEFAULT_SDK_REQUEST_HEADER;
|
|
654
684
|
}
|
|
655
685
|
async request(path, options = {}) {
|
|
656
686
|
const url = new URL(path, this.config.apiUrl).toString();
|
|
@@ -659,6 +689,7 @@ class HttpClient {
|
|
|
659
689
|
while (true) {
|
|
660
690
|
const headers = new Headers(options.headers);
|
|
661
691
|
headers.set("Authorization", `Bearer ${this.config.apiToken}`);
|
|
692
|
+
headers.set("X-Prefactor-SDK", this.sdkHeader);
|
|
662
693
|
if (options.body !== undefined && !headers.has("Content-Type")) {
|
|
663
694
|
headers.set("Content-Type", "application/json");
|
|
664
695
|
}
|
|
@@ -798,9 +829,9 @@ class HttpTransport {
|
|
|
798
829
|
spanIdMap = new Map;
|
|
799
830
|
pendingFinishes = new Map;
|
|
800
831
|
pendingChildren = new Map;
|
|
801
|
-
constructor(config) {
|
|
832
|
+
constructor(config, sdkHeaderEntry) {
|
|
802
833
|
this.config = config;
|
|
803
|
-
const httpClient = new HttpClient(config);
|
|
834
|
+
const httpClient = sdkHeaderEntry === undefined ? new HttpClient(config) : new HttpClient(config, {}, sdkHeaderEntry);
|
|
804
835
|
this.agentInstanceClient = new AgentInstanceClient(httpClient);
|
|
805
836
|
this.agentSpanClient = new AgentSpanClient(httpClient);
|
|
806
837
|
this.taskExecutor = new TaskExecutor(this.actionQueue, this.processAction, {
|
|
@@ -1086,12 +1117,12 @@ class HttpTransport {
|
|
|
1086
1117
|
}
|
|
1087
1118
|
|
|
1088
1119
|
// packages/core/src/create-core.ts
|
|
1089
|
-
function createCore(config) {
|
|
1120
|
+
function createCore(config, options = {}) {
|
|
1090
1121
|
if (!config.httpConfig) {
|
|
1091
1122
|
throw new Error("HTTP transport requires httpConfig to be provided in configuration");
|
|
1092
1123
|
}
|
|
1093
1124
|
const httpConfig = HttpTransportConfigSchema.parse(config.httpConfig);
|
|
1094
|
-
const transport = new HttpTransport(httpConfig);
|
|
1125
|
+
const transport = options.sdkHeaderEntry === undefined ? new HttpTransport(httpConfig) : new HttpTransport(httpConfig, options.sdkHeaderEntry);
|
|
1095
1126
|
let partition;
|
|
1096
1127
|
if (config.httpConfig.agentId) {
|
|
1097
1128
|
try {
|
|
@@ -1203,7 +1234,8 @@ class PrefactorClient {
|
|
|
1203
1234
|
}
|
|
1204
1235
|
}
|
|
1205
1236
|
function init(options) {
|
|
1206
|
-
const
|
|
1237
|
+
const sdkHeaderEntry = options.provider.getSdkHeaderEntry?.();
|
|
1238
|
+
const nextInitKey = buildInitKey(options, sdkHeaderEntry);
|
|
1207
1239
|
if (prefactorClient) {
|
|
1208
1240
|
if (prefactorInitKey !== nextInitKey) {
|
|
1209
1241
|
throw new Error("Prefactor is already initialized with a different provider or configuration. " + "Call shutdown() before re-initializing with different options.");
|
|
@@ -1223,7 +1255,21 @@ function init(options) {
|
|
|
1223
1255
|
}
|
|
1224
1256
|
};
|
|
1225
1257
|
}
|
|
1226
|
-
|
|
1258
|
+
if (finalConfig.httpConfig?.agentSchema) {
|
|
1259
|
+
const normalizedSchema = options.provider.normalizeAgentSchema?.(finalConfig.httpConfig.agentSchema);
|
|
1260
|
+
if (normalizedSchema) {
|
|
1261
|
+
finalConfig = {
|
|
1262
|
+
...finalConfig,
|
|
1263
|
+
httpConfig: {
|
|
1264
|
+
...finalConfig.httpConfig,
|
|
1265
|
+
agentSchema: normalizedSchema
|
|
1266
|
+
}
|
|
1267
|
+
};
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
const core = createCore(finalConfig, {
|
|
1271
|
+
sdkHeaderEntry
|
|
1272
|
+
});
|
|
1227
1273
|
const httpConfig = finalConfig.httpConfig;
|
|
1228
1274
|
if (httpConfig?.agentSchema) {
|
|
1229
1275
|
core.agentManager.registerSchema(httpConfig.agentSchema);
|
|
@@ -1236,9 +1282,13 @@ function init(options) {
|
|
|
1236
1282
|
function getClient() {
|
|
1237
1283
|
return prefactorClient;
|
|
1238
1284
|
}
|
|
1239
|
-
function buildInitKey(options) {
|
|
1285
|
+
function buildInitKey(options, sdkHeaderEntry) {
|
|
1240
1286
|
const providerType = options.provider.constructor?.name ?? "anonymous-provider";
|
|
1241
|
-
return
|
|
1287
|
+
return stableStringify2({
|
|
1288
|
+
providerType,
|
|
1289
|
+
httpConfig: options.httpConfig ?? null,
|
|
1290
|
+
sdkHeaderEntry: sdkHeaderEntry ?? null
|
|
1291
|
+
});
|
|
1242
1292
|
}
|
|
1243
1293
|
function stableStringify2(value) {
|
|
1244
1294
|
return JSON.stringify(normalizeValue2(value));
|
|
@@ -1258,6 +1308,160 @@ function normalizeValue2(value) {
|
|
|
1258
1308
|
}
|
|
1259
1309
|
return value;
|
|
1260
1310
|
}
|
|
1311
|
+
// packages/core/src/tool-schema.ts
|
|
1312
|
+
var logger2 = getLogger("tool-schema");
|
|
1313
|
+
function normalizeAgentToolSchemas(agentSchema, {
|
|
1314
|
+
defaultAgentSchema,
|
|
1315
|
+
providerName
|
|
1316
|
+
}) {
|
|
1317
|
+
const toolSchemas = extractToolSchemas(agentSchema, providerName);
|
|
1318
|
+
return {
|
|
1319
|
+
agentSchema: mergeWithDefaultAgentSchema(stripToolSchemas(agentSchema), defaultAgentSchema),
|
|
1320
|
+
toolSchemas,
|
|
1321
|
+
toolSpanTypes: buildToolSpanTypes(toolSchemas)
|
|
1322
|
+
};
|
|
1323
|
+
}
|
|
1324
|
+
function resolveMappedSpanType(toolName, toolSpanTypes, defaultSpanType) {
|
|
1325
|
+
return toolSpanTypes?.[toolName] ?? defaultSpanType;
|
|
1326
|
+
}
|
|
1327
|
+
function extractToolSchemas(agentSchema, providerName) {
|
|
1328
|
+
const rawToolSchemas = getRawToolSchemas(agentSchema);
|
|
1329
|
+
if (!rawToolSchemas) {
|
|
1330
|
+
return;
|
|
1331
|
+
}
|
|
1332
|
+
const toolSchemas = {};
|
|
1333
|
+
const toolBySpanType = new Map;
|
|
1334
|
+
for (const [toolName, rawConfig] of Object.entries(rawToolSchemas)) {
|
|
1335
|
+
const parsedToolSchema = parseToolSchemaConfig(toolName, rawConfig, providerName, toolBySpanType);
|
|
1336
|
+
if (!parsedToolSchema) {
|
|
1337
|
+
continue;
|
|
1338
|
+
}
|
|
1339
|
+
toolSchemas[toolName] = parsedToolSchema;
|
|
1340
|
+
}
|
|
1341
|
+
return Object.keys(toolSchemas).length > 0 ? toolSchemas : undefined;
|
|
1342
|
+
}
|
|
1343
|
+
function getRawToolSchemas(agentSchema) {
|
|
1344
|
+
if (!agentSchema || typeof agentSchema !== "object" || Array.isArray(agentSchema)) {
|
|
1345
|
+
return;
|
|
1346
|
+
}
|
|
1347
|
+
const rawToolSchemas = agentSchema.toolSchemas;
|
|
1348
|
+
if (rawToolSchemas === undefined) {
|
|
1349
|
+
return;
|
|
1350
|
+
}
|
|
1351
|
+
if (!rawToolSchemas || typeof rawToolSchemas !== "object" || Array.isArray(rawToolSchemas)) {
|
|
1352
|
+
logger2.warn("Ignoring invalid agentSchema.toolSchemas: expected an object keyed by tool name.");
|
|
1353
|
+
return;
|
|
1354
|
+
}
|
|
1355
|
+
return rawToolSchemas;
|
|
1356
|
+
}
|
|
1357
|
+
function parseToolSchemaConfig(toolName, rawConfig, providerName, toolBySpanType) {
|
|
1358
|
+
if (!rawConfig || typeof rawConfig !== "object" || Array.isArray(rawConfig)) {
|
|
1359
|
+
logger2.warn(`Invalid agentSchema.toolSchemas.${toolName}: expected an object with spanType and inputSchema.`);
|
|
1360
|
+
return;
|
|
1361
|
+
}
|
|
1362
|
+
const config = rawConfig;
|
|
1363
|
+
if (typeof config.spanType !== "string") {
|
|
1364
|
+
logger2.warn(`Invalid agentSchema.toolSchemas.${toolName}.spanType: expected a non-empty string.`);
|
|
1365
|
+
return;
|
|
1366
|
+
}
|
|
1367
|
+
const inputSchema = assertValidInputSchema(toolName, config.inputSchema);
|
|
1368
|
+
if (!inputSchema) {
|
|
1369
|
+
return;
|
|
1370
|
+
}
|
|
1371
|
+
const normalizedSpanType = normalizeUniqueToolSpanType(toolName, config.spanType, providerName, toolBySpanType);
|
|
1372
|
+
if (!normalizedSpanType) {
|
|
1373
|
+
return;
|
|
1374
|
+
}
|
|
1375
|
+
return {
|
|
1376
|
+
spanType: normalizedSpanType,
|
|
1377
|
+
inputSchema
|
|
1378
|
+
};
|
|
1379
|
+
}
|
|
1380
|
+
function assertValidInputSchema(toolName, inputSchema) {
|
|
1381
|
+
if (!inputSchema || typeof inputSchema !== "object" || Array.isArray(inputSchema)) {
|
|
1382
|
+
logger2.warn(`Invalid agentSchema.toolSchemas.${toolName}.inputSchema: expected an object.`);
|
|
1383
|
+
return;
|
|
1384
|
+
}
|
|
1385
|
+
return inputSchema;
|
|
1386
|
+
}
|
|
1387
|
+
function normalizeUniqueToolSpanType(toolName, spanType, providerName, toolBySpanType) {
|
|
1388
|
+
const normalizedSpanType = normalizeToolSpanType(spanType, toolName, providerName);
|
|
1389
|
+
if (!normalizedSpanType) {
|
|
1390
|
+
return;
|
|
1391
|
+
}
|
|
1392
|
+
const conflictingTool = toolBySpanType.get(normalizedSpanType);
|
|
1393
|
+
if (conflictingTool && conflictingTool !== toolName) {
|
|
1394
|
+
logger2.warn(`Invalid agentSchema.toolSchemas.${toolName}.spanType: normalized span type "${normalizedSpanType}" conflicts with "${conflictingTool}".`);
|
|
1395
|
+
return;
|
|
1396
|
+
}
|
|
1397
|
+
toolBySpanType.set(normalizedSpanType, toolName);
|
|
1398
|
+
return normalizedSpanType;
|
|
1399
|
+
}
|
|
1400
|
+
function buildToolSpanTypes(toolSchemas) {
|
|
1401
|
+
if (!toolSchemas) {
|
|
1402
|
+
return;
|
|
1403
|
+
}
|
|
1404
|
+
return Object.fromEntries(Object.entries(toolSchemas).map(([toolName, config]) => [toolName, config.spanType]));
|
|
1405
|
+
}
|
|
1406
|
+
function cloneRecord(value) {
|
|
1407
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
1408
|
+
return {};
|
|
1409
|
+
}
|
|
1410
|
+
return { ...value };
|
|
1411
|
+
}
|
|
1412
|
+
function stripToolSchemas(baseSchema) {
|
|
1413
|
+
if (!baseSchema || typeof baseSchema !== "object" || Array.isArray(baseSchema)) {
|
|
1414
|
+
return baseSchema;
|
|
1415
|
+
}
|
|
1416
|
+
const { toolSchemas: _, ...rest } = baseSchema;
|
|
1417
|
+
return rest;
|
|
1418
|
+
}
|
|
1419
|
+
function mergeWithDefaultAgentSchema(baseSchema, defaultAgentSchema) {
|
|
1420
|
+
if (!baseSchema) {
|
|
1421
|
+
return defaultAgentSchema;
|
|
1422
|
+
}
|
|
1423
|
+
return {
|
|
1424
|
+
...defaultAgentSchema,
|
|
1425
|
+
...baseSchema,
|
|
1426
|
+
span_schemas: {
|
|
1427
|
+
...cloneRecord(defaultAgentSchema.span_schemas),
|
|
1428
|
+
...cloneRecord(baseSchema.span_schemas)
|
|
1429
|
+
},
|
|
1430
|
+
span_result_schemas: {
|
|
1431
|
+
...cloneRecord(defaultAgentSchema.span_result_schemas),
|
|
1432
|
+
...cloneRecord(baseSchema.span_result_schemas)
|
|
1433
|
+
}
|
|
1434
|
+
};
|
|
1435
|
+
}
|
|
1436
|
+
function normalizeToolSpanType(spanType, toolName, providerName) {
|
|
1437
|
+
const trimmedSpanType = spanType.trim();
|
|
1438
|
+
if (trimmedSpanType.length === 0) {
|
|
1439
|
+
logger2.warn(`Invalid agentSchema.toolSchemas.${toolName}.spanType: expected a non-empty string.`);
|
|
1440
|
+
return;
|
|
1441
|
+
}
|
|
1442
|
+
const providerToolPrefix = `${providerName}:tool:`;
|
|
1443
|
+
if (trimmedSpanType.startsWith(providerToolPrefix)) {
|
|
1444
|
+
const suffix2 = trimmedSpanType.slice(providerToolPrefix.length).replace(/^:+/, "");
|
|
1445
|
+
if (suffix2.length === 0) {
|
|
1446
|
+
logger2.warn(`Invalid agentSchema.toolSchemas.${toolName}.spanType: expected a non-empty suffix after normalization.`);
|
|
1447
|
+
return;
|
|
1448
|
+
}
|
|
1449
|
+
return `${providerName}:tool:${suffix2}`;
|
|
1450
|
+
}
|
|
1451
|
+
let suffix = trimmedSpanType;
|
|
1452
|
+
if (suffix.startsWith(`${providerName}:`)) {
|
|
1453
|
+
suffix = suffix.slice(`${providerName}:`.length);
|
|
1454
|
+
}
|
|
1455
|
+
if (suffix.startsWith("tool:")) {
|
|
1456
|
+
suffix = suffix.slice("tool:".length);
|
|
1457
|
+
}
|
|
1458
|
+
suffix = suffix.replace(/^:+/, "");
|
|
1459
|
+
if (suffix.length === 0) {
|
|
1460
|
+
logger2.warn(`Invalid agentSchema.toolSchemas.${toolName}.spanType: expected a non-empty suffix after normalization.`);
|
|
1461
|
+
return;
|
|
1462
|
+
}
|
|
1463
|
+
return `${providerName}:tool:${suffix}`;
|
|
1464
|
+
}
|
|
1261
1465
|
// packages/core/src/utils/serialization.ts
|
|
1262
1466
|
function truncateString(value, maxLength) {
|
|
1263
1467
|
if (value.length <= maxLength) {
|
|
@@ -1292,4 +1496,4 @@ function serializeValue(value, maxLength = 1e4) {
|
|
|
1292
1496
|
}
|
|
1293
1497
|
}
|
|
1294
1498
|
|
|
1295
|
-
//# debugId=
|
|
1499
|
+
//# debugId=3EC702ECBCC3224764756E2164756E21
|