@clipwright/core 0.61.0 → 0.62.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.
@@ -1,6 +1,33 @@
1
1
  import { z } from "zod";
2
2
  export declare const AD_GUIDE_PATH = "/v1/ad-guide";
3
+ export declare const AD_GUIDE_SECTION_IDS: readonly ["ugc", "order", "script", "product_sheet", "photo_edit", "hero", "location", "props", "states", "models", "motion_test", "shot_list", "devices", "takes", "audit", "repair", "edit", "final_check", "spend"];
4
+ export type AdGuideSectionId = (typeof AD_GUIDE_SECTION_IDS)[number];
5
+ export declare const adGuideQuery: z.ZodObject<{
6
+ section: z.ZodOptional<z.ZodEnum<{
7
+ audit: "audit";
8
+ devices: "devices";
9
+ edit: "edit";
10
+ final_check: "final_check";
11
+ hero: "hero";
12
+ location: "location";
13
+ models: "models";
14
+ motion_test: "motion_test";
15
+ order: "order";
16
+ photo_edit: "photo_edit";
17
+ product_sheet: "product_sheet";
18
+ props: "props";
19
+ repair: "repair";
20
+ script: "script";
21
+ shot_list: "shot_list";
22
+ spend: "spend";
23
+ states: "states";
24
+ takes: "takes";
25
+ ugc: "ugc";
26
+ }>>;
27
+ }, z.core.$strict>;
28
+ export type AdGuideQuery = z.infer<typeof adGuideQuery>;
3
29
  export declare const adGuide: z.ZodObject<{
4
30
  guide: z.ZodString;
31
+ version: z.ZodOptional<z.ZodString>;
5
32
  }, z.core.$strict>;
6
33
  export type AdGuide = z.infer<typeof adGuide>;
package/dist/ad-guide.js CHANGED
@@ -1,5 +1,12 @@
1
1
  import { z } from "zod";
2
2
  export const AD_GUIDE_PATH = "/v1/ad-guide";
3
+ export const AD_GUIDE_SECTION_IDS = ["ugc", "order", "script", "product_sheet", "photo_edit", "hero", "location", "props", "states", "models",
4
+ "motion_test", "shot_list", "devices", "takes", "audit", "repair", "edit", "final_check", "spend"];
5
+ export const adGuideQuery = z.strictObject({
6
+ section: z.enum(AD_GUIDE_SECTION_IDS).optional()
7
+ .describe("One part of the guide instead of all of it: ugc (the make_ugc rules) or one step of making the ad yourself"),
8
+ });
3
9
  export const adGuide = z.strictObject({
4
10
  guide: z.string().min(1).describe("The ad guide, Markdown: the word → device catalogue, the hook, poses, live shots, captions, hands and density"),
11
+ version: z.string().regex(/^[a-f0-9]{12}$/).optional().describe("The guide's version: it changes whenever any part of the guide does"),
5
12
  });
