@promptbook/cli 0.112.0-112 → 0.112.0-113
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/README.md +7 -7
- package/apps/agents-server/README.md +1 -1
- package/apps/agents-server/next.config.ts +20 -1
- package/apps/agents-server/src/app/api/admin/code-runners/route.ts +1 -1
- package/apps/agents-server/src/app/api/internal/user-chat-jobs/run/route.ts +1 -1
- package/apps/agents-server/src/instrumentation-client.ts +28 -0
- package/apps/agents-server/src/instrumentation.ts +16 -0
- package/apps/agents-server/src/sentry.edge.config.ts +18 -0
- package/apps/agents-server/src/sentry.server.config.ts +19 -0
- package/apps/agents-server/src/utils/codeRunnerConfiguration.ts +1 -1
- package/apps/agents-server/src/utils/errorReporting/agentsServerSentryContext.ts +203 -0
- package/apps/agents-server/src/utils/errorReporting/registerServerErrorSentryLogging.ts +59 -9
- package/apps/agents-server/src/utils/errorReporting/sendApplicationErrorReportToSentry.ts +39 -3
- package/apps/agents-server/src/utils/errorReporting/sentrySdkConfig.ts +237 -0
- package/apps/agents-server/src/utils/errorReporting/sentryStore.ts +10 -0
- package/apps/agents-server/src/utils/externalChatRunner/createExternalAgentRepositoryFiles.ts +2 -2
- package/apps/agents-server/src/utils/userChat/triggerUserChatJobWorker.ts +54 -19
- package/apps/agents-server/src/utils/vpsConfiguration.ts +1 -1
- package/esm/index.es.js +9325 -8883
- package/esm/index.es.js.map +1 -1
- package/esm/scripts/run-agent-chat/executeAgentChatTurn.d.ts +28 -0
- package/esm/scripts/run-agent-chat/runAgentChat.d.ts +5 -0
- package/esm/scripts/run-agent-chat/runAgentExec.d.ts +11 -0
- package/esm/scripts/run-agent-messages/messages/createAgentRunnerSystemMessage.d.ts +10 -0
- package/esm/scripts/run-codex-prompts/common/resolveInlineOrFileText.d.ts +14 -0
- package/esm/src/_packages/node.index.d.ts +20 -0
- package/esm/src/_packages/types.index.d.ts +16 -0
- package/esm/src/book-3.0/BookNodeAgentSource.d.ts +38 -0
- package/esm/src/book-3.0/CliAgent.d.ts +68 -0
- package/esm/src/book-3.0/LiteAgent.d.ts +68 -0
- package/esm/src/book-components/BookEditor/BookEditorAboutPromptbookInformation.d.ts +12 -0
- package/esm/src/cli/cli-commands/agent/agentCliOptions.d.ts +29 -0
- package/esm/src/cli/cli-commands/agent/chat.d.ts +10 -0
- package/esm/src/cli/cli-commands/agent/exec.d.ts +10 -0
- package/esm/src/cli/cli-commands/agent/run.test.d.ts +1 -0
- package/esm/src/cli/cli-commands/agent.d.ts +14 -0
- package/esm/src/cli/cli-commands/agents-server/startAgentsServer.d.ts +3 -4
- package/esm/src/cli/cli-commands/common/promptRunnerCliOptions.d.ts +9 -9
- package/esm/src/version.d.ts +1 -1
- package/package.json +2 -1
- package/src/_packages/node.index.ts +20 -0
- package/src/_packages/types.index.ts +16 -0
- package/src/book-3.0/BookNodeAgentSource.ts +135 -0
- package/src/book-3.0/CliAgent.ts +236 -0
- package/src/book-3.0/LiteAgent.ts +463 -0
- package/src/book-components/BookEditor/BookEditor.module.css +61 -0
- package/src/book-components/BookEditor/BookEditorAboutPromptbookInformation.tsx +74 -0
- package/src/book-components/BookEditor/BookEditorActionbar.tsx +3 -3
- package/src/cli/cli-commands/agent/agentCliOptions.ts +63 -0
- package/src/cli/cli-commands/agent/chat.ts +54 -0
- package/src/cli/cli-commands/agent/exec.ts +60 -0
- package/src/cli/cli-commands/agent.ts +45 -0
- package/src/cli/cli-commands/agents-server/startAgentsServer.ts +3 -19
- package/src/cli/cli-commands/coder/getDefaultCoderPackageJsonScripts.ts +1 -1
- package/src/cli/cli-commands/common/promptRunnerCliOptions.ts +27 -23
- package/src/cli/promptbookCli.ts +2 -0
- package/src/other/templates/getTemplatesPipelineCollection.ts +836 -774
- package/src/version.ts +2 -2
- package/src/versions.txt +1 -0
- package/umd/index.umd.js +9325 -8883
- package/umd/index.umd.js.map +1 -1
- package/umd/scripts/run-agent-chat/executeAgentChatTurn.d.ts +28 -0
- package/umd/scripts/run-agent-chat/runAgentChat.d.ts +5 -0
- package/umd/scripts/run-agent-chat/runAgentExec.d.ts +11 -0
- package/umd/scripts/run-agent-messages/messages/createAgentRunnerSystemMessage.d.ts +10 -0
- package/umd/scripts/run-codex-prompts/common/resolveInlineOrFileText.d.ts +14 -0
- package/umd/src/_packages/node.index.d.ts +20 -0
- package/umd/src/_packages/types.index.d.ts +16 -0
- package/umd/src/book-3.0/BookNodeAgentSource.d.ts +38 -0
- package/umd/src/book-3.0/CliAgent.d.ts +68 -0
- package/umd/src/book-3.0/CliAgent.test.d.ts +1 -0
- package/umd/src/book-3.0/LiteAgent.d.ts +68 -0
- package/umd/src/book-3.0/LiteAgent.test.d.ts +1 -0
- package/umd/src/book-components/BookEditor/BookEditorAboutPromptbookInformation.d.ts +12 -0
- package/umd/src/cli/cli-commands/agent/agentCliOptions.d.ts +29 -0
- package/umd/src/cli/cli-commands/agent/chat.d.ts +10 -0
- package/umd/src/cli/cli-commands/agent/exec.d.ts +10 -0
- package/umd/src/cli/cli-commands/agent/run.test.d.ts +1 -0
- package/umd/src/cli/cli-commands/agent.d.ts +14 -0
- package/umd/src/cli/cli-commands/agents-server/startAgentsServer.d.ts +3 -4
- package/umd/src/cli/cli-commands/common/promptRunnerCliOptions.d.ts +9 -9
- package/umd/src/version.d.ts +1 -1
- /package/esm/src/{cli/cli-commands/agents-server/startAgentsServer.test.d.ts → book-3.0/CliAgent.test.d.ts} +0 -0
- /package/{umd/src/cli/cli-commands/agents-server/startAgentsServer.test.d.ts → esm/src/book-3.0/LiteAgent.test.d.ts} +0 -0
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION } from '../../../../../src/version';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Default Sentry project DSN for Promptbook Agents Server telemetry.
|
|
5
|
+
*
|
|
6
|
+
* @private internal Sentry SDK configuration for Agents Server
|
|
7
|
+
*/
|
|
8
|
+
export const DEFAULT_SENTRY_DSN =
|
|
9
|
+
'https://986f734e9cddaeeec33e2a360f7d0b62@o4508778158030848.ingest.de.sentry.io/4511534509785168';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Sentry organization slug used by build-time SDK tooling.
|
|
13
|
+
*
|
|
14
|
+
* @private internal Sentry SDK configuration for Agents Server
|
|
15
|
+
*/
|
|
16
|
+
export const SENTRY_ORGANIZATION = 'promptbook';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Sentry project slug used by build-time SDK tooling.
|
|
20
|
+
*
|
|
21
|
+
* @private internal Sentry SDK configuration for Agents Server
|
|
22
|
+
*/
|
|
23
|
+
export const SENTRY_PROJECT = 's22';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Performance tracing sample rate requested for the Agents Server.
|
|
27
|
+
*
|
|
28
|
+
* @private internal Sentry SDK configuration for Agents Server
|
|
29
|
+
*/
|
|
30
|
+
export const SENTRY_TRACES_SAMPLE_RATE = 1.0;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Browser-side targets that should receive distributed tracing headers.
|
|
34
|
+
*
|
|
35
|
+
* @private internal Sentry SDK configuration for Agents Server
|
|
36
|
+
*/
|
|
37
|
+
export const SENTRY_TRACE_PROPAGATION_TARGETS: Array<string | RegExp> = [
|
|
38
|
+
'localhost',
|
|
39
|
+
/^\/api\//,
|
|
40
|
+
/^https:\/\/.*\.ptbk\.io\/api\//,
|
|
41
|
+
/^https:\/\/.*\.vercel\.app\/api\//,
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Release name used for Agents Server Sentry events.
|
|
46
|
+
*/
|
|
47
|
+
const AGENTS_SERVER_SENTRY_RELEASE_NAME = 'promptbook-agents-server';
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Fallback text used in Sentry tags when a value is not configured.
|
|
51
|
+
*/
|
|
52
|
+
const UNKNOWN_SENTRY_CONTEXT_VALUE = 'unknown';
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Maximum length kept for Sentry tag values.
|
|
56
|
+
*/
|
|
57
|
+
const MAX_SENTRY_TAG_VALUE_LENGTH = 200;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Resolves the browser-safe Sentry DSN.
|
|
61
|
+
*
|
|
62
|
+
* @returns Browser-safe Sentry DSN.
|
|
63
|
+
*
|
|
64
|
+
* @private internal Sentry SDK configuration for Agents Server
|
|
65
|
+
*/
|
|
66
|
+
export function resolveBrowserSentryDsn(): string {
|
|
67
|
+
return process.env.NEXT_PUBLIC_SENTRY_DSN ?? DEFAULT_SENTRY_DSN;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Resolves the server-side Sentry DSN.
|
|
72
|
+
*
|
|
73
|
+
* @returns Server-side Sentry DSN.
|
|
74
|
+
*
|
|
75
|
+
* @private internal Sentry SDK configuration for Agents Server
|
|
76
|
+
*/
|
|
77
|
+
export function resolveServerSentryDsn(): string {
|
|
78
|
+
return process.env.SENTRY_DSN ?? resolveBrowserSentryDsn();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Resolves the most specific deployment environment name available.
|
|
83
|
+
*
|
|
84
|
+
* @returns Environment name suitable for Sentry.
|
|
85
|
+
*
|
|
86
|
+
* @private internal Sentry SDK configuration for Agents Server
|
|
87
|
+
*/
|
|
88
|
+
export function resolveSentrySdkEnvironment(): string {
|
|
89
|
+
return (
|
|
90
|
+
getFirstNonEmptyString(
|
|
91
|
+
process.env.SENTRY_ENVIRONMENT,
|
|
92
|
+
process.env.NEXT_PUBLIC_VERCEL_TARGET_ENV,
|
|
93
|
+
process.env.VERCEL_TARGET_ENV,
|
|
94
|
+
process.env.NEXT_PUBLIC_VERCEL_ENV,
|
|
95
|
+
process.env.VERCEL_ENV,
|
|
96
|
+
process.env.PROMPTBOOK_REPOSITORY_REF,
|
|
97
|
+
process.env.NODE_ENV,
|
|
98
|
+
) ?? UNKNOWN_SENTRY_CONTEXT_VALUE
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Resolves the current deployment commit hash from common hosting environment variables.
|
|
104
|
+
*
|
|
105
|
+
* @returns Commit hash or null when unavailable.
|
|
106
|
+
*
|
|
107
|
+
* @private internal Sentry SDK configuration for Agents Server
|
|
108
|
+
*/
|
|
109
|
+
export function resolveSentrySdkCommitHash(): string | null {
|
|
110
|
+
return getFirstNonEmptyString(
|
|
111
|
+
process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA,
|
|
112
|
+
process.env.VERCEL_GIT_COMMIT_SHA,
|
|
113
|
+
process.env.PROMPTBOOK_COMMIT_SHA,
|
|
114
|
+
process.env.GIT_COMMIT_SHA,
|
|
115
|
+
process.env.COMMIT_SHA,
|
|
116
|
+
process.env.SOURCE_VERSION,
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Resolves the current repository branch or deployment ref.
|
|
122
|
+
*
|
|
123
|
+
* @returns Repository branch/ref or null when unavailable.
|
|
124
|
+
*
|
|
125
|
+
* @private internal Sentry SDK configuration for Agents Server
|
|
126
|
+
*/
|
|
127
|
+
export function resolveSentrySdkRepositoryBranch(): string | null {
|
|
128
|
+
return getFirstNonEmptyString(
|
|
129
|
+
process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF,
|
|
130
|
+
process.env.VERCEL_GIT_COMMIT_REF,
|
|
131
|
+
process.env.PROMPTBOOK_REPOSITORY_REF,
|
|
132
|
+
process.env.GIT_BRANCH,
|
|
133
|
+
process.env.BRANCH_NAME,
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Resolves the Sentry release name for the current Agents Server build.
|
|
139
|
+
*
|
|
140
|
+
* @returns Release identifier suitable for Sentry.
|
|
141
|
+
*
|
|
142
|
+
* @private internal Sentry SDK configuration for Agents Server
|
|
143
|
+
*/
|
|
144
|
+
export function resolveSentrySdkRelease(): string {
|
|
145
|
+
const appPackageVersion = normalizeOptionalString(process.env.npm_package_version) ?? PROMPTBOOK_ENGINE_VERSION;
|
|
146
|
+
const commitHash = resolveSentrySdkCommitHash();
|
|
147
|
+
|
|
148
|
+
if (!commitHash) {
|
|
149
|
+
return `${AGENTS_SERVER_SENTRY_RELEASE_NAME}@${appPackageVersion}`;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return `${AGENTS_SERVER_SENTRY_RELEASE_NAME}@${appPackageVersion}+${commitHash}`;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Creates shared filterable Sentry tags for Agents Server events.
|
|
157
|
+
*
|
|
158
|
+
* @returns Sanitized Sentry tags.
|
|
159
|
+
*
|
|
160
|
+
* @private internal Sentry SDK configuration for Agents Server
|
|
161
|
+
*/
|
|
162
|
+
export function createSentrySdkTags(): Record<string, string> {
|
|
163
|
+
return createSentryTags({
|
|
164
|
+
promptbookEngineVersion: PROMPTBOOK_ENGINE_VERSION,
|
|
165
|
+
bookLanguageVersion: BOOK_LANGUAGE_VERSION,
|
|
166
|
+
appPackageVersion: normalizeOptionalString(process.env.npm_package_version) ?? PROMPTBOOK_ENGINE_VERSION,
|
|
167
|
+
commitHash: resolveSentrySdkCommitHash(),
|
|
168
|
+
repositoryBranch: resolveSentrySdkRepositoryBranch(),
|
|
169
|
+
deploymentEnvironment: resolveSentrySdkEnvironment(),
|
|
170
|
+
vercelEnvironment: getFirstNonEmptyString(process.env.NEXT_PUBLIC_VERCEL_ENV, process.env.VERCEL_ENV),
|
|
171
|
+
targetEnvironment: getFirstNonEmptyString(
|
|
172
|
+
process.env.NEXT_PUBLIC_VERCEL_TARGET_ENV,
|
|
173
|
+
process.env.VERCEL_TARGET_ENV,
|
|
174
|
+
),
|
|
175
|
+
nextRuntime: process.env.NEXT_RUNTIME,
|
|
176
|
+
nodeEnvironment: process.env.NODE_ENV,
|
|
177
|
+
vercelRegion: process.env.VERCEL_REGION,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Creates Sentry tag values, preserving missing values as explicit `unknown` markers.
|
|
183
|
+
*
|
|
184
|
+
* @param values - Raw tag values.
|
|
185
|
+
* @returns Sanitized Sentry tags.
|
|
186
|
+
*/
|
|
187
|
+
function createSentryTags(values: Record<string, string | null | undefined>): Record<string, string> {
|
|
188
|
+
return Object.fromEntries(
|
|
189
|
+
Object.entries(values).map(([key, value]) => [key, sanitizeSentryTagValue(value)]),
|
|
190
|
+
) as Record<string, string>;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Normalizes one value for use as a Sentry tag.
|
|
195
|
+
*
|
|
196
|
+
* @param value - Optional tag value.
|
|
197
|
+
* @returns Non-empty bounded tag value.
|
|
198
|
+
*/
|
|
199
|
+
function sanitizeSentryTagValue(value: string | null | undefined): string {
|
|
200
|
+
const normalizedValue = normalizeOptionalString(value) ?? UNKNOWN_SENTRY_CONTEXT_VALUE;
|
|
201
|
+
|
|
202
|
+
return normalizedValue.replace(/\s+/gu, ' ').slice(0, MAX_SENTRY_TAG_VALUE_LENGTH);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Returns the first non-empty string from a list.
|
|
207
|
+
*
|
|
208
|
+
* @param values - Candidate values in priority order.
|
|
209
|
+
* @returns First trimmed string or null.
|
|
210
|
+
*/
|
|
211
|
+
function getFirstNonEmptyString(...values: Array<string | null | undefined>): string | null {
|
|
212
|
+
for (const value of values) {
|
|
213
|
+
const normalizedValue = normalizeOptionalString(value);
|
|
214
|
+
|
|
215
|
+
if (normalizedValue) {
|
|
216
|
+
return normalizedValue;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Trims one optional environment value.
|
|
225
|
+
*
|
|
226
|
+
* @param value - Raw optional value.
|
|
227
|
+
* @returns Trimmed string or null.
|
|
228
|
+
*/
|
|
229
|
+
function normalizeOptionalString(value: string | null | undefined): string | null {
|
|
230
|
+
if (typeof value !== 'string') {
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const normalizedValue = value.trim();
|
|
235
|
+
|
|
236
|
+
return normalizedValue || null;
|
|
237
|
+
}
|
|
@@ -52,6 +52,16 @@ export type SentryStorePayload = {
|
|
|
52
52
|
*/
|
|
53
53
|
message: string;
|
|
54
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Sentry release identifier.
|
|
57
|
+
*/
|
|
58
|
+
release?: string;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Deployment environment such as production, preview, or staging.
|
|
62
|
+
*/
|
|
63
|
+
environment?: string;
|
|
64
|
+
|
|
55
65
|
/**
|
|
56
66
|
* Server/deployment name.
|
|
57
67
|
*/
|
package/apps/agents-server/src/utils/externalChatRunner/createExternalAgentRepositoryFiles.ts
CHANGED
|
@@ -53,9 +53,9 @@ function createExternalAgentRepositoryPackageJson(): string {
|
|
|
53
53
|
scripts: {
|
|
54
54
|
start: 'npm run agent:run',
|
|
55
55
|
'agent:run':
|
|
56
|
-
'npx ptbk agent-folder run-agent --
|
|
56
|
+
'npx ptbk agent-folder run-agent --harness github-copilot --model gpt-5.4 --thinking-level high --auto-pull --auto-push',
|
|
57
57
|
'agent-local:run':
|
|
58
|
-
'ts-node ../../promptbook/src/cli/test/ptbk.ts agent-folder run-agent --
|
|
58
|
+
'ts-node ../../promptbook/src/cli/test/ptbk.ts agent-folder run-agent --harness github-copilot --model gpt-5.4 --auto-pull --auto-push',
|
|
59
59
|
},
|
|
60
60
|
},
|
|
61
61
|
null,
|
|
@@ -1,28 +1,63 @@
|
|
|
1
1
|
import { resolveUserChatWorkerInternalToken } from './resolveUserChatWorkerInternalToken';
|
|
2
|
+
import { retryWithBackoff } from '../retryWithBackoff';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Number of retries for transient transport failures while waking the durable chat worker.
|
|
6
|
+
*/
|
|
7
|
+
const USER_CHAT_WORKER_TRIGGER_FETCH_RETRIES = 2;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Initial wait before retrying a failed worker wake-up request.
|
|
11
|
+
*/
|
|
12
|
+
const USER_CHAT_WORKER_TRIGGER_FETCH_INITIAL_DELAY_MS = 250;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Maximum wait before retrying a failed worker wake-up request.
|
|
16
|
+
*/
|
|
17
|
+
const USER_CHAT_WORKER_TRIGGER_FETCH_MAX_DELAY_MS = 1_000;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Multiplier used between worker wake-up retry waits.
|
|
21
|
+
*/
|
|
22
|
+
const USER_CHAT_WORKER_TRIGGER_FETCH_BACKOFF_FACTOR = 2;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Randomized extra delay ratio for worker wake-up retry waits.
|
|
26
|
+
*/
|
|
27
|
+
const USER_CHAT_WORKER_TRIGGER_FETCH_JITTER_RATIO = 0.2;
|
|
2
28
|
|
|
3
29
|
/**
|
|
4
30
|
* Schedules one best-effort internal worker invocation for durable chat jobs.
|
|
5
31
|
*/
|
|
6
|
-
export async function triggerUserChatJobWorker(options: {
|
|
7
|
-
origin: string;
|
|
8
|
-
preferredJobId?: string;
|
|
9
|
-
}): Promise<void> {
|
|
32
|
+
export async function triggerUserChatJobWorker(options: { origin: string; preferredJobId?: string }): Promise<void> {
|
|
10
33
|
const workerUrl = new URL('/api/internal/user-chat-jobs/run', ensureTrailingSlashlessOrigin(options.origin));
|
|
11
|
-
const response =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
34
|
+
const response = (
|
|
35
|
+
await retryWithBackoff(
|
|
36
|
+
async () =>
|
|
37
|
+
await fetch(workerUrl, {
|
|
38
|
+
method: 'POST',
|
|
39
|
+
cache: 'no-store',
|
|
40
|
+
headers: {
|
|
41
|
+
'Content-Type': 'application/json',
|
|
42
|
+
'x-user-chat-worker-token': resolveUserChatWorkerInternalToken(),
|
|
43
|
+
},
|
|
44
|
+
body: JSON.stringify(
|
|
45
|
+
options.preferredJobId
|
|
46
|
+
? {
|
|
47
|
+
preferredJobId: options.preferredJobId,
|
|
48
|
+
}
|
|
49
|
+
: {},
|
|
50
|
+
),
|
|
51
|
+
}),
|
|
52
|
+
{
|
|
53
|
+
retries: USER_CHAT_WORKER_TRIGGER_FETCH_RETRIES,
|
|
54
|
+
initialDelayMs: USER_CHAT_WORKER_TRIGGER_FETCH_INITIAL_DELAY_MS,
|
|
55
|
+
maxDelayMs: USER_CHAT_WORKER_TRIGGER_FETCH_MAX_DELAY_MS,
|
|
56
|
+
backoffFactor: USER_CHAT_WORKER_TRIGGER_FETCH_BACKOFF_FACTOR,
|
|
57
|
+
jitterRatio: USER_CHAT_WORKER_TRIGGER_FETCH_JITTER_RATIO,
|
|
58
|
+
},
|
|
59
|
+
)
|
|
60
|
+
).value;
|
|
26
61
|
|
|
27
62
|
if (!response.ok && response.status !== 204) {
|
|
28
63
|
throw new Error(`Failed to trigger user chat worker: ${response.status} ${response.statusText}`);
|