deepline 0.1.211 → 0.1.213
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/bundling-sources/apps/play-runner-workers/src/entry.ts +317 -340
- package/dist/bundling-sources/apps/play-runner-workers/src/runtime/customer-console.ts +23 -0
- package/dist/bundling-sources/apps/play-runner-workers/src/runtime/tool-dispatch.ts +1 -1
- package/dist/bundling-sources/sdk/src/client.ts +118 -3
- package/dist/bundling-sources/sdk/src/index.ts +2 -0
- package/dist/bundling-sources/sdk/src/play.ts +8 -1
- package/dist/bundling-sources/sdk/src/plays/bundle-play-file.ts +1 -1
- package/dist/bundling-sources/sdk/src/plays/harness-stub.ts +11 -1
- package/dist/bundling-sources/sdk/src/release.ts +2 -2
- package/dist/bundling-sources/sdk/src/types.ts +47 -0
- package/dist/bundling-sources/shared_libs/play-runtime/app-runtime-api.ts +302 -30
- package/dist/bundling-sources/shared_libs/play-runtime/child-execution-placement.ts +14 -0
- package/dist/bundling-sources/shared_libs/play-runtime/child-execution-strategy.ts +57 -23
- package/dist/bundling-sources/shared_libs/play-runtime/completed-receipt-cache.ts +166 -0
- package/dist/bundling-sources/shared_libs/play-runtime/context.ts +164 -121
- package/dist/bundling-sources/shared_libs/play-runtime/ctx-contract.ts +2 -0
- package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +42 -1
- package/dist/bundling-sources/shared_libs/play-runtime/dataset-id.ts +10 -4
- package/dist/bundling-sources/shared_libs/play-runtime/db-session.ts +9 -0
- package/dist/bundling-sources/shared_libs/play-runtime/durable-receipt-execution.ts +163 -7
- package/dist/bundling-sources/shared_libs/play-runtime/gateway-auth-session.ts +93 -0
- package/dist/bundling-sources/shared_libs/play-runtime/ledger-safe-payload.ts +14 -2
- package/dist/bundling-sources/shared_libs/play-runtime/output-size-limits.ts +4 -2
- package/dist/bundling-sources/shared_libs/play-runtime/play-call-execution.ts +1 -0
- package/dist/bundling-sources/shared_libs/play-runtime/receipt-completion-sink.ts +16 -1
- package/dist/bundling-sources/shared_libs/play-runtime/receipt-sql.ts +21 -1
- package/dist/bundling-sources/shared_libs/play-runtime/receipt-state-sink.ts +10 -0
- package/dist/bundling-sources/shared_libs/play-runtime/resource-governor.ts +80 -3
- package/dist/bundling-sources/shared_libs/play-runtime/run-ledger.ts +128 -6
- package/dist/bundling-sources/shared_libs/play-runtime/run-snapshot-stream.ts +7 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-session-execution.ts +94 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona.ts +91 -6
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/types.ts +19 -10
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-api.ts +540 -92
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-postgres-admission.ts +162 -0
- package/dist/bundling-sources/shared_libs/play-runtime/secret-capability.ts +18 -4
- package/dist/bundling-sources/shared_libs/play-runtime/sheet-attempt-sql.ts +16 -17
- package/dist/bundling-sources/shared_libs/play-runtime/tool-execute-retry-policy.ts +29 -9
- package/dist/bundling-sources/shared_libs/play-runtime/work-receipt-state-machine.ts +22 -1
- package/dist/bundling-sources/shared_libs/play-runtime/work-receipts.ts +1 -0
- package/dist/bundling-sources/shared_libs/plays/bundling/index.ts +79 -1
- package/dist/bundling-sources/shared_libs/plays/static-pipeline.ts +2 -4
- package/dist/cli/index.js +637 -229
- package/dist/cli/index.mjs +637 -229
- package/dist/{compiler-manifest-j6z8qzpd.d.mts → compiler-manifest-BhgZ23A4.d.mts} +1 -0
- package/dist/{compiler-manifest-j6z8qzpd.d.ts → compiler-manifest-BhgZ23A4.d.ts} +1 -0
- package/dist/index.d.mts +84 -11
- package/dist/index.d.ts +84 -11
- package/dist/index.js +225 -43
- package/dist/index.mjs +225 -43
- package/dist/plays/bundle-play-file.d.mts +2 -2
- package/dist/plays/bundle-play-file.d.ts +2 -2
- package/dist/plays/bundle-play-file.mjs +65 -4
- package/package.json +1 -1
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
export type RuntimePostgresLane = 'receipts' | 'sheets';
|
|
2
|
+
|
|
3
|
+
export type RuntimePostgresLaneTelemetry = {
|
|
4
|
+
active: number;
|
|
5
|
+
queued: number;
|
|
6
|
+
acquired: number;
|
|
7
|
+
waited: number;
|
|
8
|
+
timedOut: number;
|
|
9
|
+
rejected: number;
|
|
10
|
+
totalWaitMs: number;
|
|
11
|
+
maxWaitMs: number;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type RuntimePostgresAdmissionSnapshot = Record<
|
|
15
|
+
RuntimePostgresLane,
|
|
16
|
+
RuntimePostgresLaneTelemetry
|
|
17
|
+
>;
|
|
18
|
+
|
|
19
|
+
export class RuntimePostgresAdmissionTimeoutError extends Error {
|
|
20
|
+
constructor(
|
|
21
|
+
readonly lane: RuntimePostgresLane,
|
|
22
|
+
readonly queueDepth: number,
|
|
23
|
+
readonly timeoutMs: number,
|
|
24
|
+
) {
|
|
25
|
+
super(
|
|
26
|
+
`Runtime Postgres ${lane} admission timed out after ${timeoutMs}ms (${queueDepth} queued).`,
|
|
27
|
+
);
|
|
28
|
+
this.name = 'RuntimePostgresAdmissionTimeoutError';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class RuntimePostgresAdmissionQueueFullError extends Error {
|
|
33
|
+
constructor(
|
|
34
|
+
readonly lane: RuntimePostgresLane,
|
|
35
|
+
readonly queueDepth: number,
|
|
36
|
+
) {
|
|
37
|
+
super(
|
|
38
|
+
`Runtime Postgres ${lane} admission queue is full (${queueDepth} queued).`,
|
|
39
|
+
);
|
|
40
|
+
this.name = 'RuntimePostgresAdmissionQueueFullError';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
type Waiter = {
|
|
45
|
+
enqueuedAt: number;
|
|
46
|
+
timeout: ReturnType<typeof setTimeout>;
|
|
47
|
+
resolve: (release: () => void) => void;
|
|
48
|
+
reject: (error: Error) => void;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
type LaneState = RuntimePostgresLaneTelemetry & { waiters: Waiter[] };
|
|
52
|
+
|
|
53
|
+
function createLaneState(): LaneState {
|
|
54
|
+
return {
|
|
55
|
+
active: 0,
|
|
56
|
+
queued: 0,
|
|
57
|
+
acquired: 0,
|
|
58
|
+
waited: 0,
|
|
59
|
+
timedOut: 0,
|
|
60
|
+
rejected: 0,
|
|
61
|
+
totalWaitMs: 0,
|
|
62
|
+
maxWaitMs: 0,
|
|
63
|
+
waiters: [],
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export class RuntimePostgresAdmission {
|
|
68
|
+
readonly #maxActivePerLane: number;
|
|
69
|
+
readonly #maxQueuedPerLane: number;
|
|
70
|
+
readonly #acquireTimeoutMs: number;
|
|
71
|
+
readonly #lanes: Record<RuntimePostgresLane, LaneState> = {
|
|
72
|
+
receipts: createLaneState(),
|
|
73
|
+
sheets: createLaneState(),
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
constructor(input: {
|
|
77
|
+
maxActivePerLane: number;
|
|
78
|
+
maxQueuedPerLane: number;
|
|
79
|
+
acquireTimeoutMs: number;
|
|
80
|
+
}) {
|
|
81
|
+
this.#maxActivePerLane = Math.max(1, Math.floor(input.maxActivePerLane));
|
|
82
|
+
this.#maxQueuedPerLane = Math.max(0, Math.floor(input.maxQueuedPerLane));
|
|
83
|
+
this.#acquireTimeoutMs = Math.max(1, Math.floor(input.acquireTimeoutMs));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async acquire(lane: RuntimePostgresLane): Promise<() => void> {
|
|
87
|
+
const state = this.#lanes[lane];
|
|
88
|
+
if (state.active < this.#maxActivePerLane && state.waiters.length === 0) {
|
|
89
|
+
state.active += 1;
|
|
90
|
+
state.acquired += 1;
|
|
91
|
+
return this.#releaseFor(lane);
|
|
92
|
+
}
|
|
93
|
+
if (state.waiters.length >= this.#maxQueuedPerLane) {
|
|
94
|
+
state.rejected += 1;
|
|
95
|
+
throw new RuntimePostgresAdmissionQueueFullError(
|
|
96
|
+
lane,
|
|
97
|
+
state.waiters.length,
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
state.waited += 1;
|
|
101
|
+
return await new Promise<() => void>((resolve, reject) => {
|
|
102
|
+
const waiter: Waiter = {
|
|
103
|
+
enqueuedAt: Date.now(),
|
|
104
|
+
timeout: setTimeout(() => {
|
|
105
|
+
const index = state.waiters.indexOf(waiter);
|
|
106
|
+
if (index < 0) return;
|
|
107
|
+
state.waiters.splice(index, 1);
|
|
108
|
+
state.queued = state.waiters.length;
|
|
109
|
+
state.timedOut += 1;
|
|
110
|
+
reject(
|
|
111
|
+
new RuntimePostgresAdmissionTimeoutError(
|
|
112
|
+
lane,
|
|
113
|
+
state.waiters.length,
|
|
114
|
+
this.#acquireTimeoutMs,
|
|
115
|
+
),
|
|
116
|
+
);
|
|
117
|
+
}, this.#acquireTimeoutMs),
|
|
118
|
+
resolve,
|
|
119
|
+
reject,
|
|
120
|
+
};
|
|
121
|
+
state.waiters.push(waiter);
|
|
122
|
+
state.queued = state.waiters.length;
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
snapshot(): RuntimePostgresAdmissionSnapshot {
|
|
127
|
+
const snapshotLane = (state: LaneState): RuntimePostgresLaneTelemetry => ({
|
|
128
|
+
active: state.active,
|
|
129
|
+
queued: state.waiters.length,
|
|
130
|
+
acquired: state.acquired,
|
|
131
|
+
waited: state.waited,
|
|
132
|
+
timedOut: state.timedOut,
|
|
133
|
+
rejected: state.rejected,
|
|
134
|
+
totalWaitMs: state.totalWaitMs,
|
|
135
|
+
maxWaitMs: state.maxWaitMs,
|
|
136
|
+
});
|
|
137
|
+
return {
|
|
138
|
+
receipts: snapshotLane(this.#lanes.receipts),
|
|
139
|
+
sheets: snapshotLane(this.#lanes.sheets),
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
#releaseFor(lane: RuntimePostgresLane): () => void {
|
|
144
|
+
let released = false;
|
|
145
|
+
return () => {
|
|
146
|
+
if (released) return;
|
|
147
|
+
released = true;
|
|
148
|
+
const state = this.#lanes[lane];
|
|
149
|
+
state.active -= 1;
|
|
150
|
+
const waiter = state.waiters.shift();
|
|
151
|
+
state.queued = state.waiters.length;
|
|
152
|
+
if (!waiter) return;
|
|
153
|
+
clearTimeout(waiter.timeout);
|
|
154
|
+
const waitMs = Math.max(0, Date.now() - waiter.enqueuedAt);
|
|
155
|
+
state.totalWaitMs += waitMs;
|
|
156
|
+
state.maxWaitMs = Math.max(state.maxWaitMs, waitMs);
|
|
157
|
+
state.active += 1;
|
|
158
|
+
state.acquired += 1;
|
|
159
|
+
waiter.resolve(this.#releaseFor(lane));
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
}
|
|
@@ -39,10 +39,24 @@ export function isSecretAuth(value: unknown): value is SecretAuth {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
export function valueContainsSecret(value: unknown): boolean {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
const pending: unknown[] = [value];
|
|
43
|
+
const seen = new WeakSet<object>();
|
|
44
|
+
while (pending.length > 0) {
|
|
45
|
+
const candidate = pending.pop();
|
|
46
|
+
if (isSecretHandle(candidate) || isSecretAuth(candidate)) return true;
|
|
47
|
+
if (typeof candidate === 'string') {
|
|
48
|
+
if (SECRET_HANDLE_MARKER_RE.test(candidate)) return true;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (!candidate || typeof candidate !== 'object') continue;
|
|
52
|
+
if (seen.has(candidate)) continue;
|
|
53
|
+
seen.add(candidate);
|
|
54
|
+
if (Array.isArray(candidate)) {
|
|
55
|
+
for (const entry of candidate) pending.push(entry);
|
|
56
|
+
} else if (isRecord(candidate)) {
|
|
57
|
+
for (const entry of Object.values(candidate)) pending.push(entry);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
46
60
|
return false;
|
|
47
61
|
}
|
|
48
62
|
|
|
@@ -5,23 +5,14 @@ export function activeRuntimeSheetAttemptFenceSql(
|
|
|
5
5
|
attemptExpiresAtExpression: string,
|
|
6
6
|
attemptSeqExpression?: string,
|
|
7
7
|
): string {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return
|
|
16
|
-
/* owner: runtime; remove null-attempt compat after ledger cutover M1 */
|
|
17
|
-
${tableAlias}._attempt_id IS NULL
|
|
18
|
-
OR ${tableAlias}._attempt_id = ${attemptIdExpression}
|
|
19
|
-
OR ${tableAlias}._attempt_expires_at <= now()
|
|
20
|
-
OR (
|
|
21
|
-
coalesce(${tableAlias}._attempt_owner_run_id, ${tableAlias}._run_id) = ${attemptOwnerRunIdExpression}
|
|
22
|
-
AND ${activeSameOwnerNewerAttempt}
|
|
23
|
-
)
|
|
24
|
-
)`;
|
|
8
|
+
void tableAlias;
|
|
9
|
+
void attemptIdExpression;
|
|
10
|
+
void attemptOwnerRunIdExpression;
|
|
11
|
+
void attemptExpiresAtExpression;
|
|
12
|
+
void attemptSeqExpression;
|
|
13
|
+
// Legacy attempt columns remain during the rolling migration only. They are
|
|
14
|
+
// not row admission or correctness state; schedule-time write versions are.
|
|
15
|
+
return 'TRUE';
|
|
25
16
|
}
|
|
26
17
|
|
|
27
18
|
/**
|
|
@@ -68,6 +59,13 @@ export function newerTerminalRuntimeSheetRowSql(
|
|
|
68
59
|
attemptIdExpression?: string,
|
|
69
60
|
attemptOwnerRunIdExpression?: string,
|
|
70
61
|
): string {
|
|
62
|
+
void tableAlias;
|
|
63
|
+
void attemptExpiresAtExpression;
|
|
64
|
+
void attemptSeqExpression;
|
|
65
|
+
void attemptIdExpression;
|
|
66
|
+
void attemptOwnerRunIdExpression;
|
|
67
|
+
return 'FALSE';
|
|
68
|
+
/* legacy implementation intentionally unreachable during rolling cleanup
|
|
71
69
|
if (attemptSeqExpression !== undefined) {
|
|
72
70
|
const sameSeqDifferentAttemptSql = attemptOwnerRunIdExpression
|
|
73
71
|
? `OR (
|
|
@@ -100,4 +98,5 @@ export function newerTerminalRuntimeSheetRowSql(
|
|
|
100
98
|
AND ${attemptExpiresAtExpression} IS NOT NULL
|
|
101
99
|
AND ${tableAlias}._attempt_expires_at > ${attemptExpiresAtExpression}
|
|
102
100
|
)`;
|
|
101
|
+
*/
|
|
103
102
|
}
|
|
@@ -88,14 +88,15 @@ function decideToolExecuteHttpRetry(input: {
|
|
|
88
88
|
hasRetryAfterHeader?: boolean;
|
|
89
89
|
transientHttpRetrySafe?: boolean;
|
|
90
90
|
}): ToolExecuteHttpRetryDecision {
|
|
91
|
+
if (input.hardBillingFailure) {
|
|
92
|
+
return {
|
|
93
|
+
retryable: false,
|
|
94
|
+
attemptCap:
|
|
95
|
+
input.status === 429 ? TOOL_EXECUTE_RATE_LIMIT_MAX_ATTEMPTS : 1,
|
|
96
|
+
reason: 'hard_billing_error',
|
|
97
|
+
};
|
|
98
|
+
}
|
|
91
99
|
if (input.status === 429) {
|
|
92
|
-
if (input.hardBillingFailure) {
|
|
93
|
-
return {
|
|
94
|
-
retryable: false,
|
|
95
|
-
attemptCap: TOOL_EXECUTE_RATE_LIMIT_MAX_ATTEMPTS,
|
|
96
|
-
reason: 'hard_billing_error',
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
100
|
if (!input.hasRetryAfterHeader) {
|
|
100
101
|
return {
|
|
101
102
|
retryable: true,
|
|
@@ -178,6 +179,7 @@ export function classifyToolExecuteHttpFailure(input: {
|
|
|
178
179
|
bodyText: string;
|
|
179
180
|
retryAfterHeader?: string | null;
|
|
180
181
|
transientHttpRetrySafe?: boolean;
|
|
182
|
+
providerLatencyMs?: number;
|
|
181
183
|
nowMs?: number;
|
|
182
184
|
}): ToolExecuteHttpFailureOutcome {
|
|
183
185
|
const transientHttpRetrySafe = input.transientHttpRetrySafe === true;
|
|
@@ -196,15 +198,33 @@ export function classifyToolExecuteHttpFailure(input: {
|
|
|
196
198
|
maxAttempts: initialRetryDecision.attemptCap,
|
|
197
199
|
bodyText: input.bodyText,
|
|
198
200
|
});
|
|
201
|
+
if (
|
|
202
|
+
typeof input.providerLatencyMs === 'number' &&
|
|
203
|
+
Number.isFinite(input.providerLatencyMs) &&
|
|
204
|
+
input.providerLatencyMs >= 0
|
|
205
|
+
) {
|
|
206
|
+
error.message = `${error.message} (provider call ${Math.round(input.providerLatencyMs)}ms)`;
|
|
207
|
+
}
|
|
208
|
+
const hardBillingFailure = isHardBillingToolHttpError(error);
|
|
199
209
|
const retryDecision = decideToolExecuteHttpRetry({
|
|
200
210
|
status: input.status,
|
|
201
|
-
hardBillingFailure
|
|
211
|
+
hardBillingFailure,
|
|
202
212
|
hasRetryAfterHeader,
|
|
203
213
|
transientHttpRetrySafe,
|
|
204
214
|
});
|
|
205
215
|
const shouldRetry =
|
|
206
216
|
retryDecision.retryable && input.attempt < retryDecision.attemptCap;
|
|
207
|
-
|
|
217
|
+
// In-attempt retry safety and later-run repairability are different
|
|
218
|
+
// decisions. A non-idempotent 5xx must not be repeated automatically inside
|
|
219
|
+
// this execution attempt, but an explicit later `plays run` must be able to
|
|
220
|
+
// repair that failed work while completed calls remain reusable. Otherwise
|
|
221
|
+
// one provider gateway failure poisons the semantic call forever.
|
|
222
|
+
if (
|
|
223
|
+
!hardBillingFailure &&
|
|
224
|
+
(retryDecision.retryable || (input.status >= 500 && input.status < 600))
|
|
225
|
+
) {
|
|
226
|
+
error.receiptFailureKind = 'repairable';
|
|
227
|
+
}
|
|
208
228
|
const retryAfterMs = parseToolExecuteRetryAfterMs(
|
|
209
229
|
input.retryAfterHeader,
|
|
210
230
|
input.nowMs,
|
|
@@ -9,6 +9,7 @@ export type WorkReceiptStateStatus =
|
|
|
9
9
|
export type WorkReceiptStateInput = {
|
|
10
10
|
status: WorkReceiptStateStatus;
|
|
11
11
|
runId?: string | null;
|
|
12
|
+
error?: string | null;
|
|
12
13
|
failureKind?: 'terminal' | 'repairable' | null;
|
|
13
14
|
leaseId?: string | null;
|
|
14
15
|
leaseOwnerRunId?: string | null;
|
|
@@ -16,6 +17,25 @@ export type WorkReceiptStateInput = {
|
|
|
16
17
|
leaseExpiresAt?: string | null;
|
|
17
18
|
};
|
|
18
19
|
|
|
20
|
+
export function isLegacyRepairableWorkReceiptError(
|
|
21
|
+
error: string | null | undefined,
|
|
22
|
+
): boolean {
|
|
23
|
+
const message = error?.trim().toLowerCase() ?? '';
|
|
24
|
+
if (!message) return false;
|
|
25
|
+
if (
|
|
26
|
+
message.includes('billing cap') ||
|
|
27
|
+
message.includes('insufficient credits') ||
|
|
28
|
+
message.includes('monthly billing limit')
|
|
29
|
+
) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
return (
|
|
33
|
+
/(?:^|\D)5\d\d(?:\D|$)/.test(message) ||
|
|
34
|
+
message.includes('transport failed calling') ||
|
|
35
|
+
message.includes('runtime api call timed out')
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
19
39
|
export type WorkReceiptLeaseState =
|
|
20
40
|
| { kind: 'none' }
|
|
21
41
|
| {
|
|
@@ -254,7 +274,8 @@ export function decideWorkReceiptClaim(input: {
|
|
|
254
274
|
const claimantRunAttempt = normalizeAttempt(input.claimantRunAttempt);
|
|
255
275
|
const ownerAttempt = normalizeAttempt(input.receipt.leaseOwnerAttempt);
|
|
256
276
|
if (
|
|
257
|
-
input.receipt.failureKind === 'repairable'
|
|
277
|
+
(input.receipt.failureKind === 'repairable' ||
|
|
278
|
+
isLegacyRepairableWorkReceiptError(input.receipt.error)) &&
|
|
258
279
|
claimantRunId !== null &&
|
|
259
280
|
ownerRunId !== null &&
|
|
260
281
|
(claimantRunId !== ownerRunId || ownerAttempt < claimantRunAttempt)
|
|
@@ -31,7 +31,7 @@ import { buildPlayContractCompatibility } from '../contracts';
|
|
|
31
31
|
import { validatePlaySourceFilesHaveNoInlineSecrets } from '../secret-guardrails';
|
|
32
32
|
import { MAX_ESM_WORKERS_BUNDLE_BYTES, MAX_PLAY_BUNDLE_BYTES } from './limits';
|
|
33
33
|
|
|
34
|
-
const PLAY_BUNDLE_CACHE_VERSION =
|
|
34
|
+
const PLAY_BUNDLE_CACHE_VERSION = 25;
|
|
35
35
|
const PLAY_ARTIFACT_CACHE_DIR = join(
|
|
36
36
|
tmpdir(),
|
|
37
37
|
`deepline-play-artifacts-v${PLAY_BUNDLE_CACHE_VERSION}`,
|
|
@@ -1223,6 +1223,72 @@ function workersPlayEntryAliasPlugin(playFilePath: string): Plugin {
|
|
|
1223
1223
|
};
|
|
1224
1224
|
}
|
|
1225
1225
|
|
|
1226
|
+
const CUSTOMER_CONSOLE_CAPTURE_GLOBAL = '__deeplineCaptureCustomerConsole';
|
|
1227
|
+
|
|
1228
|
+
function sourceLoaderForPath(path: string): 'ts' | 'tsx' | 'js' | 'jsx' {
|
|
1229
|
+
const extension = extname(path).toLowerCase();
|
|
1230
|
+
if (extension === '.tsx') return 'tsx';
|
|
1231
|
+
if (extension === '.jsx') return 'jsx';
|
|
1232
|
+
if (extension === '.js' || extension === '.mjs' || extension === '.cjs') {
|
|
1233
|
+
return 'js';
|
|
1234
|
+
}
|
|
1235
|
+
return 'ts';
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
/**
|
|
1239
|
+
* Give the customer's entry module a lexical console without replacing the
|
|
1240
|
+
* Worker's process-wide console. Runtime diagnostics therefore keep flowing
|
|
1241
|
+
* to Cloudflare while console.* calls authored in the play join its Run Log
|
|
1242
|
+
* Stream. The lazy global lookup is required because ESM dependencies are
|
|
1243
|
+
* evaluated before the harness installs the request-scoped capture function.
|
|
1244
|
+
*/
|
|
1245
|
+
function workersCustomerConsolePlugin(
|
|
1246
|
+
customerSourceFilePaths: readonly string[],
|
|
1247
|
+
): Plugin {
|
|
1248
|
+
const customerSourceFiles = new Set(
|
|
1249
|
+
customerSourceFilePaths
|
|
1250
|
+
.filter((path) => extname(path).toLowerCase() !== '.json')
|
|
1251
|
+
.map((path) => resolve(path)),
|
|
1252
|
+
);
|
|
1253
|
+
return {
|
|
1254
|
+
name: 'deepline-workers-customer-console',
|
|
1255
|
+
setup(buildContext) {
|
|
1256
|
+
buildContext.onLoad({ filter: /./ }, (args) => {
|
|
1257
|
+
if (!customerSourceFiles.has(resolve(args.path))) return undefined;
|
|
1258
|
+
const source = readFileSync(args.path, 'utf8');
|
|
1259
|
+
const declaresOwnConsole =
|
|
1260
|
+
/(?:^|\n)\s*(?:(?:const|let|var|class|function)\s+console\b|import[^\n]*\bconsole\b)/m.test(
|
|
1261
|
+
source,
|
|
1262
|
+
);
|
|
1263
|
+
if (declaresOwnConsole) {
|
|
1264
|
+
return {
|
|
1265
|
+
contents: source,
|
|
1266
|
+
loader: sourceLoaderForPath(args.path),
|
|
1267
|
+
resolveDir: dirname(args.path),
|
|
1268
|
+
};
|
|
1269
|
+
}
|
|
1270
|
+
const prelude = `
|
|
1271
|
+
const console = new Proxy(globalThis.console, {
|
|
1272
|
+
get(target, property) {
|
|
1273
|
+
const capture = globalThis.${CUSTOMER_CONSOLE_CAPTURE_GLOBAL};
|
|
1274
|
+
if (typeof capture === 'function') {
|
|
1275
|
+
return (...args) => capture(String(property), args);
|
|
1276
|
+
}
|
|
1277
|
+
const value = Reflect.get(target, property);
|
|
1278
|
+
return typeof value === 'function' ? value.bind(target) : value;
|
|
1279
|
+
},
|
|
1280
|
+
});
|
|
1281
|
+
`;
|
|
1282
|
+
return {
|
|
1283
|
+
contents: `${prelude}\n${source}`,
|
|
1284
|
+
loader: sourceLoaderForPath(args.path),
|
|
1285
|
+
resolveDir: dirname(args.path),
|
|
1286
|
+
};
|
|
1287
|
+
});
|
|
1288
|
+
},
|
|
1289
|
+
};
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1226
1292
|
function workersNamedPlayEntryAliasPlugin(
|
|
1227
1293
|
playFilePath: string,
|
|
1228
1294
|
exportName: string,
|
|
@@ -1989,6 +2055,7 @@ type PlayArtifactTargetAdapter = {
|
|
|
1989
2055
|
includeWorkersHarnessInGraphHash: boolean;
|
|
1990
2056
|
runEsbuild(input: {
|
|
1991
2057
|
entryFile: string;
|
|
2058
|
+
customerSourceFilePaths: string[];
|
|
1992
2059
|
importedPlayDependencies: ImportedPlayDependency[];
|
|
1993
2060
|
adapter: PlayBundlingAdapter;
|
|
1994
2061
|
exportName: string;
|
|
@@ -1997,6 +2064,7 @@ type PlayArtifactTargetAdapter = {
|
|
|
1997
2064
|
|
|
1998
2065
|
async function runEsbuildForCjsNode(
|
|
1999
2066
|
entryFile: string,
|
|
2067
|
+
_customerSourceFilePaths: string[],
|
|
2000
2068
|
importedPlayDependencies: ImportedPlayDependency[],
|
|
2001
2069
|
adapter: PlayBundlingAdapter,
|
|
2002
2070
|
exportName: string,
|
|
@@ -2048,6 +2116,7 @@ async function runEsbuildForCjsNode(
|
|
|
2048
2116
|
|
|
2049
2117
|
async function runEsbuildForEsmWorkers(
|
|
2050
2118
|
playEntryFile: string,
|
|
2119
|
+
customerSourceFilePaths: string[],
|
|
2051
2120
|
importedPlayDependencies: ImportedPlayDependency[],
|
|
2052
2121
|
adapter: PlayBundlingAdapter,
|
|
2053
2122
|
exportName: string,
|
|
@@ -2058,6 +2127,9 @@ async function runEsbuildForEsmWorkers(
|
|
|
2058
2127
|
exportName === 'default'
|
|
2059
2128
|
? workersPlayEntryAliasPlugin(playEntryFile)
|
|
2060
2129
|
: workersNamedPlayEntryAliasPlugin(playEntryFile, exportName);
|
|
2130
|
+
const customerConsolePlugin = workersCustomerConsolePlugin(
|
|
2131
|
+
customerSourceFilePaths,
|
|
2132
|
+
);
|
|
2061
2133
|
const result = await build({
|
|
2062
2134
|
// Entry is the Workers harness; it imports the play via the virtual
|
|
2063
2135
|
// `deepline-play-entry` alias resolved by workersPlayEntryAliasPlugin.
|
|
@@ -2102,6 +2174,7 @@ async function runEsbuildForEsmWorkers(
|
|
|
2102
2174
|
sdkAliasPlugin,
|
|
2103
2175
|
playProxyPlugin,
|
|
2104
2176
|
playEntryAlias,
|
|
2177
|
+
customerConsolePlugin,
|
|
2105
2178
|
workersNodeBuiltinStubPlugin(),
|
|
2106
2179
|
// Strip non-English zod locale data from the bundle. zod's locales
|
|
2107
2180
|
// are re-exported as a static namespace from `zod/v4/core`, so
|
|
@@ -2136,12 +2209,14 @@ const PLAY_ARTIFACT_TARGET_ADAPTERS: Record<
|
|
|
2136
2209
|
includeWorkersHarnessInGraphHash: false,
|
|
2137
2210
|
runEsbuild: ({
|
|
2138
2211
|
entryFile,
|
|
2212
|
+
customerSourceFilePaths,
|
|
2139
2213
|
importedPlayDependencies,
|
|
2140
2214
|
adapter,
|
|
2141
2215
|
exportName,
|
|
2142
2216
|
}) =>
|
|
2143
2217
|
runEsbuildForCjsNode(
|
|
2144
2218
|
entryFile,
|
|
2219
|
+
customerSourceFilePaths,
|
|
2145
2220
|
importedPlayDependencies,
|
|
2146
2221
|
adapter,
|
|
2147
2222
|
exportName,
|
|
@@ -2153,12 +2228,14 @@ const PLAY_ARTIFACT_TARGET_ADAPTERS: Record<
|
|
|
2153
2228
|
includeWorkersHarnessInGraphHash: true,
|
|
2154
2229
|
runEsbuild: ({
|
|
2155
2230
|
entryFile,
|
|
2231
|
+
customerSourceFilePaths,
|
|
2156
2232
|
importedPlayDependencies,
|
|
2157
2233
|
adapter,
|
|
2158
2234
|
exportName,
|
|
2159
2235
|
}) =>
|
|
2160
2236
|
runEsbuildForEsmWorkers(
|
|
2161
2237
|
entryFile,
|
|
2238
|
+
customerSourceFilePaths,
|
|
2162
2239
|
importedPlayDependencies,
|
|
2163
2240
|
adapter,
|
|
2164
2241
|
exportName,
|
|
@@ -2288,6 +2365,7 @@ export async function bundlePlayFile(
|
|
|
2288
2365
|
|
|
2289
2366
|
const buildOutcome = await targetAdapter.runEsbuild({
|
|
2290
2367
|
entryFile: absolutePath,
|
|
2368
|
+
customerSourceFilePaths: analysis.importPolicy.localFiles,
|
|
2291
2369
|
importedPlayDependencies: analysis.importedPlayDependencies,
|
|
2292
2370
|
adapter,
|
|
2293
2371
|
exportName,
|
|
@@ -308,10 +308,7 @@ function truncateStaticSubstepsForStorage(
|
|
|
308
308
|
return truncateStaticSubstepShallowForStorage(base);
|
|
309
309
|
}
|
|
310
310
|
|
|
311
|
-
if (
|
|
312
|
-
base.type !== 'play_call' &&
|
|
313
|
-
'pipeline' in substepWithoutSourceText
|
|
314
|
-
) {
|
|
311
|
+
if (base.type !== 'play_call' && 'pipeline' in substepWithoutSourceText) {
|
|
315
312
|
const nestedPipeline = substepWithoutSourceText.pipeline;
|
|
316
313
|
(base as { pipeline?: PlayStaticPipeline | null }).pipeline =
|
|
317
314
|
nestedPipeline
|
|
@@ -588,6 +585,7 @@ export type PlayStaticSubstep = PlayStaticSubstepMetadata &
|
|
|
588
585
|
| {
|
|
589
586
|
type: 'play_call';
|
|
590
587
|
playId: string;
|
|
588
|
+
execution?: 'inline' | 'child-workflow';
|
|
591
589
|
field: string;
|
|
592
590
|
inLoop?: boolean;
|
|
593
591
|
pipeline?: PlayStaticPipeline | null;
|