@@ -0,0 +1,3 @@
1
+ import { z } from "zod";
2
+ export declare const adId: z.ZodString;
3
+ export declare const adSlotId: z.ZodString;
package/dist/ad-ids.js ADDED
@@ -0,0 +1,4 @@
1
+ import { z } from "zod";
2
+ export const adId = z.string().regex(/^ad_[a-f0-9]{32}$/, "an ad id is ad_ and 32 hex characters").describe("An ad record of this account (create_ad)");
3
+ export const adSlotId = z.string().regex(/^[a-z0-9][a-z0-9_-]{0,23}$/, "a slot id is up to 24 lowercase letters, digits, - or _")
4
+ .describe("A slot of the ad record: one shot of the shot list, such as hook or s2");
package/dist/ads.d.ts ADDED
@@ -0,0 +1,145 @@
1
+ import { z } from "zod";
2
+ export { adId, adSlotId } from "./ad-ids.js";
3
+ export declare const ADS_PATH = "/v1/ads";
4
+ export declare const AD_PATH = "/v1/ads/:id";
5
+ export declare const DIY_RECORD_KINDS: readonly ["ad"];
6
+ export type DiyRecordKind = (typeof DIY_RECORD_KINDS)[number];
7
+ export declare const DIY_MAX_SLOTS: Readonly<Record<DiyRecordKind, number>>;
8
+ export declare const AD_MAX_SLOTS: number;
9
+ export declare const AD_RECORDS_PER_DAY = 50;
10
+ export declare const adBrief: z.ZodObject<{
11
+ product: z.ZodString;
12
+ audience: z.ZodOptional<z.ZodString>;
13
+ message: z.ZodOptional<z.ZodString>;
14
+ notes: z.ZodOptional<z.ZodString>;
15
+ }, z.core.$strict>;
16
+ export type AdBrief = z.infer<typeof adBrief>;
17
+ export declare const adSlot: z.ZodObject<{
18
+ id: z.ZodString;
19
+ shot: z.ZodString;
20
+ }, z.core.$strict>;
21
+ export type AdSlot = z.infer<typeof adSlot>;
22
+ export declare const createAdInput: z.ZodObject<{
23
+ brief: z.ZodObject<{
24
+ product: z.ZodString;
25
+ audience: z.ZodOptional<z.ZodString>;
26
+ message: z.ZodOptional<z.ZodString>;
27
+ notes: z.ZodOptional<z.ZodString>;
28
+ }, z.core.$strict>;
29
+ slots: z.ZodArray<z.ZodObject<{
30
+ id: z.ZodString;
31
+ shot: z.ZodString;
32
+ }, z.core.$strict>>;
33
+ }, z.core.$strict>;
34
+ export type CreateAdInput = z.infer<typeof createAdInput>;
35
+ export declare const updateAdInput: z.ZodObject<{
36
+ brief: z.ZodOptional<z.ZodObject<{
37
+ product: z.ZodString;
38
+ audience: z.ZodOptional<z.ZodString>;
39
+ message: z.ZodOptional<z.ZodString>;
40
+ notes: z.ZodOptional<z.ZodString>;
41
+ }, z.core.$strict>>;
42
+ slots: z.ZodOptional<z.ZodArray<z.ZodObject<{
43
+ id: z.ZodString;
44
+ shot: z.ZodString;
45
+ }, z.core.$strict>>>;
46
+ }, z.core.$strict>;
47
+ export type UpdateAdInput = z.infer<typeof updateAdInput>;
48
+ export declare const AD_SLOT_STATES: readonly ["no_take", "checking", "failed", "passed"];
49
+ export declare const adRecord: z.ZodObject<{
50
+ ad_id: z.ZodString;
51
+ brief: z.ZodObject<{
52
+ product: z.ZodString;
53
+ audience: z.ZodOptional<z.ZodString>;
54
+ message: z.ZodOptional<z.ZodString>;
55
+ notes: z.ZodOptional<z.ZodString>;
56
+ }, z.core.$strict>;
57
+ guide_version: z.ZodString;
58
+ slots: z.ZodArray<z.ZodObject<{
59
+ id: z.ZodString;
60
+ shot: z.ZodString;
61
+ state: z.ZodEnum<{
62
+ checking: "checking";
63
+ failed: "failed";
64
+ no_take: "no_take";
65
+ passed: "passed";
66
+ }>;
67
+ takes: z.ZodArray<z.ZodObject<{
68
+ run_id: z.ZodNullable<z.ZodString>;
69
+ asset_id: z.ZodNullable<z.ZodString>;
70
+ passed: z.ZodBoolean;
71
+ checks: z.ZodArray<z.ZodObject<{
72
+ run_id: z.ZodString;
73
+ state: z.ZodString;
74
+ passed: z.ZodNullable<z.ZodBoolean>;
75
+ verdict: z.ZodNullable<z.ZodObject<{
76
+ duration_sec: z.ZodNumber;
77
+ findings: z.ZodArray<z.ZodObject<{
78
+ code: z.ZodString;
79
+ level: z.ZodEnum<{
80
+ action: "action";
81
+ asset: "asset";
82
+ camera: "camera";
83
+ roll: "roll";
84
+ }>;
85
+ from: z.ZodNumber;
86
+ to: z.ZodNumber;
87
+ whole_take: z.ZodBoolean;
88
+ why: z.ZodNullable<z.ZodString>;
89
+ }, z.core.$strict>>;
90
+ clean: z.ZodArray<z.ZodObject<{
91
+ from: z.ZodNumber;
92
+ to: z.ZodNumber;
93
+ }, z.core.$strict>>;
94
+ motion: z.ZodOptional<z.ZodObject<{
95
+ subject: z.ZodNumber;
96
+ camera: z.ZodNumber;
97
+ jitter: z.ZodNumber;
98
+ format: z.ZodEnum<{
99
+ fashion: "fashion";
100
+ product: "product";
101
+ }>;
102
+ target: z.ZodObject<{
103
+ subject: z.ZodNumber;
104
+ camera: z.ZodNullable<z.ZodNumber>;
105
+ }, z.core.$strict>;
106
+ windows: z.ZodArray<z.ZodObject<{
107
+ subject: z.ZodNumber;
108
+ camera: z.ZodNumber;
109
+ jitter: z.ZodNumber;
110
+ from: z.ZodNumber;
111
+ to: z.ZodNumber;
112
+ }, z.core.$strict>>;
113
+ finding: z.ZodNullable<z.ZodString>;
114
+ shake: z.ZodNullable<z.ZodString>;
115
+ }, z.core.$strict>>;
116
+ }, z.core.$strict>>;
117
+ created_at: z.ZodString;
118
+ }, z.core.$strict>>;
119
+ }, z.core.$strict>>;
120
+ }, z.core.$strict>>;
121
+ edits: z.ZodArray<z.ZodObject<{
122
+ run_id: z.ZodString;
123
+ state: z.ZodString;
124
+ credits_charged: z.ZodNullable<z.ZodNumber>;
125
+ created_at: z.ZodString;
126
+ }, z.core.$strict>>;
127
+ next: z.ZodNullable<z.ZodObject<{
128
+ action: z.ZodString;
129
+ method: z.ZodEnum<{
130
+ GET: "GET";
131
+ POST: "POST";
132
+ }>;
133
+ path: z.ZodString;
134
+ body: z.ZodRecord<z.ZodString, z.ZodUnknown>;
135
+ add: z.ZodArray<z.ZodString>;
136
+ note: z.ZodString;
137
+ }, z.core.$strict>>;
138
+ blocked: z.ZodNullable<z.ZodObject<{
139
+ reason: z.ZodString;
140
+ unblock: z.ZodString;
141
+ }, z.core.$strict>>;
142
+ created_at: z.ZodString;
143
+ updated_at: z.ZodString;
144
+ }, z.core.$strict>;
145
+ export type AdRecord = z.infer<typeof adRecord>;
package/dist/ads.js ADDED
@@ -0,0 +1,56 @@
1
+ import { z } from "zod";
2
+ import { adId, adSlotId } from "./ad-ids.js";
3
+ import { assetId } from "./asset-identity.js";
4
+ import { diyBlocked, diyNext } from "./diy-next.js";
5
+ import { FILM_EDIT_MAX_CLIPS, takeCheckVerdict } from "./own-agent-runs.js";
6
+ import { runId } from "./runs.js";
7
+ export { adId, adSlotId } from "./ad-ids.js";
8
+ export const ADS_PATH = "/v1/ads";
9
+ export const AD_PATH = "/v1/ads/:id";
10
+ export const DIY_RECORD_KINDS = ["ad"];
11
+ export const DIY_MAX_SLOTS = { ad: FILM_EDIT_MAX_CLIPS };
12
+ export const AD_MAX_SLOTS = DIY_MAX_SLOTS.ad;
13
+ export const AD_RECORDS_PER_DAY = 50;
14
+ export const adBrief = z.strictObject({
15
+ product: z.string().trim().min(1).max(200).describe("The product the ad sells, as the buyer knows it"),
16
+ audience: z.string().trim().min(1).max(300).optional().describe("Who the ad speaks to, and whom they trust on screen"),
17
+ message: z.string().trim().min(1).max(500).optional().describe("The one benefit the ad leads with, and the objection it answers"),
18
+ notes: z.string().trim().min(1).max(2000).optional().describe("Anything else the ad must keep: facts from the product page, the reference it follows"),
19
+ });
20
+ export const adSlot = z.strictObject({
21
+ id: adSlotId,
22
+ shot: z.string().trim().min(1).max(500).describe("What the shot shows, in a line: its action and the spoken line it carries"),
23
+ });
24
+ const slots = z.array(adSlot).min(1).max(AD_MAX_SLOTS)
25
+ .refine(list => new Set(list.map(slot => slot.id)).size === list.length, "each slot id is used once")
26
+ .describe(`The shot list in cut order, 1 to ${AD_MAX_SLOTS} slots: one per shot you will make takes for`);
27
+ export const createAdInput = z.strictObject({ brief: adBrief, slots });
28
+ export const updateAdInput = z.strictObject({
29
+ brief: adBrief.optional().describe("Replaces the brief"),
30
+ slots: slots.optional().describe("Replaces the shot list; a slot that already has a checked take stays in it"),
31
+ }).refine(change => change.brief !== undefined || change.slots !== undefined, "send brief, slots or both");
32
+ export const AD_SLOT_STATES = ["no_take", "checking", "failed", "passed"];
33
+ const adCheck = z.strictObject({
34
+ run_id: runId,
35
+ state: z.string(),
36
+ passed: z.boolean().nullable(),
37
+ verdict: takeCheckVerdict.nullable(),
38
+ created_at: z.string(),
39
+ });
40
+ const adTake = z.strictObject({
41
+ run_id: runId.nullable().describe("The take's generate_video run, or null for a video asset"),
42
+ asset_id: assetId.nullable(),
43
+ passed: z.boolean(),
44
+ checks: z.array(adCheck),
45
+ });
46
+ export const adRecord = z.strictObject({
47
+ ad_id: adId,
48
+ brief: adBrief,
49
+ guide_version: z.string(),
50
+ slots: z.array(z.strictObject({ id: adSlotId, shot: z.string(), state: z.enum(AD_SLOT_STATES), takes: z.array(adTake) })),
51
+ edits: z.array(z.strictObject({ run_id: runId, state: z.string(), credits_charged: z.number().int().nonnegative().nullable(), created_at: z.string() })),
52
+ next: diyNext.nullable(),
53
+ blocked: diyBlocked.nullable(),
54
+ created_at: z.string(),
55
+ updated_at: z.string(),
56
+ });
@@ -1,4 +1,5 @@
1
1
  import { z } from "zod";
