@nodaro/shared 3.14.0 → 3.18.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/dist/index.cjs +1679 -81
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1822 -49
- package/dist/index.d.ts +1822 -49
- package/dist/index.js +1491 -82
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/apply-edl-credit-id.test.ts +25 -0
- package/src/__tests__/camera-switch-contract.test.ts +98 -0
- package/src/__tests__/competitors.test.ts +49 -0
- package/src/__tests__/content-recipe-ideas.test.ts +96 -0
- package/src/__tests__/edl-multicam.test.ts +192 -0
- package/src/__tests__/exposed-field-keys.test.ts +78 -0
- package/src/__tests__/instagram-scrape.test.ts +62 -0
- package/src/__tests__/llm-models.test.ts +5 -2
- package/src/__tests__/music-provider.test.ts +17 -0
- package/src/__tests__/node-runtime-keys.test.ts +11 -0
- package/src/__tests__/parameter-node-value.test.ts +2 -1
- package/src/__tests__/per-unit-video-pricing.test.ts +97 -0
- package/src/__tests__/producer-types.test.ts +35 -0
- package/src/__tests__/saved-posts.test.ts +37 -0
- package/src/__tests__/script-settings.test.ts +61 -0
- package/src/__tests__/settings-input.test.ts +252 -0
- package/src/__tests__/social-search.test.ts +243 -0
- package/src/__tests__/studio-sequence-owner.test.ts +356 -0
- package/src/__tests__/studio-take-voice.test.ts +200 -0
- package/src/__tests__/studio-transient.test.ts +71 -0
- package/src/__tests__/sub-gates.test.ts +21 -0
- package/src/__tests__/telegram-account-trigger.test.ts +120 -0
- package/src/__tests__/text-to-audio-pricing.test.ts +71 -0
- package/src/__tests__/tts-capabilities.test.ts +237 -0
- package/src/__tests__/video-analysis-pricing.test.ts +27 -13
- package/src/__tests__/video-link.test.ts +2 -2
- package/src/__tests__/video-utils.test.ts +89 -83
- package/src/__tests__/workflow-export-strip.test.ts +37 -0
- package/src/camera-switch-contract.ts +166 -0
- package/src/catalog-projection.ts +7 -0
- package/src/competitors.ts +430 -0
- package/src/content-recipe-ideas.ts +69 -0
- package/src/credit-estimators/index.ts +21 -0
- package/src/credit-estimators/ltx-extend.ts +33 -0
- package/src/credit-estimators/ltx-retake.ts +30 -0
- package/src/credit-estimators/text-to-audio.ts +58 -0
- package/src/credit-estimators/video-sfx.ts +41 -0
- package/src/credit-estimators/video-utils.ts +38 -24
- package/src/credit-identifiers.ts +22 -0
- package/src/edl-multicam.ts +220 -0
- package/src/exposed-field-keys.ts +49 -0
- package/src/fan-out-rows.ts +7 -2
- package/src/i18n/action-fx.ko.ts +18 -18
- package/src/i18n/action-fx.pt-BR.ts +66 -66
- package/src/i18n/aesthetic.ko.ts +49 -49
- package/src/i18n/aesthetic.pt-BR.ts +14 -14
- package/src/i18n/animals.ko.ts +126 -126
- package/src/i18n/animals.pt-BR.ts +33 -33
- package/src/i18n/atmosphere.ko.ts +37 -37
- package/src/i18n/atmosphere.pt-BR.ts +29 -29
- package/src/i18n/backdrop.ko.ts +40 -40
- package/src/i18n/backdrop.pt-BR.ts +38 -38
- package/src/i18n/camera-format.ko.ts +31 -31
- package/src/i18n/camera-format.pt-BR.ts +12 -12
- package/src/i18n/camera-motions.ko.ts +66 -66
- package/src/i18n/camera-motions.pt-BR.ts +51 -51
- package/src/i18n/character-fx.ko.ts +19 -19
- package/src/i18n/character-fx.pt-BR.ts +64 -52
- package/src/i18n/character-motion.ko.ts +164 -164
- package/src/i18n/character-motion.pt-BR.ts +867 -858
- package/src/i18n/color-look.ko.ts +41 -41
- package/src/i18n/color-look.pt-BR.ts +23 -23
- package/src/i18n/composition-effects.ko.ts +18 -18
- package/src/i18n/composition-effects.pt-BR.ts +17 -17
- package/src/i18n/era.ko.ts +28 -28
- package/src/i18n/era.pt-BR.ts +20 -20
- package/src/i18n/exposure-settings.ko.ts +20 -20
- package/src/i18n/exposure-settings.pt-BR.ts +3 -3
- package/src/i18n/framing.ko.ts +66 -66
- package/src/i18n/framing.pt-BR.ts +50 -50
- package/src/i18n/furniture.ko.ts +78 -78
- package/src/i18n/furniture.pt-BR.ts +46 -46
- package/src/i18n/held-prop.ko.ts +60 -60
- package/src/i18n/held-prop.pt-BR.ts +30 -30
- package/src/i18n/instrumentation.ko.ts +62 -62
- package/src/i18n/instrumentation.pt-BR.ts +64 -64
- package/src/i18n/lens.ko.ts +16 -16
- package/src/i18n/lens.pt-BR.ts +5 -5
- package/src/i18n/lighting.ko.ts +68 -68
- package/src/i18n/lighting.pt-BR.ts +43 -43
- package/src/i18n/loop-subject.ko.ts +1 -1
- package/src/i18n/loop-subject.pt-BR.ts +31 -31
- package/src/i18n/materials.ko.ts +66 -66
- package/src/i18n/materials.pt-BR.ts +22 -22
- package/src/i18n/mood.ko.ts +50 -50
- package/src/i18n/mood.pt-BR.ts +12 -12
- package/src/i18n/music-genre.ko.ts +28 -28
- package/src/i18n/music-genre.pt-BR.ts +50 -50
- package/src/i18n/music-mood.ko.ts +27 -27
- package/src/i18n/music-mood.pt-BR.ts +20 -20
- package/src/i18n/person.ko.ts +396 -396
- package/src/i18n/person.pt-BR.ts +237 -237
- package/src/i18n/photo-genre.ko.ts +46 -46
- package/src/i18n/photo-genre.pt-BR.ts +32 -32
- package/src/i18n/photographer.ko.ts +63 -63
- package/src/i18n/photographer.pt-BR.ts +15 -15
- package/src/i18n/pose.ko.ts +81 -81
- package/src/i18n/pose.pt-BR.ts +65 -65
- package/src/i18n/post-process-effects.ko.ts +18 -18
- package/src/i18n/post-process-effects.pt-BR.ts +18 -18
- package/src/i18n/render-quality.ko.ts +24 -24
- package/src/i18n/render-quality.pt-BR.ts +12 -12
- package/src/i18n/setting.ko.ts +64 -64
- package/src/i18n/setting.pt-BR.ts +41 -41
- package/src/i18n/style.ko.ts +49 -49
- package/src/i18n/style.pt-BR.ts +19 -19
- package/src/i18n/styling.ko.ts +265 -265
- package/src/i18n/styling.pt-BR.ts +141 -141
- package/src/i18n/temporal.ko.ts +18 -18
- package/src/i18n/temporal.pt-BR.ts +12 -12
- package/src/i18n/transitions.ko.ts +14 -14
- package/src/i18n/transitions.pt-BR.ts +83 -71
- package/src/i18n/vehicles.ko.ts +107 -107
- package/src/i18n/vehicles.pt-BR.ts +55 -55
- package/src/i18n/voice-character.ko.ts +19 -19
- package/src/i18n/voice-character.pt-BR.ts +19 -19
- package/src/i18n/voice-delivery.ko.ts +22 -22
- package/src/i18n/voice-delivery.pt-BR.ts +22 -22
- package/src/i18n/weapons.ko.ts +85 -85
- package/src/i18n/weapons.pt-BR.ts +46 -46
- package/src/index.ts +236 -1
- package/src/instagram-scrape.ts +91 -16
- package/src/llm-models.ts +11 -0
- package/src/model-catalog.ts +151 -16
- package/src/model-constants.ts +54 -16
- package/src/node-mappable-fields.ts +21 -5
- package/src/node-runtime-keys.ts +45 -0
- package/src/oauth-scopes.ts +28 -0
- package/src/parameter-node-value.ts +13 -5
- package/src/pipeline-defaults.ts +14 -0
- package/src/pipeline-state-types.ts +14 -0
- package/src/presentation-utils.ts +5 -1
- package/src/producer-types.ts +85 -0
- package/src/recast-segment-packs.ts +13 -0
- package/src/resolve-field-mappings.ts +15 -5
- package/src/saved-posts.ts +106 -0
- package/src/script-settings.ts +70 -0
- package/src/settings-input.ts +366 -0
- package/src/social-search.ts +467 -0
- package/src/studio-transient.ts +479 -7
- package/src/telegram-account-send.ts +32 -0
- package/src/telegram-account-trigger.ts +108 -0
- package/src/tts-capabilities.ts +75 -0
- package/src/video-analysis-pricing.ts +17 -6
- package/src/video-link.ts +16 -4
- package/src/workflow-export.ts +7 -0
package/src/studio-transient.ts
CHANGED
|
@@ -12,6 +12,26 @@
|
|
|
12
12
|
* of them and does not own them; all they carry across is job ids.
|
|
13
13
|
* - `freecutDraftUrl` — an unsaved editor draft.
|
|
14
14
|
*
|
|
15
|
+
* Two more things are the owner's alone though neither is transient: a
|
|
16
|
+
* scene's EMPTY media slots — unsubmitted drafts ({@link STUDIO_SHOT_DRAFT_KEYS})
|
|
17
|
+
* — and a finished take's VOICE RECORD ({@link STUDIO_TAKE_VOICE_KEYS}), which
|
|
18
|
+
* rides the canvas node's result rows rather than `settings`. The owner's own
|
|
19
|
+
* reads and exports keep both; every other reader's projection drops them, and
|
|
20
|
+
* drops them from the bin's deleted entries too.
|
|
21
|
+
*
|
|
22
|
+
* So is a LINKED (keyframe / sequence) production's owner state (T87), on the
|
|
23
|
+
* same terms: the director's sequence recommendations
|
|
24
|
+
* ({@link STUDIO_SEQUENCE_PLANNING_KEYS}), the current generation preferences
|
|
25
|
+
* ({@link STUDIO_SEQUENCE_POLICY_KEYS} — emptied, not dropped), a take's
|
|
26
|
+
* endpoint pins ({@link STUDIO_TAKE_SEQUENCE_KEYS}, on the result rows), a
|
|
27
|
+
* sequence take unit's continuation review
|
|
28
|
+
* ({@link STUDIO_SEQUENCE_UNIT_REVIEW_KEYS}), a unit result's frozen request
|
|
29
|
+
* ({@link STUDIO_SEQUENCE_UNIT_MANIFEST_KEYS}), a keyframe's in-flight runs
|
|
30
|
+
* and review record ({@link STUDIO_KEYFRAME_NODE_TRANSIENT_KEYS},
|
|
31
|
+
* {@link STUDIO_KEYFRAME_TRANSIENT_KEYS}, {@link STUDIO_KEYFRAME_REVIEW_KEYS}),
|
|
32
|
+
* and the owner's reason for waiving a keyframe's requirements, inside its
|
|
33
|
+
* acceptance ({@link STUDIO_KEYFRAME_ACCEPTANCE_PRIVATE_KEYS}).
|
|
34
|
+
*
|
|
15
35
|
* They do NOT all live at the same level, and that is the whole reason this
|
|
16
36
|
* file exists rather than one array: the writer puts `trash` and
|
|
17
37
|
* `freecutDraftUrl` on `settings.studio` itself, and puts the per-shot markers
|
|
@@ -60,6 +80,175 @@ export const STUDIO_TRANSIENT_KEYS = [
|
|
|
60
80
|
*/
|
|
61
81
|
export const STUDIO_SHOT_TRANSIENT_KEYS = ["pendingClips", "pendingClip", "pendingStills"] as const
|
|
62
82
|
|
|
83
|
+
/**
|
|
84
|
+
* ...and a SHOT entry's owner DRAFTS: the studio's empty media slots — a slot
|
|
85
|
+
* the owner opened and filled in but has not generated from yet.
|
|
86
|
+
*
|
|
87
|
+
* Not transient — the owner's own exports and copies keep them — so they are
|
|
88
|
+
* NOT on {@link STUDIO_SHOT_TRANSIENT_KEYS}. They are unsubmitted prose and
|
|
89
|
+
* reference urls the owner never generated, so no OTHER reader receives them.
|
|
90
|
+
* The studio codec keeps its own copy of these two keys for its own non-owner
|
|
91
|
+
* projection.
|
|
92
|
+
*/
|
|
93
|
+
export const STUDIO_SHOT_DRAFT_KEYS = ["stillSlots", "clipSlots"] as const
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* ...and a SHOT's 3D previsualization RUN STATE, on `shots[].previsualization`:
|
|
97
|
+
* `pendingJobs` (the scene runs in flight) and `proSubmission` (a 3D Render Pro
|
|
98
|
+
* submission's idempotency key and its exact priced body). Same reason as the
|
|
99
|
+
* per-shot markers — they name jobs on the owner's account — and a sharper one
|
|
100
|
+
* for the Pro key: carried out, it would let a replay adopt the owner's paid
|
|
101
|
+
* run. A finished render and an unadopted result (`pendingPlan`) are results,
|
|
102
|
+
* not run state, and stay.
|
|
103
|
+
*
|
|
104
|
+
* The PUBLIC share read's strip only ({@link stripStudioTransientSettings}),
|
|
105
|
+
* mirroring the studio codec's non-owner projection (`stripTransientSettings`,
|
|
106
|
+
* which drops the same two keys). A `view` read keeps them, as the codec's
|
|
107
|
+
* read-only load does ({@link stripStudioDraftSettings}).
|
|
108
|
+
*/
|
|
109
|
+
export const STUDIO_PREVIZ_RUN_STATE_KEYS = ["pendingJobs", "proSubmission"] as const
|
|
110
|
+
|
|
111
|
+
/** Everything a shot entry loses on its way to a reader who is not its owner. */
|
|
112
|
+
const STUDIO_SHOT_PRIVATE_KEYS: ReadonlyArray<string> = [...STUDIO_SHOT_TRANSIENT_KEYS, ...STUDIO_SHOT_DRAFT_KEYS]
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* ...and a finished TAKE's voice record (studio ruling T42): the plan a clip
|
|
116
|
+
* was recast with (`revoiceTo` — the owner's voice ids) and the Voice control's
|
|
117
|
+
* mode (`voiceMode`). Both live on the RESULT, so on a canvas node's
|
|
118
|
+
* `data.generatedResults` rows — never on `settings.studio.shots[]`, which is
|
|
119
|
+
* why no settings strip reaches them ({@link stripStudioTakeVoiceRecords} does).
|
|
120
|
+
*
|
|
121
|
+
* Results only: a scene recipe's `voiceMode` and a clip's `revoicedVoiceId` /
|
|
122
|
+
* `revoicedVoiceName` are not a take's record and stay. The studio codec keeps
|
|
123
|
+
* its own copy of these two keys (`READER_PRIVATE_TAKE_KEYS`) for its own
|
|
124
|
+
* non-owner projections, as it does the slot pair.
|
|
125
|
+
*/
|
|
126
|
+
export const STUDIO_TAKE_VOICE_KEYS = ["revoiceTo", "voiceMode"] as const
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* ...and a finished TAKE's SEQUENCE PINS (studio ruling T87): the exact
|
|
130
|
+
* keyframe results a linked scene's clip was generated between
|
|
131
|
+
* (`sequenceEndpoints`). Like the voice record it rides the RESULT, on a canvas
|
|
132
|
+
* node's `data.generatedResults` rows, so the same walker drops both
|
|
133
|
+
* ({@link stripStudioTakeVoiceRecords}). The in-flight marker carrying the same
|
|
134
|
+
* pins (`pendingClips[].sequenceEndpoints`) already goes whole with
|
|
135
|
+
* {@link STUDIO_SHOT_TRANSIENT_KEYS}.
|
|
136
|
+
*/
|
|
137
|
+
export const STUDIO_TAKE_SEQUENCE_KEYS = ["sequenceEndpoints"] as const
|
|
138
|
+
|
|
139
|
+
/** Everything a result row loses on its way to a reader who is not its owner. */
|
|
140
|
+
const STUDIO_TAKE_PRIVATE_KEYS: ReadonlyArray<string> = [...STUDIO_TAKE_VOICE_KEYS, ...STUDIO_TAKE_SEQUENCE_KEYS]
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* ...and a LINKED production's SEQUENCE PLANNING state on `settings.studio`
|
|
144
|
+
* itself (T87): `sequenceRecommendations`, the director's suggested generation
|
|
145
|
+
* policies for each sequence, with their reasons and provenance.
|
|
146
|
+
*
|
|
147
|
+
* The studio codec's non-owner view withholds more than the lists here carry
|
|
148
|
+
* — a take's `policy` and `compilation`, a unit's result rows (on the unit
|
|
149
|
+
* video node's `data.sequenceUnitResults`, mirrored in its `generatedResults`),
|
|
150
|
+
* a keyframe's `plan`, its `acceptance` record and all its results but the
|
|
151
|
+
* preview and the accepted one — because it builds that view AFTER reading
|
|
152
|
+
* the row. These strips drop KEYS from the stored row; they never filter rows
|
|
153
|
+
* or rewrite records, so all of it still goes out, the acceptance without its
|
|
154
|
+
* waiver reason ({@link STUDIO_KEYFRAME_ACCEPTANCE_PRIVATE_KEYS}).
|
|
155
|
+
*
|
|
156
|
+
* Part of it the codec's reader requires (0.13.0's `parseProduction`; without
|
|
157
|
+
* it every reader's load of the production fails): each take's `policy` and
|
|
158
|
+
* `compilation`; every unit result row some take selects, plus, for the take
|
|
159
|
+
* selected for export, the existing-clip opening row its policy names; a
|
|
160
|
+
* keyframe plan's `id`, `label`, `revision`, `frame` (any record, `{}`
|
|
161
|
+
* included) and `requirements` (a list, empty included); and the result its
|
|
162
|
+
* `previewResultKey` names. The rest it can do without: the unit node's
|
|
163
|
+
* mirror, the unit results no take selects, a keyframe's other results, its
|
|
164
|
+
* plan's `frame` content and `references`, and its `acceptance` — from which
|
|
165
|
+
* the non-owner view reads the accepted result. Studio ruling T94 keeps all of
|
|
166
|
+
* it visible.
|
|
167
|
+
*/
|
|
168
|
+
export const STUDIO_SEQUENCE_PLANNING_KEYS = ["sequenceRecommendations"] as const
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* ...and a sequence TAKE's per-unit review (T87), on
|
|
172
|
+
* `settings.studio.sequenceTakes[].units[]`: `continuationAcceptance` — which
|
|
173
|
+
* result the owner accepted as the next continuation's predecessor, who, when,
|
|
174
|
+
* and the review checks.
|
|
175
|
+
*/
|
|
176
|
+
export const STUDIO_SEQUENCE_UNIT_REVIEW_KEYS = ["continuationAcceptance"] as const
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* ...and a LINKED production's current GENERATION PREFERENCES on
|
|
180
|
+
* `settings.studio` (T87): `sequenceGenerationPolicies`, the policy the owner
|
|
181
|
+
* last set for each sequence — what its next take would be made with.
|
|
182
|
+
*
|
|
183
|
+
* EMPTIED, never deleted: a non-empty record goes out as `{}`. The codec's
|
|
184
|
+
* reader parses the key as a record whenever a production has takes, and
|
|
185
|
+
* reads an empty one fine. A row that does not carry the key never gains it:
|
|
186
|
+
* that reader takes the key alone for take state, and refuses it on a
|
|
187
|
+
* production that never declared takes. Each take's own `policy` — the one it
|
|
188
|
+
* was made with — stays (the reader requires it), so `{}` withholds the
|
|
189
|
+
* owner's current preference, not the takes' history.
|
|
190
|
+
*/
|
|
191
|
+
export const STUDIO_SEQUENCE_POLICY_KEYS = ["sequenceGenerationPolicies"] as const
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* ...and a sequence unit RESULT's frozen request (T87), on a unit video node's
|
|
195
|
+
* `data.sequenceUnitResults[]` rows: `requestManifest` — the submission as the
|
|
196
|
+
* host froze it, with the compiled prompts, the reference media, the endpoint
|
|
197
|
+
* pins, the take's policy and snapshots of the owner's scenes as they stood
|
|
198
|
+
* then. Optional to the codec's reader; the rest of the row stays.
|
|
199
|
+
*/
|
|
200
|
+
export const STUDIO_SEQUENCE_UNIT_MANIFEST_KEYS = ["requestManifest"] as const
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* ...and a KEYFRAME's in-flight image runs (T87, on T22's terms), which the
|
|
204
|
+
* writer keeps on the frame's image node: `data.keyframePendingImages`. Each
|
|
205
|
+
* names a job on the owner's account, with the frame it was submitted with and
|
|
206
|
+
* that submission's provenance; a reader can land none of them.
|
|
207
|
+
*/
|
|
208
|
+
export const STUDIO_KEYFRAME_NODE_TRANSIENT_KEYS = ["keyframePendingImages"] as const
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* ...and the same runs on a DELETED keyframe, where the bin keeps the whole
|
|
212
|
+
* frame (`trash[].keyframe`, `kind: "keyframe"`) and calls them `pendingImages`.
|
|
213
|
+
*/
|
|
214
|
+
export const STUDIO_KEYFRAME_TRANSIENT_KEYS = ["pendingImages"] as const
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* ...and a KEYFRAME's review record (T87): `rejections` — which of its results
|
|
218
|
+
* the owner sent back for revision, who, when and why — on each
|
|
219
|
+
* `settings.studio.keyframes[]` entry and on a deleted keyframe in the bin.
|
|
220
|
+
* Optional to the codec's reader. The frame's `acceptance` stays, without its
|
|
221
|
+
* waiver reason ({@link STUDIO_KEYFRAME_ACCEPTANCE_PRIVATE_KEYS}): every reader
|
|
222
|
+
* is shown the accepted result, and that is where the reader finds it.
|
|
223
|
+
*/
|
|
224
|
+
export const STUDIO_KEYFRAME_REVIEW_KEYS = ["rejections"] as const
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* ...and a KEYFRAME acceptance's private part (T87): `waivedReason`, the
|
|
228
|
+
* owner's own words on why the requirements they waived are acceptable. It is
|
|
229
|
+
* one level down, inside the `acceptance` record of each
|
|
230
|
+
* `settings.studio.keyframes[]` entry and of a deleted keyframe in the bin, so
|
|
231
|
+
* the walk goes into the record ({@link keyframeForReader}).
|
|
232
|
+
*
|
|
233
|
+
* Optional to the codec's reader; the rest of the record stays, the waived
|
|
234
|
+
* requirement checks included. Only the codec's resolution of an accepted
|
|
235
|
+
* frame checks the reason (`reviewValid`): in a copy made from a stripped row,
|
|
236
|
+
* a frame that waived a requirement must be accepted again before the codec
|
|
237
|
+
* resolves it for a dependent frame or a clip.
|
|
238
|
+
*/
|
|
239
|
+
export const STUDIO_KEYFRAME_ACCEPTANCE_PRIVATE_KEYS = ["waivedReason"] as const
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Everything a deleted keyframe entry loses on its way to a reader who is not
|
|
243
|
+
* its owner. Its acceptance loses {@link STUDIO_KEYFRAME_ACCEPTANCE_PRIVATE_KEYS}
|
|
244
|
+
* as well.
|
|
245
|
+
*/
|
|
246
|
+
const STUDIO_KEYFRAME_PRIVATE_KEYS: ReadonlyArray<string> = [...STUDIO_KEYFRAME_TRANSIENT_KEYS, ...STUDIO_KEYFRAME_REVIEW_KEYS]
|
|
247
|
+
|
|
248
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
249
|
+
return !!value && typeof value === "object" && !Array.isArray(value)
|
|
250
|
+
}
|
|
251
|
+
|
|
63
252
|
function withoutKeys(
|
|
64
253
|
source: Record<string, unknown>,
|
|
65
254
|
drop: ReadonlyArray<string>,
|
|
@@ -73,22 +262,41 @@ function withoutKeys(
|
|
|
73
262
|
}
|
|
74
263
|
|
|
75
264
|
/**
|
|
76
|
-
* `settings.studio.shots` with
|
|
265
|
+
* `settings.studio.shots` with the given per-shot keys removed.
|
|
77
266
|
*
|
|
78
267
|
* Returns the SAME array when no shot carried one, so an idle production's
|
|
79
268
|
* share read allocates nothing. Anything that is not a shot-shaped object rides
|
|
80
269
|
* through untouched: this runs on whatever is in the column, and a projection
|
|
81
270
|
* that threw on an unexpected row would take the share read down with it.
|
|
82
271
|
*/
|
|
83
|
-
function stripShots(value: unknown): unknown {
|
|
272
|
+
function stripShots(value: unknown, drop: ReadonlyArray<string>): unknown {
|
|
84
273
|
if (!Array.isArray(value)) return value
|
|
85
274
|
let changed = false
|
|
86
275
|
const out = value.map((entry) => {
|
|
87
276
|
if (!entry || typeof entry !== "object" || Array.isArray(entry)) return entry
|
|
88
277
|
const shot = entry as Record<string, unknown>
|
|
89
|
-
if (!
|
|
278
|
+
if (!drop.some((key) => key in shot)) return entry
|
|
90
279
|
changed = true
|
|
91
|
-
return withoutKeys(shot,
|
|
280
|
+
return withoutKeys(shot, drop)
|
|
281
|
+
})
|
|
282
|
+
return changed ? out : value
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* `settings.studio.shots` with every shot's 3D run state
|
|
287
|
+
* ({@link STUDIO_PREVIZ_RUN_STATE_KEYS}) removed from its `previsualization`.
|
|
288
|
+
* The SAME array back when no shot carried any, and anything that is not
|
|
289
|
+
* shaped like a shot with a previsualization rides through untouched.
|
|
290
|
+
*/
|
|
291
|
+
function stripPrevizRunState(value: unknown): unknown {
|
|
292
|
+
if (!Array.isArray(value)) return value
|
|
293
|
+
let changed = false
|
|
294
|
+
const out = value.map((entry) => {
|
|
295
|
+
if (!isRecord(entry)) return entry
|
|
296
|
+
const previz = entry.previsualization
|
|
297
|
+
if (!isRecord(previz) || !STUDIO_PREVIZ_RUN_STATE_KEYS.some((key) => key in previz)) return entry
|
|
298
|
+
changed = true
|
|
299
|
+
return { ...entry, previsualization: withoutKeys(previz, STUDIO_PREVIZ_RUN_STATE_KEYS) }
|
|
92
300
|
})
|
|
93
301
|
return changed ? out : value
|
|
94
302
|
}
|
|
@@ -112,13 +320,277 @@ export function stripStudioTransientSettings(settings: unknown): unknown {
|
|
|
112
320
|
|
|
113
321
|
const source = studio as Record<string, unknown>
|
|
114
322
|
const kept = withoutKeys(source, STUDIO_TRANSIENT_KEYS)
|
|
115
|
-
const shots = stripShots(source.shots)
|
|
323
|
+
const shots = stripPrevizRunState(stripShots(source.shots, STUDIO_SHOT_PRIVATE_KEYS))
|
|
116
324
|
if (source.shots !== undefined) kept.shots = shots
|
|
325
|
+
const planned = stripLinkedOwnerState(kept)
|
|
117
326
|
|
|
118
|
-
// Nothing to drop at
|
|
327
|
+
// Nothing to drop at any level — hand back the original object so an
|
|
119
328
|
// ordinary share read allocates nothing.
|
|
120
|
-
if (Object.keys(kept).length === Object.keys(source).length && shots === source.shots) {
|
|
329
|
+
if (Object.keys(kept).length === Object.keys(source).length && shots === source.shots && planned === kept) {
|
|
121
330
|
return settings
|
|
122
331
|
}
|
|
332
|
+
return { ...(settings as Record<string, unknown>), studio: planned }
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* A workflow's `nodes` without the owner's state that rides a NODE rather
|
|
337
|
+
* than `settings`: every result row's voice record
|
|
338
|
+
* ({@link STUDIO_TAKE_VOICE_KEYS}, T42) and sequence pins
|
|
339
|
+
* ({@link STUDIO_TAKE_SEQUENCE_KEYS}, T87), every sequence unit result's
|
|
340
|
+
* frozen request ({@link STUDIO_SEQUENCE_UNIT_MANIFEST_KEYS}, T87), and a
|
|
341
|
+
* keyframe image node's in-flight runs
|
|
342
|
+
* ({@link STUDIO_KEYFRAME_NODE_TRANSIENT_KEYS}, T87). Named for the first.
|
|
343
|
+
*
|
|
344
|
+
* Every node is walked, not only a clip, unit or keyframe node: the keys exist
|
|
345
|
+
* only on those, and a type list would be one more thing to keep in step.
|
|
346
|
+
* Copy-on-write, and the SAME array back when no node carries any of the keys.
|
|
347
|
+
* Anything that is not node-shaped rides through untouched: this runs on
|
|
348
|
+
* whatever is in the column.
|
|
349
|
+
*/
|
|
350
|
+
export function stripStudioTakeVoiceRecords(nodes: unknown): unknown {
|
|
351
|
+
if (!Array.isArray(nodes)) return nodes
|
|
352
|
+
let changed = false
|
|
353
|
+
const out = nodes.map((node: unknown) => {
|
|
354
|
+
const data = isRecord(node) ? node.data : undefined
|
|
355
|
+
if (!isRecord(data)) return node
|
|
356
|
+
const results = stripRows(data.generatedResults, STUDIO_TAKE_PRIVATE_KEYS)
|
|
357
|
+
const unitResults = stripRows(data.sequenceUnitResults, STUDIO_SEQUENCE_UNIT_MANIFEST_KEYS)
|
|
358
|
+
const running = STUDIO_KEYFRAME_NODE_TRANSIENT_KEYS.some((key) => key in data)
|
|
359
|
+
if (results === data.generatedResults && unitResults === data.sequenceUnitResults && !running) return node
|
|
360
|
+
changed = true
|
|
361
|
+
const kept = withoutKeys(data, STUDIO_KEYFRAME_NODE_TRANSIENT_KEYS)
|
|
362
|
+
if (results !== data.generatedResults) kept.generatedResults = results
|
|
363
|
+
if (unitResults !== data.sequenceUnitResults) kept.sequenceUnitResults = unitResults
|
|
364
|
+
return { ...(node as Record<string, unknown>), data: kept }
|
|
365
|
+
})
|
|
366
|
+
return changed ? out : nodes
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* A list of rows with the given keys off every row — a node's result rows, a
|
|
371
|
+
* unit's result rows. The SAME array back when no row carries one, and
|
|
372
|
+
* anything that is not a list, or not a row, rides through untouched.
|
|
373
|
+
*/
|
|
374
|
+
function stripRows(value: unknown, drop: ReadonlyArray<string>): unknown {
|
|
375
|
+
if (!Array.isArray(value)) return value
|
|
376
|
+
let changed = false
|
|
377
|
+
const out = value.map((row: unknown) => {
|
|
378
|
+
if (!isRecord(row) || !drop.some((key) => key in row)) return row
|
|
379
|
+
changed = true
|
|
380
|
+
return withoutKeys(row, drop)
|
|
381
|
+
})
|
|
382
|
+
return changed ? out : value
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* `settings.studio` without the linked production's owner state these lists
|
|
387
|
+
* carry (T87): its own {@link STUDIO_SEQUENCE_PLANNING_KEYS}; each
|
|
388
|
+
* {@link STUDIO_SEQUENCE_POLICY_KEYS} record EMPTIED, never dropped and never
|
|
389
|
+
* added; every sequence take's units without their
|
|
390
|
+
* {@link STUDIO_SEQUENCE_UNIT_REVIEW_KEYS}; and every keyframe entry without
|
|
391
|
+
* its {@link STUDIO_KEYFRAME_REVIEW_KEYS} or its acceptance's
|
|
392
|
+
* {@link STUDIO_KEYFRAME_ACCEPTANCE_PRIVATE_KEYS}. Every other part of a take
|
|
393
|
+
* or a frame stays, including what the codec's reader requires to read the
|
|
394
|
+
* row (which part that is: {@link STUDIO_SEQUENCE_PLANNING_KEYS}).
|
|
395
|
+
*
|
|
396
|
+
* The ONE change site for both settings strips. The SAME object back when it
|
|
397
|
+
* carries none of it, and anything that is not take- or frame-shaped rides
|
|
398
|
+
* through — a preferences value that is not a record included.
|
|
399
|
+
*/
|
|
400
|
+
function stripLinkedOwnerState(studio: Record<string, unknown>): Record<string, unknown> {
|
|
401
|
+
const takes = stripTakeUnitReviews(studio.sequenceTakes)
|
|
402
|
+
const keyframes = stripKeyframes(studio.keyframes)
|
|
403
|
+
const preferences = STUDIO_SEQUENCE_POLICY_KEYS.filter((key) => {
|
|
404
|
+
const value = studio[key]
|
|
405
|
+
return isRecord(value) && Object.keys(value).length > 0
|
|
406
|
+
})
|
|
407
|
+
if (!STUDIO_SEQUENCE_PLANNING_KEYS.some((key) => key in studio) && takes === studio.sequenceTakes
|
|
408
|
+
&& keyframes === studio.keyframes && preferences.length === 0) return studio
|
|
409
|
+
const kept = withoutKeys(studio, STUDIO_SEQUENCE_PLANNING_KEYS)
|
|
410
|
+
if (takes !== studio.sequenceTakes) kept.sequenceTakes = takes
|
|
411
|
+
if (keyframes !== studio.keyframes) kept.keyframes = keyframes
|
|
412
|
+
for (const key of preferences) kept[key] = {}
|
|
413
|
+
return kept
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/** `settings.studio.sequenceTakes` with every unit's review removed; the SAME array back when no unit carries one. */
|
|
417
|
+
function stripTakeUnitReviews(value: unknown): unknown {
|
|
418
|
+
if (!Array.isArray(value)) return value
|
|
419
|
+
let changed = false
|
|
420
|
+
const out = value.map((take: unknown) => {
|
|
421
|
+
if (!isRecord(take) || !Array.isArray(take.units)) return take
|
|
422
|
+
let touched = false
|
|
423
|
+
const units = take.units.map((unit: unknown) => {
|
|
424
|
+
if (!isRecord(unit) || !STUDIO_SEQUENCE_UNIT_REVIEW_KEYS.some((key) => key in unit)) return unit
|
|
425
|
+
touched = true
|
|
426
|
+
return withoutKeys(unit, STUDIO_SEQUENCE_UNIT_REVIEW_KEYS)
|
|
427
|
+
})
|
|
428
|
+
if (!touched) return take
|
|
429
|
+
changed = true
|
|
430
|
+
return { ...take, units }
|
|
431
|
+
})
|
|
432
|
+
return changed ? out : value
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* `settings.studio.keyframes` with every entry as {@link keyframeForReader}
|
|
437
|
+
* leaves it: no {@link STUDIO_KEYFRAME_REVIEW_KEYS}, no acceptance waiver
|
|
438
|
+
* reason. The SAME array back when no entry carries either, and anything that
|
|
439
|
+
* is not a list, or not an entry, rides through untouched.
|
|
440
|
+
*/
|
|
441
|
+
function stripKeyframes(value: unknown): unknown {
|
|
442
|
+
if (!Array.isArray(value)) return value
|
|
443
|
+
let changed = false
|
|
444
|
+
const out = value.map((frame: unknown) => {
|
|
445
|
+
if (!isRecord(frame)) return frame
|
|
446
|
+
const kept = keyframeForReader(frame, STUDIO_KEYFRAME_REVIEW_KEYS)
|
|
447
|
+
if (kept !== frame) changed = true
|
|
448
|
+
return kept
|
|
449
|
+
})
|
|
450
|
+
return changed ? out : value
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* A keyframe entry, live or deleted, without the given keys and without its
|
|
455
|
+
* acceptance's {@link STUDIO_KEYFRAME_ACCEPTANCE_PRIVATE_KEYS}; the rest of the
|
|
456
|
+
* acceptance stays. The ONE place either level is dropped, for the live
|
|
457
|
+
* entries ({@link stripKeyframes}) and the bin's ({@link binKeyframeForReader}).
|
|
458
|
+
* The SAME entry back when it carries none of it; an acceptance that is not a
|
|
459
|
+
* record rides through.
|
|
460
|
+
*/
|
|
461
|
+
function keyframeForReader(frame: Record<string, unknown>, drop: ReadonlyArray<string>): Record<string, unknown> {
|
|
462
|
+
const acceptance = frame.acceptance
|
|
463
|
+
const waived = isRecord(acceptance) && STUDIO_KEYFRAME_ACCEPTANCE_PRIVATE_KEYS.some((key) => key in acceptance)
|
|
464
|
+
if (!waived && !drop.some((key) => key in frame)) return frame
|
|
465
|
+
const kept = withoutKeys(frame, drop)
|
|
466
|
+
if (waived) kept.acceptance = withoutKeys(acceptance, STUDIO_KEYFRAME_ACCEPTANCE_PRIVATE_KEYS)
|
|
467
|
+
return kept
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* `settings` with every SHOT's owner-private state removed — its empty media
|
|
472
|
+
* slots ({@link STUDIO_SHOT_DRAFT_KEYS}) and its in-flight run markers
|
|
473
|
+
* ({@link STUDIO_SHOT_TRANSIENT_KEYS}) — and the bin kept WITHOUT the owner's
|
|
474
|
+
* drafts in it ({@link stripBin}: deleted empty slots, deleted takes' voice
|
|
475
|
+
* records) — and without a linked production's owner state
|
|
476
|
+
* ({@link stripLinkedOwnerState}, T87). The document-level markers and
|
|
477
|
+
* everything else stay.
|
|
478
|
+
*
|
|
479
|
+
* For a reader the owner let LOOK but not edit: a `view` reader's
|
|
480
|
+
* `GET /v1/workflows/:id` and `GET /v1/workflows/:id/export`, and the MCP
|
|
481
|
+
* `get_workflow_json` / `export_workflow` tools on the same access — each
|
|
482
|
+
* through {@link stripStudioDraftWorkflow}, which strips the nodes as well.
|
|
483
|
+
* The markers go with the slots because a viewer cannot land the owner's runs,
|
|
484
|
+
* and a marker for a run started from a slot carries that slot's unsent
|
|
485
|
+
* inputs. An editor keeps all of it: their editor saves `settings` back whole.
|
|
486
|
+
*
|
|
487
|
+
* The very same object back when neither a shot, the bin nor the linked
|
|
488
|
+
* owner state carries any of it.
|
|
489
|
+
*/
|
|
490
|
+
export function stripStudioDraftSettings(settings: unknown): unknown {
|
|
491
|
+
if (!settings || typeof settings !== "object") return settings
|
|
492
|
+
const studio = (settings as { studio?: unknown }).studio
|
|
493
|
+
if (!isRecord(studio)) return settings
|
|
494
|
+
const shots = stripShots(studio.shots, STUDIO_SHOT_PRIVATE_KEYS)
|
|
495
|
+
const trash = stripBin(studio.trash)
|
|
496
|
+
const planned = stripLinkedOwnerState(studio)
|
|
497
|
+
if (shots === studio.shots && trash === studio.trash && planned === studio) return settings
|
|
498
|
+
const kept: Record<string, unknown> = { ...planned }
|
|
499
|
+
if (shots !== studio.shots) kept.shots = shots
|
|
500
|
+
if (trash !== studio.trash) kept.trash = trash
|
|
123
501
|
return { ...(settings as Record<string, unknown>), studio: kept }
|
|
124
502
|
}
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* The owner's BIN (`settings.studio.trash`) as a `view` reader receives it —
|
|
506
|
+
* T11, T42 and T87 applied to what the owner deleted:
|
|
507
|
+
*
|
|
508
|
+
* - a deleted EMPTY slot (`kind: "slot"`) goes whole: it is an unsubmitted
|
|
509
|
+
* draft, prose and reference urls the owner never generated;
|
|
510
|
+
* - a deleted SCENE (`kind: "shot"`) is a one-scene production graph, so it
|
|
511
|
+
* gets what a live production gets: the owner's state off the graph's nodes
|
|
512
|
+
* (takes' records and sequence pins, unit results' frozen requests, frame
|
|
513
|
+
* runs), its slots and runs off the graph's scene entry, and its linked
|
|
514
|
+
* owner state off the graph's settings;
|
|
515
|
+
* - a deleted KEYFRAME (`kind: "keyframe"`) keeps the frame without its
|
|
516
|
+
* in-flight runs, its review record or its acceptance's waiver reason
|
|
517
|
+
* ({@link binKeyframeForReader});
|
|
518
|
+
* - any other entry — a deleted take (`kind: "clip"`, or a legacy entry with
|
|
519
|
+
* no kind, which the bin reads as a clip) — keeps its result without the
|
|
520
|
+
* voice record or the sequence pins. A deleted still carries none and rides
|
|
521
|
+
* through.
|
|
522
|
+
*
|
|
523
|
+
* Mirrors the studio codec's `withoutBinDrafts` branch for branch (that walker
|
|
524
|
+
* does not drop the T87 state yet, and lets a deleted keyframe through
|
|
525
|
+
* whole). Copy-on-write, the SAME array back when no entry carries any of it,
|
|
526
|
+
* and anything that is not an entry rides through untouched.
|
|
527
|
+
*/
|
|
528
|
+
function stripBin(trash: unknown): unknown {
|
|
529
|
+
if (!Array.isArray(trash)) return trash
|
|
530
|
+
let changed = false
|
|
531
|
+
const out: unknown[] = []
|
|
532
|
+
for (const entry of trash as unknown[]) {
|
|
533
|
+
if (isRecord(entry) && entry.kind === "slot") {
|
|
534
|
+
changed = true
|
|
535
|
+
continue
|
|
536
|
+
}
|
|
537
|
+
const kept = !isRecord(entry) ? entry
|
|
538
|
+
: entry.kind === "shot" ? binSceneForReader(entry)
|
|
539
|
+
: entry.kind === "keyframe" ? binKeyframeForReader(entry)
|
|
540
|
+
: binTakeForReader(entry)
|
|
541
|
+
if (kept !== entry) changed = true
|
|
542
|
+
out.push(kept)
|
|
543
|
+
}
|
|
544
|
+
return changed ? out : trash
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/** A deleted scene's graph through the two `view` strips. */
|
|
548
|
+
function binSceneForReader(entry: Record<string, unknown>): Record<string, unknown> {
|
|
549
|
+
const graph = entry.graph
|
|
550
|
+
if (!isRecord(graph)) return entry
|
|
551
|
+
const nodes = stripStudioTakeVoiceRecords(graph.nodes)
|
|
552
|
+
const settings = stripStudioDraftSettings(graph.settings)
|
|
553
|
+
if (nodes === graph.nodes && settings === graph.settings) return entry
|
|
554
|
+
return { ...entry, graph: { ...graph, nodes, settings } }
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/** A deleted take without its voice record or sequence pins; any other entry as it is. */
|
|
558
|
+
function binTakeForReader(entry: Record<string, unknown>): Record<string, unknown> {
|
|
559
|
+
const result = entry.result
|
|
560
|
+
if (!isRecord(result) || !STUDIO_TAKE_PRIVATE_KEYS.some((key) => key in result)) return entry
|
|
561
|
+
return { ...entry, result: withoutKeys(result, STUDIO_TAKE_PRIVATE_KEYS) }
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* A deleted keyframe without its in-flight runs or its review record
|
|
566
|
+
* ({@link STUDIO_KEYFRAME_PRIVATE_KEYS}), and without its acceptance's waiver
|
|
567
|
+
* reason ({@link keyframeForReader}); the SAME entry back when it carries none
|
|
568
|
+
* of it.
|
|
569
|
+
*/
|
|
570
|
+
function binKeyframeForReader(entry: Record<string, unknown>): Record<string, unknown> {
|
|
571
|
+
const keyframe = entry.keyframe
|
|
572
|
+
if (!isRecord(keyframe)) return entry
|
|
573
|
+
const kept = keyframeForReader(keyframe, STUDIO_KEYFRAME_PRIVATE_KEYS)
|
|
574
|
+
return kept === keyframe ? entry : { ...entry, keyframe: kept }
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* A workflow row as a reader the owner let LOOK but not edit receives it: the
|
|
579
|
+
* owner's state off its `nodes` ({@link stripStudioTakeVoiceRecords}) and the
|
|
580
|
+
* owner's drafts, runs and linked-production state off its `settings`
|
|
581
|
+
* ({@link stripStudioDraftSettings}).
|
|
582
|
+
*
|
|
583
|
+
* The ONE strip every `view` door applies, so no door can strip the settings
|
|
584
|
+
* and forget the nodes. A half the row does not carry is not added. Copy-on-
|
|
585
|
+
* write, and the very same row back when neither half changed.
|
|
586
|
+
*/
|
|
587
|
+
export function stripStudioDraftWorkflow<T extends { nodes?: unknown; settings?: unknown }>(row: T): T {
|
|
588
|
+
const nodes = "nodes" in row ? stripStudioTakeVoiceRecords(row.nodes) : row.nodes
|
|
589
|
+
const settings = "settings" in row ? stripStudioDraftSettings(row.settings) : row.settings
|
|
590
|
+
if (nodes === row.nodes && settings === row.settings) return row
|
|
591
|
+
return {
|
|
592
|
+
...row,
|
|
593
|
+
...(nodes !== row.nodes ? { nodes } : {}),
|
|
594
|
+
...(settings !== row.settings ? { settings } : {}),
|
|
595
|
+
}
|
|
596
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram Reply (`telegram-account-send`) — who writes the message and
|
|
3
|
+
* where it goes, as node data spells it. Structural vocabulary only: every
|
|
4
|
+
* destination is the run's OWNER — the chat of the post they shared, their
|
|
5
|
+
* Saved Messages, or their private chat with their own bot. How the Cloud
|
|
6
|
+
* connector sends is not part of the contract.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export const TELEGRAM_ACCOUNT_SEND_NODE_TYPE = "telegram-account-send"
|
|
10
|
+
|
|
11
|
+
/** `account`: the owner's connected account writes. `bot`: the owner's own bot writes to them privately. */
|
|
12
|
+
export const TELEGRAM_SEND_AS = ["account", "bot"] as const
|
|
13
|
+
export type TelegramSendAs = (typeof TELEGRAM_SEND_AS)[number]
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Where an account-written message goes. `reply`: under the post that started
|
|
17
|
+
* the run, in its chat (a run started by the Telegram Account Trigger only).
|
|
18
|
+
* `saved`: the owner's Saved Messages. A bot always writes to the owner's
|
|
19
|
+
* private chat with it, so it has no destination to choose.
|
|
20
|
+
*/
|
|
21
|
+
export const TELEGRAM_SEND_DESTINATIONS = ["reply", "saved"] as const
|
|
22
|
+
export type TelegramSendDestination = (typeof TELEGRAM_SEND_DESTINATIONS)[number]
|
|
23
|
+
|
|
24
|
+
/** The node's `sendAs`, as every reader reads it: anything else is the account. */
|
|
25
|
+
export function telegramSendAsOf(value: unknown): TelegramSendAs {
|
|
26
|
+
return value === "bot" ? "bot" : "account"
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The node's `destination`, as every reader reads it: anything else is a reply. */
|
|
30
|
+
export function telegramSendDestinationOf(value: unknown): TelegramSendDestination {
|
|
31
|
+
return value === "saved" ? "saved" : "reply"
|
|
32
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Telegram Account Trigger's named outputs — the wire contract between the
|
|
3
|
+
* Cloud connector that starts a run (it writes these keys into the run's
|
|
4
|
+
* trigger data) and everything that reads them: both workflow engines, the
|
|
5
|
+
* canvas card and the public node registry. A handle id IS the trigger-data
|
|
6
|
+
* key, so the two can never disagree.
|
|
7
|
+
*
|
|
8
|
+
* Structural vocabulary only: the keys and what each one carries. How the
|
|
9
|
+
* connector decides which key a post fills is not part of the contract.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** The message itself — the card's original output. */
|
|
13
|
+
export const TELEGRAM_ACCOUNT_TRIGGER_MESSAGE_HANDLE = "out"
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Named outputs, in the order the card shows them. Exactly one of `videoLink`
|
|
17
|
+
* and `postText` carries a value in a run that is about a shared post; both
|
|
18
|
+
* are empty otherwise. Never undefined — an engine reading an empty one gets
|
|
19
|
+
* "", never the message text in its place.
|
|
20
|
+
*/
|
|
21
|
+
export const TELEGRAM_ACCOUNT_TRIGGER_POST_FIELDS = [
|
|
22
|
+
/** The post's link, when the post has a video to analyze. */
|
|
23
|
+
"videoLink",
|
|
24
|
+
/** The post's words, when it has no video: the message, the link's preview, or the forwarded post. */
|
|
25
|
+
"postText",
|
|
26
|
+
/** The link of the post this run is about, whatever its kind. */
|
|
27
|
+
"postLink",
|
|
28
|
+
] as const
|
|
29
|
+
|
|
30
|
+
export type TelegramAccountTriggerPostField = (typeof TELEGRAM_ACCOUNT_TRIGGER_POST_FIELDS)[number]
|
|
31
|
+
|
|
32
|
+
/** Message facts carried alongside — read through trigger tokens and JSON-authored wires. */
|
|
33
|
+
export const TELEGRAM_ACCOUNT_TRIGGER_MESSAGE_FIELDS = [
|
|
34
|
+
"chatId",
|
|
35
|
+
"chatType",
|
|
36
|
+
"messageId",
|
|
37
|
+
"senderId",
|
|
38
|
+
] as const
|
|
39
|
+
|
|
40
|
+
/** Every handle the card renders, `out` first. */
|
|
41
|
+
export const TELEGRAM_ACCOUNT_TRIGGER_OUTPUT_HANDLES: readonly string[] = [
|
|
42
|
+
TELEGRAM_ACCOUNT_TRIGGER_MESSAGE_HANDLE,
|
|
43
|
+
...TELEGRAM_ACCOUNT_TRIGGER_POST_FIELDS,
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
const NAMED_HANDLES: ReadonlySet<string> = new Set([...TELEGRAM_ACCOUNT_TRIGGER_POST_FIELDS, ...TELEGRAM_ACCOUNT_TRIGGER_MESSAGE_FIELDS])
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* A handle naming one value of the run (a post field or a message fact) —
|
|
50
|
+
* every handle but the message itself. A wire from one carries that value,
|
|
51
|
+
* "" when the run has none, never the message in its place.
|
|
52
|
+
*/
|
|
53
|
+
export function isTelegramAccountTriggerNamedHandle(handle: unknown): handle is string {
|
|
54
|
+
return typeof handle === "string" && NAMED_HANDLES.has(handle)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* What an account trigger listens to, and whether it listens: the settings
|
|
59
|
+
* only its owner may set. One canonical string, so the editor that changed a
|
|
60
|
+
* trigger and the server that arms it compare the same thing — the server
|
|
61
|
+
* arms a trigger the owner's editor named only while the stored node still
|
|
62
|
+
* says exactly what that editor set.
|
|
63
|
+
*
|
|
64
|
+
* It states what the trigger hears, not how the node spells it: in inbox mode
|
|
65
|
+
* the owner's own messages are always heard, so `includeOutgoing` reads as on
|
|
66
|
+
* there — a setting the panel does not show in that mode never decides a match.
|
|
67
|
+
* The account id is the one exception: it is read exactly as written, because
|
|
68
|
+
* the server never listens on one that is not written exactly (padded), and
|
|
69
|
+
* the editor shows such an id as no account of the owner's.
|
|
70
|
+
*/
|
|
71
|
+
export function telegramAccountListeningSignature(data: unknown): string {
|
|
72
|
+
const d = (data !== null && typeof data === "object" ? data : {}) as Record<string, unknown>
|
|
73
|
+
const list = (value: unknown): string[] =>
|
|
74
|
+
Array.isArray(value)
|
|
75
|
+
? [...new Set(value.filter((x): x is string => typeof x === "string").map((x) => x.trim()).filter((x) => x !== ""))].sort()
|
|
76
|
+
: []
|
|
77
|
+
return JSON.stringify({
|
|
78
|
+
accountId: typeof d.accountId === "string" ? d.accountId : "",
|
|
79
|
+
chatIds: list(d.chatIds),
|
|
80
|
+
senderIds: list(d.senderIds),
|
|
81
|
+
messageTypeFilters: list(d.messageTypeFilters),
|
|
82
|
+
keywords: list(d.keywords),
|
|
83
|
+
includeOutgoing: d.inboxMode === true || d.includeOutgoing === true,
|
|
84
|
+
inboxMode: d.inboxMode === true,
|
|
85
|
+
isActive: d.isActive === true,
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function stringField(value: unknown): string {
|
|
90
|
+
if (typeof value === "string") return value.trim()
|
|
91
|
+
if (typeof value === "number" && Number.isFinite(value)) return String(value)
|
|
92
|
+
return ""
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The named outputs of one run, from its trigger data: every post field
|
|
97
|
+
* present (possibly ""), each message field only when it has a value.
|
|
98
|
+
*/
|
|
99
|
+
export function telegramAccountTriggerOutputs(triggerData: Record<string, unknown> | null | undefined): Record<string, string> {
|
|
100
|
+
const td = triggerData ?? {}
|
|
101
|
+
const out: Record<string, string> = {}
|
|
102
|
+
for (const key of TELEGRAM_ACCOUNT_TRIGGER_POST_FIELDS) out[key] = stringField(td[key])
|
|
103
|
+
for (const key of TELEGRAM_ACCOUNT_TRIGGER_MESSAGE_FIELDS) {
|
|
104
|
+
const value = stringField(td[key])
|
|
105
|
+
if (value !== "") out[key] = value
|
|
106
|
+
}
|
|
107
|
+
return out
|
|
108
|
+
}
|