@gencow/core 0.1.28 → 0.1.30
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/auth-config.d.ts +92 -5
- package/dist/config.d.ts +107 -0
- package/dist/config.js +12 -0
- package/dist/context.d.ts +139 -0
- package/dist/context.js +3 -0
- package/dist/crud.d.ts +5 -5
- package/dist/crud.js +19 -35
- package/dist/document-types.d.ts +2 -2
- package/dist/http-action.d.ts +77 -0
- package/dist/http-action.js +41 -0
- package/dist/index.d.ts +21 -5
- package/dist/index.js +12 -3
- package/dist/platform-capacity-profile.d.ts +19 -0
- package/dist/platform-capacity-profile.js +94 -0
- package/dist/procedure.d.ts +58 -0
- package/dist/procedure.js +115 -0
- package/dist/rag-schema.d.ts +449 -540
- package/dist/reactive-mutation-types.d.ts +11 -0
- package/dist/reactive-mutation-types.js +1 -0
- package/dist/reactive-mutation.d.ts +51 -0
- package/dist/reactive-mutation.js +75 -0
- package/dist/reactive-query-types.d.ts +12 -0
- package/dist/reactive-query-types.js +1 -0
- package/dist/reactive-query.d.ts +14 -0
- package/dist/reactive-query.js +28 -0
- package/dist/reactive-realtime.d.ts +48 -0
- package/dist/reactive-realtime.js +236 -0
- package/dist/reactive.d.ts +16 -5
- package/dist/reactive.js +65 -0
- package/dist/runtime-env-policy.js +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/storage-metering.d.ts +13 -0
- package/dist/storage-metering.js +18 -0
- package/dist/storage.d.ts +3 -1
- package/dist/storage.js +11 -7
- package/dist/wake-app-result.d.ts +22 -0
- package/dist/wake-app-result.js +11 -0
- package/dist/workflow-json.d.ts +2 -0
- package/dist/workflow-json.js +5 -0
- package/dist/workflow-types.d.ts +13 -1
- package/dist/workflow.d.ts +1 -1
- package/dist/workflow.js +135 -12
- package/dist/workflows-api.js +72 -3
- package/package.json +4 -1
- package/src/auth-config.ts +104 -3
- package/src/config.ts +119 -0
- package/src/context.ts +152 -0
- package/src/crud.ts +18 -35
- package/src/document-types.ts +9 -2
- package/src/http-action.ts +101 -0
- package/src/index.ts +77 -19
- package/src/platform-capacity-profile.ts +114 -0
- package/src/procedure.ts +283 -0
- package/src/reactive-mutation-types.ts +13 -0
- package/src/reactive-mutation.ts +115 -0
- package/src/reactive-query-types.ts +14 -0
- package/src/reactive-query.ts +48 -0
- package/src/reactive-realtime.ts +267 -0
- package/src/runtime-env-policy.ts +1 -1
- package/src/server.ts +6 -1
- package/src/storage-metering.ts +35 -0
- package/src/storage.ts +14 -6
- package/src/wake-app-result.ts +37 -0
- package/src/workflow-json.ts +6 -0
- package/src/workflow-types.ts +13 -1
- package/src/workflow.ts +163 -13
- package/src/workflows-api.ts +83 -3
- package/src/reactive.ts +0 -593
package/src/workflows-api.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { sql } from "drizzle-orm";
|
|
2
|
-
import {
|
|
2
|
+
import { query } from "./reactive-query.js";
|
|
3
|
+
import { mutation } from "./reactive-mutation.js";
|
|
3
4
|
import {
|
|
4
5
|
createWorkflowRealtimeToken,
|
|
5
6
|
deserializeWorkflowValue,
|
|
@@ -7,6 +8,7 @@ import {
|
|
|
7
8
|
getWorkflowRealtimeKey,
|
|
8
9
|
serializeWorkflowValue,
|
|
9
10
|
} from "./workflow.js";
|
|
11
|
+
import { workflowJsonb } from "./workflow-json.js";
|
|
10
12
|
import { GencowValidationError, v } from "./v.js";
|
|
11
13
|
import type {
|
|
12
14
|
WorkflowDerivedStatus,
|
|
@@ -31,6 +33,7 @@ type WorkflowRow = {
|
|
|
31
33
|
current_step: string | null;
|
|
32
34
|
result: unknown;
|
|
33
35
|
error: string | null;
|
|
36
|
+
error_code: string | null;
|
|
34
37
|
retry_count: number;
|
|
35
38
|
max_retries: number;
|
|
36
39
|
max_duration_ms: number;
|
|
@@ -101,6 +104,7 @@ function mapWorkflowSummary(row: WorkflowRow): WorkflowSummary {
|
|
|
101
104
|
derivedStatus: deriveWorkflowStatus(row.status, row.current_step),
|
|
102
105
|
currentStep: row.current_step,
|
|
103
106
|
error: row.error,
|
|
107
|
+
errorCode: row.error_code,
|
|
104
108
|
retryCount: row.retry_count,
|
|
105
109
|
maxRetries: row.max_retries,
|
|
106
110
|
maxDurationMs: Number(row.max_duration_ms),
|
|
@@ -198,10 +202,77 @@ async function loadWorkflowSignalTarget(
|
|
|
198
202
|
FROM _gencow_workflows
|
|
199
203
|
WHERE id = ${workflowId}
|
|
200
204
|
LIMIT 1
|
|
201
|
-
|
|
205
|
+
`);
|
|
202
206
|
return rowsFromResult<WorkflowSignalTargetRow>(result)[0] ?? null;
|
|
203
207
|
}
|
|
204
208
|
|
|
209
|
+
function isMissingWorkflowV2SignalSchemaError(error: unknown): boolean {
|
|
210
|
+
const code =
|
|
211
|
+
error && typeof error === "object" && "code" in error ? String((error as { code?: unknown }).code) : "";
|
|
212
|
+
const cause =
|
|
213
|
+
error && typeof error === "object" && "cause" in error ? (error as { cause?: unknown }).cause : null;
|
|
214
|
+
const causeCode =
|
|
215
|
+
cause && typeof cause === "object" && "code" in cause ? String((cause as { code?: unknown }).code) : "";
|
|
216
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
217
|
+
return (
|
|
218
|
+
code === "42P01" ||
|
|
219
|
+
code === "42703" ||
|
|
220
|
+
causeCode === "42P01" ||
|
|
221
|
+
causeCode === "42703" ||
|
|
222
|
+
((code === "23503" || causeCode === "23503") && message.includes("_gencow_workflow_signals_v2")) ||
|
|
223
|
+
message.includes('relation "_gencow_workflow_signals_v2" does not exist') ||
|
|
224
|
+
message.includes("relation _gencow_workflow_signals_v2 does not exist") ||
|
|
225
|
+
message.includes('relation "_gencow_workflow_runs_v2" does not exist') ||
|
|
226
|
+
message.includes("relation _gencow_workflow_runs_v2 does not exist")
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
async function tryRecordWorkflowV2Signal(options: {
|
|
231
|
+
db: WorkflowDbLike;
|
|
232
|
+
workflowId: string;
|
|
233
|
+
event: string;
|
|
234
|
+
payload: unknown;
|
|
235
|
+
}): Promise<boolean> {
|
|
236
|
+
try {
|
|
237
|
+
await options.db.execute(sql`
|
|
238
|
+
WITH inserted AS (
|
|
239
|
+
INSERT INTO _gencow_workflow_signals_v2 (
|
|
240
|
+
id,
|
|
241
|
+
run_id,
|
|
242
|
+
event_name,
|
|
243
|
+
payload_json,
|
|
244
|
+
idempotency_key
|
|
245
|
+
)
|
|
246
|
+
VALUES (
|
|
247
|
+
${crypto.randomUUID()},
|
|
248
|
+
${options.workflowId},
|
|
249
|
+
${options.event},
|
|
250
|
+
${workflowJsonb(options.payload)},
|
|
251
|
+
${crypto.randomUUID()}
|
|
252
|
+
)
|
|
253
|
+
RETURNING run_id
|
|
254
|
+
)
|
|
255
|
+
UPDATE _gencow_workflow_runs_v2 run
|
|
256
|
+
SET
|
|
257
|
+
status = 'queued',
|
|
258
|
+
runnable_at = NOW(),
|
|
259
|
+
lease_owner = NULL,
|
|
260
|
+
lease_expires_at = NULL,
|
|
261
|
+
heartbeat_at = NULL,
|
|
262
|
+
updated_at = NOW()
|
|
263
|
+
FROM inserted
|
|
264
|
+
WHERE run.id = inserted.run_id
|
|
265
|
+
AND run.status = 'waiting'
|
|
266
|
+
AND run.completed_at IS NULL
|
|
267
|
+
AND run.cancel_requested_at IS NULL
|
|
268
|
+
`);
|
|
269
|
+
return true;
|
|
270
|
+
} catch (error) {
|
|
271
|
+
if (isMissingWorkflowV2SignalSchemaError(error)) return false;
|
|
272
|
+
throw error;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
205
276
|
export async function loadWorkflowSnapshot(
|
|
206
277
|
db: WorkflowDbLike,
|
|
207
278
|
workflowId: string,
|
|
@@ -219,6 +290,7 @@ export async function loadWorkflowSnapshot(
|
|
|
219
290
|
current_step,
|
|
220
291
|
result,
|
|
221
292
|
error,
|
|
293
|
+
error_code,
|
|
222
294
|
retry_count,
|
|
223
295
|
max_retries,
|
|
224
296
|
max_duration_ms,
|
|
@@ -326,9 +398,15 @@ export function registerWorkflowsApi(): void {
|
|
|
326
398
|
${crypto.randomUUID()},
|
|
327
399
|
${workflow.id},
|
|
328
400
|
${normalizedEvent},
|
|
329
|
-
|
|
401
|
+
${workflowJsonb(persistedPayload)}
|
|
330
402
|
)
|
|
331
403
|
`);
|
|
404
|
+
await tryRecordWorkflowV2Signal({
|
|
405
|
+
db: ctx.unsafeDb,
|
|
406
|
+
workflowId: workflow.id,
|
|
407
|
+
event: normalizedEvent,
|
|
408
|
+
payload: persistedPayload,
|
|
409
|
+
});
|
|
332
410
|
|
|
333
411
|
let scheduledJobId: string | null = null;
|
|
334
412
|
if (workflow.status === "pending" && workflow.current_step?.startsWith("wait:")) {
|
|
@@ -372,6 +450,7 @@ export function registerWorkflowsApi(): void {
|
|
|
372
450
|
current_step,
|
|
373
451
|
result,
|
|
374
452
|
error,
|
|
453
|
+
error_code,
|
|
375
454
|
retry_count,
|
|
376
455
|
max_retries,
|
|
377
456
|
max_duration_ms,
|
|
@@ -393,6 +472,7 @@ export function registerWorkflowsApi(): void {
|
|
|
393
472
|
current_step,
|
|
394
473
|
result,
|
|
395
474
|
error,
|
|
475
|
+
error_code,
|
|
396
476
|
retry_count,
|
|
397
477
|
max_retries,
|
|
398
478
|
max_duration_ms,
|