2
+ import type { DiyBlocked, DiyNext } from "./diy-next.js";
2
3
  import { workflowCommandErrorRead } from "./contracts/v1/workflow-execution.js";
3
4
  export interface RateLimitedFailure extends WorkflowDiagnostics {
4
5
  kind: "rate_limited";
@@ -102,6 +103,8 @@ export interface ClientFailure extends WorkflowDiagnostics {
102
103
  status: number;
103
104
  message: string;
104
105
  code: string | undefined;
106
+ next?: DiyNext;
107
+ blocked?: DiyBlocked;
105
108
  }
106
109
  export type ApiFailure = RateLimitedFailure | InsufficientCreditsFailure | MaxCreditsExceededFailure | DebtOutstandingFailure | NotAdmittedFailure | EditConflictFailure | RunNotEditableFailure | EditingClosedFailure | EditCeilingReachedFailure | EditInvalidFailure | WorkflowFailure | ServerFailure | ClientFailure;
107
110
  export declare function isRetryableFailure(failure: ApiFailure): boolean;
@@ -139,7 +142,10 @@ export interface AgentFailureReport {
139
142
  run_ids?: string[];
140
143
  issues?: EditIssueRead[] | WorkflowFailure["issues"];
141
144
  warnings?: string[];
145
+ next?: DiyNext;
146
+ blocked?: DiyBlocked;
142
147
  }
148
+ export declare const TAKE_UNCHECKED_NEXT_ACTION: string;
143
149
  export declare const UPLOAD_NOT_FINISHED_NEXT_ACTION: string;
144
150
  export declare const UNAUTHORIZED_NEXT_ACTION: string;
145
151
  export declare function agentFailureReport(failure: ApiFailure): AgentFailureReport;
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { accountNotAdmittedError, apiError, debtOutstandingError, editCeilingReachedError, editConflictError, editingDisabledError, editingNotPricedError, editInvalidError, insufficientCreditsError, maxCreditsExceededError, runNotEditableError, } from "./errors.js";
2
+ import { accountNotAdmittedError, apiError, debtOutstandingError, editCeilingReachedError, editConflictError, editingDisabledError, editingNotPricedError, editInvalidError, insufficientCreditsError, maxCreditsExceededError, runNotEditableError, takeUncheckedError, } from "./errors.js";
3
3
  import { PUBLIC_APP_BASE_URL } from "./public-endpoints.js";
4
4
  import { rateLimitedError } from "./rate-limit.js";
5
5
  import { workflowCommandErrorRead } from "./contracts/v1/workflow-execution.js";
@@ -215,6 +215,11 @@ export function parseApiFailure(input) {
215
215
  const { error } = workflow.data;
216
216
  return { kind: error.code, status, message: error.message, issues: error.issues, warnings: error.warnings };
217
217
  }
218
+ const unchecked = takeUncheckedError.safeParse(body);
219
+ if (unchecked.success && status === 409) {
220
+ const { error } = unchecked.data;
221
+ return { kind: "client_error", status, message: error.message, code: error.code, next: error.next, blocked: error.blocked };
222
+ }
218
223
  const generic = apiError.safeParse(body);
219
224
  const message = generic.success
220
225
  ? generic.data.error.message
@@ -252,6 +257,9 @@ function messageFromStatus(status, bodyText) {
252
257
  : `HTTP ${status}: the response body is not a Clipwright error object`;
253
258
  return tail === undefined ? head : `${head}. Body: ${tail}`;
254
259
  }
260
+ export const TAKE_UNCHECKED_NEXT_ACTION = "Do not render yet: each clip the message names was made with generate_video and has no passing check_take on its file. Quote " +
261
+ "the check in next (add direction: the shot's part of the prompt the take was made with), run check_take after the user's go-ahead, " +
262
+ "and cut only takes that pass. Nothing was charged and no run was created.";
255
263
  export const UPLOAD_NOT_FINISHED_NEXT_ACTION = "Finish the upload first: PUT the file to the put_url from create_upload with the given put_headers, confirm it " +
256
264
  "with get_upload, then repeat this call. If the message says the upload is finishing, the file is already there: " +
257
265
  "wait a few seconds and repeat. Nothing was charged and no run was created.";
@@ -424,10 +432,13 @@ export function agentFailureReport(failure) {
424
432
  status: "FAILED",
425
433
  code: failure.code ?? `http_${failure.status}`,
426
434
  retryable: false,
427
- next_action: failure.code === "upload_not_finished" ? UPLOAD_NOT_FINISHED_NEXT_ACTION :
428
- failure.code === "unauthorized" ? UNAUTHORIZED_NEXT_ACTION :
429
- "STOP. Do NOT retry: the request itself was rejected, so repeating it unchanged gives " +
430
- "the same answer. Read the message, fix the call, or tell the user what is wrong.",
435
+ ...(failure.next && { next: failure.next }),
436
+ ...(failure.blocked && { blocked: failure.blocked }),
437
+ next_action: failure.code === "take_unchecked" ? TAKE_UNCHECKED_NEXT_ACTION :
438
+ failure.code === "upload_not_finished" ? UPLOAD_NOT_FINISHED_NEXT_ACTION :
439
+ failure.code === "unauthorized" ? UNAUTHORIZED_NEXT_ACTION :
440
+ "STOP. Do NOT retry: the request itself was rejected, so repeating it unchanged gives " +
441
+ "the same answer. Read the message, fix the call, or tell the user what is wrong.",
431
442
  };
432
443
  }
