@temporalio/openai-agents 1.19.0 → 1.20.0
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/lib/workflow/span-helpers.d.ts +1 -1
- package/lib/workflow/span-helpers.js +1 -4
- package/lib/workflow/span-helpers.js.map +1 -1
- package/lib/workflow/trace-interceptor.js +15 -18
- package/lib/workflow/trace-interceptor.js.map +1 -1
- package/package.json +10 -10
- package/src/workflow/span-helpers.ts +1 -9
- package/src/workflow/trace-interceptor.ts +34 -46
- package/lib/workflow/prng.d.ts +0 -4
- package/lib/workflow/prng.js +0 -42
- package/lib/workflow/prng.js.map +0 -1
- package/src/workflow/prng.ts +0 -38
|
@@ -2,7 +2,7 @@ import type { Headers } from '@temporalio/workflow';
|
|
|
2
2
|
import { type AgentsSpanHeader } from '../common/headers';
|
|
3
3
|
export declare function shouldAddTemporalSpans(): boolean;
|
|
4
4
|
export declare function isFireAndForgetActivity(activityType: string): boolean;
|
|
5
|
-
export declare function maybeTemporalSpan<T>(spanName: string, fn: () => T, data?: Record<string, unknown
|
|
5
|
+
export declare function maybeTemporalSpan<T>(spanName: string, fn: () => T, data?: Record<string, unknown>): T;
|
|
6
6
|
export declare function withInjectedHeader<I extends {
|
|
7
7
|
headers: Headers;
|
|
8
8
|
}, T>(input: I, next: (i: I) => Promise<T>, spanConfig?: {
|
|
@@ -19,13 +19,10 @@ const FIRE_AND_FORGET_ACTIVITY_SUFFIXES = [mcp_types_1.MCP_SERVER_SESSION_SUFFIX
|
|
|
19
19
|
function isFireAndForgetActivity(activityType) {
|
|
20
20
|
return FIRE_AND_FORGET_ACTIVITY_SUFFIXES.some((s) => activityType.endsWith(s));
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
// persisted to history, so generated IDs can collide with body spans.
|
|
24
|
-
function maybeTemporalSpan(spanName, fn, data, spanId) {
|
|
22
|
+
function maybeTemporalSpan(spanName, fn, data) {
|
|
25
23
|
if (shouldAddTemporalSpans() && (0, agents_core_1.getCurrentTrace)()) {
|
|
26
24
|
const span = (0, agents_core_1.createCustomSpan)({
|
|
27
25
|
data: { name: spanName, data: data ?? {} },
|
|
28
|
-
...(spanId !== undefined ? { spanId } : {}),
|
|
29
26
|
});
|
|
30
27
|
return (0, trace_context_1.withScopedSpan)(span, fn);
|
|
31
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"span-helpers.js","sourceRoot":"","sources":["../../src/workflow/span-helpers.ts"],"names":[],"mappings":";;AAOA,wDAEC;AAMD,0DAEC;
|
|
1
|
+
{"version":3,"file":"span-helpers.js","sourceRoot":"","sources":["../../src/workflow/span-helpers.ts"],"names":[],"mappings":";;AAOA,wDAEC;AAMD,0DAEC;AAED,8CAQC;AAID,gDAeC;AAMD,gFAMC;AA1DD,qDAAwE;AAExE,+CAA4G;AAC5G,mDAAgE;AAChE,2DAAyD;AACzD,+DAA+D;AAE/D,SAAgB,sBAAsB;IACpC,OAAO,IAAA,4CAAsB,GAAE,EAAE,gBAAgB,KAAK,IAAI,CAAC;AAC7D,CAAC;AAED,yEAAyE;AACzE,wBAAwB;AACxB,MAAM,iCAAiC,GAAG,CAAC,qCAAyB,CAAC,CAAC;AAEtE,SAAgB,uBAAuB,CAAC,YAAoB;IAC1D,OAAO,iCAAiC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AACjF,CAAC;AAED,SAAgB,iBAAiB,CAAI,QAAgB,EAAE,EAAW,EAAE,IAA8B;IAChG,IAAI,sBAAsB,EAAE,IAAI,IAAA,6BAAe,GAAE,EAAE,CAAC;QAClD,MAAM,IAAI,GAAG,IAAA,8BAAgB,EAAC;YAC5B,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,IAAI,EAAE,EAAE;SAC3C,CAAC,CAAC;QACH,OAAO,IAAA,8BAAc,EAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAClC,CAAC;IACD,OAAO,EAAE,EAAE,CAAC;AACd,CAAC;AAED,8EAA8E;AAC9E,yDAAyD;AAClD,KAAK,UAAU,kBAAkB,CACtC,KAAQ,EACR,IAA0B,EAC1B,UAA6D;IAE7D,MAAM,QAAQ,GAAG,GAAe,EAAE;QAChC,MAAM,MAAM,GAAG,IAAA,iCAAuB,GAAE,CAAC;QACzC,MAAM,OAAO,GAAG,IAAA,iCAAuB,EAAC,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC/D,OAAO,IAAI,CAAC,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;IACrC,CAAC,CAAC;IAEF,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,iBAAiB,CAAC,UAAU,CAAC,IAAI,EAAE,QAAQ,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;IACvE,CAAC;IACD,OAAO,QAAQ,EAAE,CAAC;AACpB,CAAC;AAED,8EAA8E;AAC9E,6EAA6E;AAC7E,yEAAyE;AACzE,6EAA6E;AAC7E,SAAgB,kCAAkC,CAAC,QAAgB,EAAE,IAA6B;IAChG,IAAI,sBAAsB,EAAE,IAAI,IAAA,6BAAe,GAAE,EAAE,CAAC;QAClD,MAAM,IAAI,GAAG,IAAA,8BAAgB,EAAC,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;QAClE,OAAO,IAAA,8BAAc,EAAC,IAAI,EAAE,GAAG,EAAE,CAAC,IAAA,iCAAuB,GAAE,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,IAAA,iCAAuB,GAAE,CAAC;AACnC,CAAC"}
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.interceptors = void 0;
|
|
4
4
|
const agents_core_1 = require("@openai/agents-core");
|
|
5
5
|
const workflow_1 = require("@temporalio/workflow");
|
|
6
|
-
const global_attributes_1 = require("@temporalio/workflow/lib/global-attributes");
|
|
7
6
|
const headers_1 = require("../common/headers");
|
|
8
7
|
const trace_context_1 = require("../common/trace-context");
|
|
9
8
|
const model_activity_options_1 = require("../common/model-activity-options");
|
|
@@ -11,19 +10,14 @@ const span_helpers_1 = require("./span-helpers");
|
|
|
11
10
|
const plugin_config_store_1 = require("./plugin-config-store");
|
|
12
11
|
const tracing_1 = require("./tracing");
|
|
13
12
|
const agent_sink_processor_1 = require("./agent-sink-processor");
|
|
14
|
-
const prng_1 = require("./prng");
|
|
15
13
|
const TRACING_STREAM_NAME = 'package-openai-agents-tracing';
|
|
14
|
+
// The Workflow body, signals, and updates persist their tracing-ID draws to
|
|
15
|
+
// history, so they must use the replay-seeded stream. Query handlers and update
|
|
16
|
+
// validators are read-only — their draws aren't persisted — so they use
|
|
17
|
+
// `unsafe.random` instead, which is the only safe random source there.
|
|
16
18
|
function tracingRandom() {
|
|
17
19
|
return (0, workflow_1.getRandomStream)(TRACING_STREAM_NAME).random();
|
|
18
20
|
}
|
|
19
|
-
// Temporal Core hard-codes queryId === 'legacy_query' on the legacy single-Query
|
|
20
|
-
// Workflow Task path, so distinct Queries collide on the spanId/PRNG seed.
|
|
21
|
-
function resolveQueryKey(input) {
|
|
22
|
-
if (input.queryId !== 'legacy_query')
|
|
23
|
-
return input.queryId;
|
|
24
|
-
// Legacy queries arrive one at a time with a hardcoded id.
|
|
25
|
-
return `${input.queryName}:${(0, global_attributes_1.getActivator)().getTimeOfDay()}`;
|
|
26
|
-
}
|
|
27
21
|
/**
|
|
28
22
|
* Inbound interceptor: populates the per-Workflow plugin-config store from
|
|
29
23
|
* the propagated config header and restores agent trace context.
|
|
@@ -68,20 +62,23 @@ class OpenAIAgentsTraceInboundInterceptor {
|
|
|
68
62
|
});
|
|
69
63
|
}
|
|
70
64
|
async handleQuery(input, next) {
|
|
71
|
-
|
|
72
|
-
return (0, tracing_1.runWithTracingRandom)((0, prng_1.prngFromInputId)(keyInput), () => {
|
|
65
|
+
return (0, tracing_1.runWithTracingRandom)(() => (0, workflow_1.workflowInfo)().unsafe.random.random(), () => {
|
|
73
66
|
const header = (0, headers_1.extractAgentsTraceHeader)(input.headers);
|
|
74
|
-
const spanId = (0, prng_1.spanIdFromInputId)(keyInput);
|
|
75
67
|
if (!header?.traceId) {
|
|
76
|
-
return (0, trace_context_1.withIsolatedAgentsTraceContext)(() => (0, span_helpers_1.maybeTemporalSpan)(`temporal:handleQuery:${input.queryName}`, () => next(input), {
|
|
68
|
+
return (0, trace_context_1.withIsolatedAgentsTraceContext)(() => (0, span_helpers_1.maybeTemporalSpan)(`temporal:handleQuery:${input.queryName}`, () => next(input), {
|
|
69
|
+
queryName: input.queryName,
|
|
70
|
+
}));
|
|
77
71
|
}
|
|
78
|
-
return (0, trace_context_1.withRestoredAgentsTraceContext)(header, () => (0, span_helpers_1.maybeTemporalSpan)(`temporal:handleQuery:${input.queryName}`, () => next(input), {
|
|
72
|
+
return (0, trace_context_1.withRestoredAgentsTraceContext)(header, () => (0, span_helpers_1.maybeTemporalSpan)(`temporal:handleQuery:${input.queryName}`, () => next(input), {
|
|
73
|
+
queryName: input.queryName,
|
|
74
|
+
}));
|
|
79
75
|
});
|
|
80
76
|
}
|
|
81
77
|
validateUpdate(input, next) {
|
|
82
|
-
return (0, tracing_1.runWithTracingRandom)((0,
|
|
83
|
-
const
|
|
84
|
-
|
|
78
|
+
return (0, tracing_1.runWithTracingRandom)(() => (0, workflow_1.workflowInfo)().unsafe.random.random(), () => {
|
|
79
|
+
const runValidate = () => (0, span_helpers_1.maybeTemporalSpan)(`temporal:validateUpdate:${input.name}`, () => next(input), {
|
|
80
|
+
updateName: input.name,
|
|
81
|
+
});
|
|
85
82
|
const header = (0, headers_1.extractAgentsTraceHeader)(input.headers);
|
|
86
83
|
if (!header?.traceId) {
|
|
87
84
|
return (0, trace_context_1.withIsolatedAgentsTraceContext)(runValidate);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trace-interceptor.js","sourceRoot":"","sources":["../../src/workflow/trace-interceptor.ts"],"names":[],"mappings":";;;AAAA,qDAAwE;AACxE,mDAqB8B;AAC9B
|
|
1
|
+
{"version":3,"file":"trace-interceptor.js","sourceRoot":"","sources":["../../src/workflow/trace-interceptor.ts"],"names":[],"mappings":";;;AAAA,qDAAwE;AACxE,mDAqB8B;AAC9B,+CAO2B;AAC3B,2DAIiC;AACjC,6EAAkF;AAClF,iDAMwB;AACxB,+DAAsH;AACtH,uCAAmF;AACnF,iEAAwE;AAExE,MAAM,mBAAmB,GAAG,+BAA+B,CAAC;AAE5D,4EAA4E;AAC5E,gFAAgF;AAChF,wEAAwE;AACxE,uEAAuE;AACvE,SAAS,aAAa;IACpB,OAAO,IAAA,0BAAe,EAAC,mBAAmB,CAAC,CAAC,MAAM,EAAE,CAAC;AACvD,CAAC;AAED;;;GAGG;AACH,MAAM,mCAAmC;IACvC,KAAK,CAAC,OAAO,CAAC,KAA2B,EAAE,IAAsD;QAC/F,IAAA,0CAAgC,GAAE,CAAC;QAEnC,MAAM,YAAY,GAAG,IAAA,mCAAyB,EAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC9D,IAAI,YAAY,EAAE,CAAC;YACjB,MAAM,YAAY,GAAiB;gBACjC,gBAAgB,EAAE,YAAY,CAAC,gBAAgB,IAAI,KAAK;gBACxD,sBAAsB,EAAE,YAAY,CAAC,sBAAsB,IAAI,KAAK;gBACpE,WAAW,EAAE,EAAE,GAAG,uDAA8B,EAAE,GAAG,YAAY,CAAC,WAAW,EAAE;aAChF,CAAC;YACF,IAAA,qCAAe,EAAC,YAAY,CAAC,CAAC;QAChC,CAAC;QAED,IAAI,CAAC;YACH,OAAO,MAAM,IAAA,8BAAoB,EAAC,aAAa,EAAE,GAAG,EAAE;gBACpD,MAAM,MAAM,GAAG,IAAA,kCAAwB,EAAC,KAAK,CAAC,OAAO,CAAC,CAAC;gBACvD,IAAI,CAAC,MAAM,EAAE,OAAO,E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AAA,iCAAuB,EAAC,iBAAiB,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;IACzF,CAAC;CACF;AAED,SAAS,2BAA2B,CAAC,OAAgB;IACnD,MAAM,MAAM,GAAG,IAAA,4CAAsB,GAAE,CAAC;IACxC,IAAI,CAAC,MAAM;QAAE,OAAO,OAAO,CAAC;IAE5B,OAAO,IAAA,kCAAwB,EAAC,OAAO,EAAE;QACvC,gBAAgB,EAAE,MAAM,CAAC,gBAAgB;QACzC,sBAAsB,EAAE,MAAM,CAAC,sBAAsB;QACrD,WAAW,EAAE,MAAM,CAAC,WAAW;KAChC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,gCAAgC;IACpC,OAAO,CAAC,KAAmB,EAAE,IAAmD;QAC9E,IAAA,uCAAiB,GAAE,CAAC;QACpB,IAAA,qCAAc,GAAE,CAAC;QACjB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;CACF;AAEM,MAAM,YAAY,GAAG,GAAyB,EAAE,CAAC,CAAC;IACvD,OAAO,EAAE,CAAC,IAAI,mCAAmC,EAAE,CAAC;IACpD,QAAQ,EAAE,CAAC,IAAI,oCAAoC,EAAE,CAAC;IACtD,SAAS,EAAE,CAAC,IAAI,gCAAgC,EAAE,CAAC;CACpD,CAAC,CAAC;AAJU,QAAA,YAAY,gBAItB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temporalio/openai-agents",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.20.0",
|
|
4
4
|
"description": "Temporal OpenAI Agents SDK integration package",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -66,11 +66,11 @@
|
|
|
66
66
|
"@ungap/structured-clone": "^1.3.1",
|
|
67
67
|
"headers-polyfill": "^4.0.3",
|
|
68
68
|
"web-streams-polyfill": "^4.2.0",
|
|
69
|
-
"@temporalio/
|
|
70
|
-
"@temporalio/
|
|
71
|
-
"@temporalio/
|
|
72
|
-
"@temporalio/
|
|
73
|
-
"@temporalio/
|
|
69
|
+
"@temporalio/common": "1.20.0",
|
|
70
|
+
"@temporalio/workflow": "1.20.0",
|
|
71
|
+
"@temporalio/activity": "1.20.0",
|
|
72
|
+
"@temporalio/plugin": "1.20.0",
|
|
73
|
+
"@temporalio/worker": "1.20.0"
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
76
76
|
"@openai/agents-core": "~0.11.6",
|
|
@@ -93,10 +93,10 @@
|
|
|
93
93
|
"ava": "^5.3.1",
|
|
94
94
|
"nexus-rpc": "^0.0.2",
|
|
95
95
|
"openai": "^6.35.0",
|
|
96
|
-
"@temporalio/
|
|
97
|
-
"@temporalio/
|
|
98
|
-
"@temporalio/
|
|
99
|
-
"@temporalio/
|
|
96
|
+
"@temporalio/client": "1.20.0",
|
|
97
|
+
"@temporalio/proto": "1.20.0",
|
|
98
|
+
"@temporalio/test-helpers": "1.20.0",
|
|
99
|
+
"@temporalio/testing": "1.20.0"
|
|
100
100
|
},
|
|
101
101
|
"engines": {
|
|
102
102
|
"node": ">= 20.3.0"
|
|
@@ -17,18 +17,10 @@ export function isFireAndForgetActivity(activityType: string): boolean {
|
|
|
17
17
|
return FIRE_AND_FORGET_ACTIVITY_SUFFIXES.some((s) => activityType.endsWith(s));
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
// persisted to history, so generated IDs can collide with body spans.
|
|
22
|
-
export function maybeTemporalSpan<T>(
|
|
23
|
-
spanName: string,
|
|
24
|
-
fn: () => T,
|
|
25
|
-
data?: Record<string, unknown>,
|
|
26
|
-
spanId?: string
|
|
27
|
-
): T {
|
|
20
|
+
export function maybeTemporalSpan<T>(spanName: string, fn: () => T, data?: Record<string, unknown>): T {
|
|
28
21
|
if (shouldAddTemporalSpans() && getCurrentTrace()) {
|
|
29
22
|
const span = createCustomSpan({
|
|
30
23
|
data: { name: spanName, data: data ?? {} },
|
|
31
|
-
...(spanId !== undefined ? { spanId } : {}),
|
|
32
24
|
});
|
|
33
25
|
return withScopedSpan(span, fn);
|
|
34
26
|
}
|
|
@@ -21,7 +21,6 @@ import {
|
|
|
21
21
|
type WorkflowInterceptors,
|
|
22
22
|
type WorkflowOutboundCallsInterceptor,
|
|
23
23
|
} from '@temporalio/workflow';
|
|
24
|
-
import { getActivator } from '@temporalio/workflow/lib/global-attributes';
|
|
25
24
|
import {
|
|
26
25
|
currentAgentsSpanHeader,
|
|
27
26
|
extractAgentsConfigHeader,
|
|
@@ -46,22 +45,17 @@ import {
|
|
|
46
45
|
import { getCurrentPluginConfig, setPluginConfig, clearPluginConfig, type PluginConfig } from './plugin-config-store';
|
|
47
46
|
import { ensureTracingProcessorRegistered, runWithTracingRandom } from './tracing';
|
|
48
47
|
import { clearOpenSpans, flushOpenSpans } from './agent-sink-processor';
|
|
49
|
-
import { prngFromInputId, spanIdFromInputId } from './prng';
|
|
50
48
|
|
|
51
49
|
const TRACING_STREAM_NAME = 'package-openai-agents-tracing';
|
|
52
50
|
|
|
51
|
+
// The Workflow body, signals, and updates persist their tracing-ID draws to
|
|
52
|
+
// history, so they must use the replay-seeded stream. Query handlers and update
|
|
53
|
+
// validators are read-only — their draws aren't persisted — so they use
|
|
54
|
+
// `unsafe.random` instead, which is the only safe random source there.
|
|
53
55
|
function tracingRandom(): number {
|
|
54
56
|
return getRandomStream(TRACING_STREAM_NAME).random();
|
|
55
57
|
}
|
|
56
58
|
|
|
57
|
-
// Temporal Core hard-codes queryId === 'legacy_query' on the legacy single-Query
|
|
58
|
-
// Workflow Task path, so distinct Queries collide on the spanId/PRNG seed.
|
|
59
|
-
function resolveQueryKey(input: QueryInput): string {
|
|
60
|
-
if (input.queryId !== 'legacy_query') return input.queryId;
|
|
61
|
-
// Legacy queries arrive one at a time with a hardcoded id.
|
|
62
|
-
return `${input.queryName}:${getActivator().getTimeOfDay()}`;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
59
|
/**
|
|
66
60
|
* Inbound interceptor: populates the per-Workflow plugin-config store from
|
|
67
61
|
* the propagated config header and restores agent trace context.
|
|
@@ -117,49 +111,43 @@ class OpenAIAgentsTraceInboundInterceptor implements WorkflowInboundCallsInterce
|
|
|
117
111
|
}
|
|
118
112
|
|
|
119
113
|
async handleQuery(input: QueryInput, next: Next<WorkflowInboundCallsInterceptor, 'handleQuery'>): Promise<unknown> {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
114
|
+
return runWithTracingRandom(
|
|
115
|
+
() => workflowInfo().unsafe.random.random(),
|
|
116
|
+
() => {
|
|
117
|
+
const header = extractAgentsTraceHeader(input.headers);
|
|
124
118
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
119
|
+
if (!header?.traceId) {
|
|
120
|
+
return withIsolatedAgentsTraceContext(() =>
|
|
121
|
+
maybeTemporalSpan(`temporal:handleQuery:${input.queryName}`, () => next(input), {
|
|
122
|
+
queryName: input.queryName,
|
|
123
|
+
})
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return withRestoredAgentsTraceContext(header, () =>
|
|
128
|
+
maybeTemporalSpan(`temporal:handleQuery:${input.queryName}`, () => next(input), {
|
|
129
|
+
queryName: input.queryName,
|
|
130
|
+
})
|
|
133
131
|
);
|
|
134
132
|
}
|
|
135
|
-
|
|
136
|
-
return withRestoredAgentsTraceContext(header, () =>
|
|
137
|
-
maybeTemporalSpan(
|
|
138
|
-
`temporal:handleQuery:${input.queryName}`,
|
|
139
|
-
() => next(input),
|
|
140
|
-
{ queryName: input.queryName },
|
|
141
|
-
spanId
|
|
142
|
-
)
|
|
143
|
-
);
|
|
144
|
-
});
|
|
133
|
+
);
|
|
145
134
|
}
|
|
146
135
|
|
|
147
136
|
validateUpdate(input: UpdateInput, next: Next<WorkflowInboundCallsInterceptor, 'validateUpdate'>): void {
|
|
148
|
-
return runWithTracingRandom(
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
`temporal:validateUpdate:${input.name}`,
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
)
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
return
|
|
137
|
+
return runWithTracingRandom(
|
|
138
|
+
() => workflowInfo().unsafe.random.random(),
|
|
139
|
+
() => {
|
|
140
|
+
const runValidate = () =>
|
|
141
|
+
maybeTemporalSpan(`temporal:validateUpdate:${input.name}`, () => next(input), {
|
|
142
|
+
updateName: input.name,
|
|
143
|
+
});
|
|
144
|
+
const header = extractAgentsTraceHeader(input.headers);
|
|
145
|
+
if (!header?.traceId) {
|
|
146
|
+
return withIsolatedAgentsTraceContext(runValidate);
|
|
147
|
+
}
|
|
148
|
+
return withRestoredAgentsTraceContext(header, runValidate);
|
|
160
149
|
}
|
|
161
|
-
|
|
162
|
-
});
|
|
150
|
+
);
|
|
163
151
|
}
|
|
164
152
|
|
|
165
153
|
async handleUpdate(
|
package/lib/workflow/prng.d.ts
DELETED
package/lib/workflow/prng.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fnv1a32 = fnv1a32;
|
|
4
|
-
exports.spanIdFromInputId = spanIdFromInputId;
|
|
5
|
-
exports.mulberry32 = mulberry32;
|
|
6
|
-
exports.prngFromInputId = prngFromInputId;
|
|
7
|
-
function fnv1a32(s) {
|
|
8
|
-
let h = 0x811c9dc5;
|
|
9
|
-
for (let i = 0; i < s.length; i++) {
|
|
10
|
-
h ^= s.charCodeAt(i);
|
|
11
|
-
h = Math.imul(h, 0x01000193);
|
|
12
|
-
}
|
|
13
|
-
return h >>> 0;
|
|
14
|
-
}
|
|
15
|
-
// Agent-SDK-shaped span ID derived from a Temporal-supplied unique input ID
|
|
16
|
-
// (queryId/updateId), orthogonal to the Workflow PRNG stream. Uses three
|
|
17
|
-
// salted FNV-1a-32 hashes (96 bits) to fill 24 hex characters, so user-
|
|
18
|
-
// supplied IDs that differ by case or punctuation produce distinct span IDs.
|
|
19
|
-
function spanIdFromInputId(inputId) {
|
|
20
|
-
const a = fnv1a32(`0:${inputId}`).toString(16).padStart(8, '0');
|
|
21
|
-
const b = fnv1a32(`1:${inputId}`).toString(16).padStart(8, '0');
|
|
22
|
-
const c = fnv1a32(`2:${inputId}`).toString(16).padStart(8, '0');
|
|
23
|
-
return `span_${a}${b}${c}`;
|
|
24
|
-
}
|
|
25
|
-
function mulberry32(seed) {
|
|
26
|
-
let s = seed >>> 0;
|
|
27
|
-
return () => {
|
|
28
|
-
s = (s + 0x6d2b79f5) >>> 0;
|
|
29
|
-
let t = s;
|
|
30
|
-
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
31
|
-
t = (t + Math.imul(t ^ (t >>> 7), t | 61)) ^ t;
|
|
32
|
-
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
// Per-call PRNG seeded from a unique input ID. Read-only handlers must NOT
|
|
36
|
-
// reuse the body PRNG: handler-task PRNG consumption isn't persisted, so
|
|
37
|
-
// using the body PRNG would either desync the body or collide across
|
|
38
|
-
// concurrent handlers in fresh-VM tasks.
|
|
39
|
-
function prngFromInputId(inputId) {
|
|
40
|
-
return mulberry32(fnv1a32(inputId));
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=prng.js.map
|
package/lib/workflow/prng.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prng.js","sourceRoot":"","sources":["../../src/workflow/prng.ts"],"names":[],"mappings":";;AAAA,0BAOC;AAMD,8CAKC;AAED,gCASC;AAMD,0CAEC;AArCD,SAAgB,OAAO,CAAC,CAAS;IAC/B,IAAI,CAAC,GAAG,UAAU,CAAC;IACnB,KAAK,I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IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;QAC/C,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,UAAU,CAAC;IAC/C,CAAC,CAAC;AACJ,CAAC;AAED,2EAA2E;AAC3E,yEAAyE;AACzE,qEAAqE;AACrE,yCAAyC;AACzC,SAAgB,eAAe,CAAC,OAAe;IAC7C,OAAO,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;AACtC,CAAC"}
|
package/src/workflow/prng.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
export function fnv1a32(s: string): number {
|
|
2
|
-
let h = 0x811c9dc5;
|
|
3
|
-
for (let i = 0; i < s.length; i++) {
|
|
4
|
-
h ^= s.charCodeAt(i);
|
|
5
|
-
h = Math.imul(h, 0x01000193);
|
|
6
|
-
}
|
|
7
|
-
return h >>> 0;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
// Agent-SDK-shaped span ID derived from a Temporal-supplied unique input ID
|
|
11
|
-
// (queryId/updateId), orthogonal to the Workflow PRNG stream. Uses three
|
|
12
|
-
// salted FNV-1a-32 hashes (96 bits) to fill 24 hex characters, so user-
|
|
13
|
-
// supplied IDs that differ by case or punctuation produce distinct span IDs.
|
|
14
|
-
export function spanIdFromInputId(inputId: string): string {
|
|
15
|
-
const a = fnv1a32(`0:${inputId}`).toString(16).padStart(8, '0');
|
|
16
|
-
const b = fnv1a32(`1:${inputId}`).toString(16).padStart(8, '0');
|
|
17
|
-
const c = fnv1a32(`2:${inputId}`).toString(16).padStart(8, '0');
|
|
18
|
-
return `span_${a}${b}${c}`;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function mulberry32(seed: number): () => number {
|
|
22
|
-
let s = seed >>> 0;
|
|
23
|
-
return () => {
|
|
24
|
-
s = (s + 0x6d2b79f5) >>> 0;
|
|
25
|
-
let t = s;
|
|
26
|
-
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
27
|
-
t = (t + Math.imul(t ^ (t >>> 7), t | 61)) ^ t;
|
|
28
|
-
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Per-call PRNG seeded from a unique input ID. Read-only handlers must NOT
|
|
33
|
-
// reuse the body PRNG: handler-task PRNG consumption isn't persisted, so
|
|
34
|
-
// using the body PRNG would either desync the body or collide across
|
|
35
|
-
// concurrent handlers in fresh-VM tasks.
|
|
36
|
-
export function prngFromInputId(inputId: string): () => number {
|
|
37
|
-
return mulberry32(fnv1a32(inputId));
|
|
38
|
-
}
|