433
444
  }
@@ -0,0 +1,18 @@
1
+ import { z } from "zod";
2
+ export declare const diyNext: z.ZodObject<{
3
+ action: z.ZodString;
4
+ method: z.ZodEnum<{
5
+ GET: "GET";
6
+ POST: "POST";
7
+ }>;
8
+ path: z.ZodString;
9
+ body: z.ZodRecord<z.ZodString, z.ZodUnknown>;
10
+ add: z.ZodArray<z.ZodString>;
11
+ note: z.ZodString;
12
+ }, z.core.$strict>;
13
+ export type DiyNext = z.infer<typeof diyNext>;
14
+ export declare const diyBlocked: z.ZodObject<{
15
+ reason: z.ZodString;
16
+ unblock: z.ZodString;
17
+ }, z.core.$strict>;
18
+ export type DiyBlocked = z.infer<typeof diyBlocked>;
@@ -0,0 +1,13 @@
1
+ import { z } from "zod";
2
+ export const diyNext = z.strictObject({
3
+ action: z.string().describe("The tool to call next"),
4
+ method: z.enum(["GET", "POST"]),
5
+ path: z.string().describe("Its REST route"),
6
+ body: z.record(z.string(), z.unknown()).describe("The tool's arguments, ready to send"),
7
+ add: z.array(z.string()).describe("The fields you write or change before the call; empty when the body is complete"),
8
+ note: z.string(),
9
+ });
10
+ export const diyBlocked = z.strictObject({
11
+ reason: z.string().describe("Why the ad cannot move on yet"),
12
+ unblock: z.string().describe("What unblocks it"),
13
+ });