@larkup/tool-video-intelligence 0.2.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.
Files changed (54) hide show
  1. package/.env.example +150 -0
  2. package/LICENSE +176 -0
  3. package/README.md +281 -0
  4. package/compose.gpu.yaml +14 -0
  5. package/compose.yaml +71 -0
  6. package/dist/agent.d.ts +131 -0
  7. package/dist/agent.js +2087 -0
  8. package/dist/brief.d.ts +2 -0
  9. package/dist/brief.js +37 -0
  10. package/dist/client.d.ts +46 -0
  11. package/dist/client.js +139 -0
  12. package/dist/contracts.d.ts +331 -0
  13. package/dist/contracts.js +1 -0
  14. package/dist/index.d.ts +87 -0
  15. package/dist/index.js +391 -0
  16. package/dist/runtime.d.ts +96 -0
  17. package/dist/runtime.js +592 -0
  18. package/dist/ui.d.ts +82 -0
  19. package/dist/ui.js +87 -0
  20. package/package.json +84 -0
  21. package/runtime/Dockerfile +119 -0
  22. package/runtime/app/__init__.py +3 -0
  23. package/runtime/app/__main__.py +19 -0
  24. package/runtime/app/api/__init__.py +0 -0
  25. package/runtime/app/api/deps.py +69 -0
  26. package/runtime/app/api/v1.py +166 -0
  27. package/runtime/app/config.py +78 -0
  28. package/runtime/app/db/__init__.py +0 -0
  29. package/runtime/app/db/schemas.py +162 -0
  30. package/runtime/app/db/store.py +466 -0
  31. package/runtime/app/main.py +27 -0
  32. package/runtime/app/model_configuration.py +157 -0
  33. package/runtime/app/services/__init__.py +0 -0
  34. package/runtime/app/services/brain.py +2221 -0
  35. package/runtime/app/services/embedding.py +473 -0
  36. package/runtime/app/services/jobs.py +237 -0
  37. package/runtime/app/services/motion.py +66 -0
  38. package/runtime/app/services/pipeline.py +1911 -0
  39. package/runtime/app/services/scene.py +161 -0
  40. package/runtime/app/services/storage.py +44 -0
  41. package/runtime/app/services/transcription.py +667 -0
  42. package/runtime/app/services/vision.py +1441 -0
  43. package/runtime/app/utils/__init__.py +0 -0
  44. package/runtime/app/utils/timing.py +99 -0
  45. package/runtime/app/worker.py +20 -0
  46. package/runtime/pyproject.toml +56 -0
  47. package/runtime/requirements-cpu.txt +15 -0
  48. package/runtime/requirements-smoke.txt +7 -0
  49. package/runtime/requirements.txt +14 -0
  50. package/runtime/uv.lock +3637 -0
  51. package/scripts/grant-cloud-credits.sh +43 -0
  52. package/scripts/runtime.mjs +156 -0
  53. package/scripts/validate-indexing.mjs +168 -0
  54. package/tool.manifest.json +617 -0
package/.env.example ADDED
@@ -0,0 +1,150 @@
1
+ # This is the one configuration file for a self-hosted Video Intelligence
2
+ # runtime and its optional GPU providers. Copy it with:
3
+ # pnpm --filter @larkup/tool-video-intelligence exec larkup-video-intelligence config init
4
+ # Then update individual values without opening an editor:
5
+ # pnpm --filter @larkup/tool-video-intelligence exec larkup-video-intelligence config set KEY VALUE
6
+
7
+ # Docker/runtime selection. Set LARKUP_VIDEO_ACCELERATOR=gpu to make the
8
+ # lifecycle command use compose.gpu.yaml; `--gpu` remains a one-off override.
9
+ LARKUP_VIDEO_IMAGE=ghcr.io/larkup-ai/video-intelligence:0.1.0
10
+ LARKUP_VIDEO_PORT=8787
11
+ LARKUP_VIDEO_ACCELERATOR=cpu
12
+ LARKUP_VIDEO_DEVICE=auto
13
+ LARKUP_VIDEO_WORKERS=1
14
+ LARKUP_VIDEO_DATA_DIR=/data
15
+ LARKUP_VIDEO_MODEL_DIR=/models
16
+ LARKUP_VIDEO_ALLOWED_ORIGINS=http://localhost:3000
17
+ LARKUP_VIDEO_MAX_UPLOAD_BYTES=21474836480
18
+ LARKUP_VIDEO_REQUESTS_PER_MINUTE=120
19
+ LARKUP_VIDEO_REQUIRE_AUTH=false
20
+ LARKUP_VIDEO_SHARED_API_KEY=
21
+ LARKUP_VIDEO_ADMIN_TOKEN=
22
+
23
+ # Vercel AI Gateway powers vision and the recommended multimodal embedding
24
+ # provider. It can route OpenAI models too, so one gateway credential is all
25
+ # this runtime needs for those model calls.
26
+ AI_GATEWAY_API_KEY=
27
+ AI_GATEWAY_BASE_URL=https://ai-gateway.vercel.sh/v1
28
+ LARKUP_VIDEO_SEMANTIC_VISION=true
29
+ LARKUP_VIDEO_SEMANTIC_VISION_MODEL=google/gemini-3.6-flash
30
+ LARKUP_VIDEO_REASONING_VISION_MODEL=google/gemini-3.6-flash
31
+ LARKUP_VIDEO_SEMANTIC_REASONING_EFFORT=minimal
32
+ # Tool-brain planner. Every runtime receives the user's selected provider,
33
+ # model, and key; managed cloud supplies GPU compute only.
34
+ LARKUP_VIDEO_AGENT_ENABLED=true
35
+ LARKUP_VIDEO_AGENT_PROVIDER=vercel_ai_gateway
36
+ LARKUP_VIDEO_AGENT_MODEL=openai/gpt-5-mini
37
+ LARKUP_VIDEO_AGENT_API_KEY=
38
+ LARKUP_VIDEO_AGENT_BASE_URL=https://ai-gateway.vercel.sh/v1
39
+ LARKUP_VIDEO_GATEWAY_BATCH_SIZE=4
40
+ LARKUP_VIDEO_GATEWAY_CONCURRENCY=24
41
+ LARKUP_VIDEO_GATEWAY_REQUESTS_PER_MINUTE=60
42
+ LARKUP_VIDEO_GOOGLE_CONCURRENCY=4
43
+ LARKUP_VIDEO_GOOGLE_MAX_IMAGES_PER_REQUEST=8
44
+ LARKUP_VIDEO_GOOGLE_REQUESTS_PER_MINUTE=12
45
+ LARKUP_VIDEO_GATEWAY_EMBEDDING_MODEL=google/gemini-embedding-2
46
+ LARKUP_VIDEO_GATEWAY_EMBEDDING_BATCH_SIZE=6
47
+ LARKUP_VIDEO_GATEWAY_EMBEDDING_CONCURRENCY=6
48
+ LARKUP_VIDEO_GATEWAY_EMBEDDING_BASE_URL=https://ai-gateway.vercel.sh/v4/ai
49
+
50
+ # User-owned hosted speech-to-text. Managed cloud never injects a provider key
51
+ # and does not fall back to a Larkup-funded local Whisper pass.
52
+ LARKUP_VIDEO_TRANSCRIPTION_PROVIDER=deepgram
53
+ LARKUP_VIDEO_TRANSCRIPTION_FALLBACK=
54
+ # Long hosted transcriptions are split once and sent in bounded parallel requests.
55
+ LARKUP_VIDEO_TRANSCRIPTION_CHUNK_SECONDS=180
56
+ LARKUP_VIDEO_TRANSCRIPTION_CONCURRENCY=3
57
+ LARKUP_VIDEO_TRANSCRIPTION_REQUEST_TIMEOUT_SECONDS=60
58
+ LARKUP_VIDEO_WHISPER_MODEL=small
59
+ DEEPGRAM_API_KEY=
60
+ LARKUP_VIDEO_DEEPGRAM_MODEL=nova-3
61
+ LARKUP_VIDEO_DEEPGRAM_AUTO_MODEL=nova-3
62
+ OPENAI_API_KEY=
63
+ LARKUP_VIDEO_OPENAI_TRANSCRIPTION_MODEL=whisper-1
64
+ GROQ_API_KEY=
65
+ LARKUP_VIDEO_GROQ_TRANSCRIPTION_MODEL=whisper-large-v3-turbo
66
+ ELEVENLABS_API_KEY=
67
+ LARKUP_VIDEO_ELEVENLABS_TRANSCRIPTION_MODEL=scribe_v2
68
+
69
+ # Cross-modal video-clip embeddings. The gateway provider is the default;
70
+ # choose one of: disabled, gateway-gemini-embedding-2, qwen3-vl-embedding,
71
+ # runpod-qwen3-vl-embedding, huggingface-qwen3-vl-embedding.
72
+ LARKUP_VIDEO_EMBEDDING_PROVIDER=gateway-gemini-embedding-2
73
+ # If the selected service is unavailable, keep RAG retrieval operational with
74
+ # the user-owned AI Gateway key. Set to disabled to require the primary only.
75
+ LARKUP_VIDEO_EMBEDDING_FALLBACK_PROVIDER=gateway-gemini-embedding-2
76
+ LARKUP_VIDEO_EMBEDDING_MODEL=qwen3-vl-embedding
77
+ LARKUP_VIDEO_EMBEDDING_DIMENSION=3072
78
+ LARKUP_VIDEO_EMBEDDING_FRAMES_PER_CLIP=4
79
+ LARKUP_VIDEO_EMBEDDING_INSTRUCTION=
80
+ DASHSCOPE_API_KEY=
81
+ DASHSCOPE_WORKSPACE_ID=
82
+ DASHSCOPE_REGION=
83
+ LARKUP_VIDEO_DASHSCOPE_BASE_URL=
84
+ RUNPOD_API_KEY=
85
+ LARKUP_VIDEO_RUNPOD_EMBEDDING_API_KEY=
86
+ LARKUP_VIDEO_RUNPOD_EMBEDDING_ENDPOINT_ID=
87
+ LARKUP_VIDEO_RUNPOD_EMBEDDING_BASE_URL=
88
+ HF_TOKEN=
89
+ LARKUP_VIDEO_HF_EMBEDDING_API_KEY=
90
+ LARKUP_VIDEO_HF_EMBEDDING_URL=
91
+
92
+ # Frame object storage. Keep local data URIs by default; S3 needs the normal
93
+ # AWS credential chain supplied by the deployment environment.
94
+ LARKUP_VIDEO_FRAME_STORAGE=local
95
+ LARKUP_VIDEO_BUCKET=
96
+ LARKUP_VIDEO_FRAME_PREFIX=tmp-frames
97
+ AWS_REGION=eu-central-1
98
+ LARKUP_VIDEO_OCR_ENGINE=RapidOCR
99
+ LARKUP_VIDEO_DISABLE_HEAVY_OPERATORS=false
100
+
101
+ # Cloud control-plane and GPU-provider settings. They are inert for local
102
+ # Docker use, but are intentionally kept here so a deployment has no second
103
+ # hidden env file.
104
+ LARKUP_VIDEO_GPU_PROVIDER=modal
105
+ LARKUP_VIDEO_GPU_TYPE=
106
+ RUNPOD_ENDPOINT_ID=
107
+ RUNPOD_REGISTRY_AUTH_ID=
108
+ MODAL_TOKEN_ID=
109
+ MODAL_TOKEN_SECRET=
110
+ MODAL_API_KEY=
111
+ LARKUP_VIDEO_MODAL_APP=larkup-video-intelligence
112
+ LARKUP_VIDEO_MODAL_FUNCTION=process_video_job
113
+ GPUAI_API_KEY=
114
+ HYPERSTACK_API_KEY=
115
+ HYPERSTACK_ENVIRONMENT_NAME=
116
+ HYPERSTACK_KEY_NAME=
117
+ NORTHFLANK_API_KEY=
118
+ NORTHFLANK_PROJECT_ID=
119
+ NORTHFLANK_DEPLOYMENT_PLAN=
120
+ NORTHFLANK_IMAGE_CREDENTIALS_ID=
121
+ SALAD_API_KEY=
122
+ SALAD_ORGANIZATION_NAME=
123
+ SALAD_PROJECT_NAME=
124
+ SCALEAWAY_ACCESS_KEY_ID=
125
+ SCALEAWAY_API_KEY=
126
+ SCALEAWAY_DEFAULT_ZONE=
127
+ SCALEAWAY_GPU_IMAGE_ID=
128
+ SCALEAWAY_PROJECT_ID=
129
+ SHADE_FORM_API_KEY=
130
+ THUNDERCOMPUTE_API_KEY=
131
+ VAST_API_KEY=
132
+
133
+ # AWS control-plane policy and webhook configuration.
134
+ ADMIN_TOKEN=
135
+ WEBHOOK_SIGNING_SECRET=
136
+ MAX_UPLOAD_BYTES=21474836480
137
+ REQUESTS_PER_MINUTE=120
138
+ PROCESSING_ENABLED=false
139
+ AUTO_PROVISIONING_ENABLED=false
140
+ # The first 100 new device IDs receive a 600-minute (10-hour) monthly cloud
141
+ # allowance. No payment provider is involved; later devices can request support access.
142
+ TRIAL_DEVICE_LIMIT=100
143
+ TRIAL_SOURCE_MINUTES=600
144
+ TRIAL_REQUESTS_PER_MINUTE=60
145
+ POST_TRIAL_SOURCE_MINUTES=0
146
+ # Backward-compatible allowance for cloud device records created before the
147
+ # bounded trial policy. New devices use the TRIAL_* values above.
148
+ AUTO_PROVISIONED_SOURCE_MINUTES=30
149
+ STALE_JOB_TIMEOUT_HOURS=6
150
+ TESTING_DEVICE_HASHES=
package/LICENSE ADDED
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
package/README.md ADDED
@@ -0,0 +1,281 @@
1
+ # Larkup Video Intelligence
2
+
3
+ An installable Marketplace v3 tool with a cloud-first Larkup Cloud connection. On first use, the app creates an opaque, device-scoped key automatically; administrators may also provide a replacement key in Installed Tools. The AWS GPU endpoint and raw key are never shown in the connection status. PyAV/FFmpeg, faster-whisper, RapidOCR/PaddleOCR, YOLOX, ONNX Runtime, and anonymous tracking are isolated in runtime images.
4
+
5
+ The evidence pipeline is genre-neutral. Planning is driven by the user's goal,
6
+ question shape, source duration, and measured visual/audio signals—not a fixed
7
+ branch for sports, lectures, entertainment, films, meetings, or any other
8
+ content type. Direct visual claims preserve generic `subject`, `relation`, and
9
+ `value` bindings so the same corroboration logic works across every genre.
10
+
11
+ ## Where things live
12
+
13
+ ```
14
+ runtime/app/
15
+ main.py FastAPI app + CORS + exception handlers, mounts the v1 router
16
+ config.py Settings -- the one place env vars are read
17
+ api/
18
+ v1.py every /v1 route (health, uploads, jobs, usage, access codes)
19
+ deps.py auth/rate-limit dependencies, and the settings/store/jobs singletons
20
+ services/
21
+ brain.py bounded agent planner: chooses modalities, density, segments, and extraction focus
22
+ pipeline.py shared cloud/local executor: scout -> plan -> parallel evidence extraction -> synthesis
23
+ transcription.py TranscriptionService: WhisperProvider (local) / DeepgramProvider (hosted)
24
+ vision.py SemanticVisionService: per-clip captioning via the Vercel AI Gateway
25
+ embedding.py VideoEmbeddingService: cross-modal clip search via DashScope (Qwen3-VL-Embedding)
26
+ scene.py SceneDetector: scene-cut + fixed-window clip planning
27
+ motion.py MotionSampler: adaptive frame selection within a clip
28
+ storage.py pluggable frame-upload interface (S3 today; not hardcoded to it)
29
+ jobs.py JobService: runs a queued job in a background thread (local-Docker path only)
30
+ db/
31
+ store.py SQLite-backed principals/keys/uploads/jobs
32
+ schemas.py pydantic request/response models
33
+ utils/
34
+ timing.py range clamping/merging, sampling cadence, timestamp rebasing
35
+ worker.py local-Docker CLI entrypoint (`python -m app.worker <job_id>`)
36
+ ```
37
+
38
+ `deploy/` is the operator/infrastructure side for Larkup's managed cloud offering: the AWS control plane (Lambda + API Gateway + DynamoDB + S3) and GPU provider dispatch/worker entrypoints (RunPod, Modal, and other vendors behind one interface). It is gitignored and not part of this public checkout -- kept fully separate from `runtime/app` so a self-hosted Docker/local install never depends on it. If you operate the managed cloud stack, see `deploy/README.md` in your private checkout for testing, validation, and deploy commands.
39
+
40
+ ## Local run
41
+
42
+ Requirements: Docker Desktop or Docker Engine with Compose v2. NVIDIA acceleration additionally requires the NVIDIA Container Toolkit.
43
+
44
+ ```bash
45
+ pnpm --filter @larkup/tool-video-intelligence runtime:start
46
+ # NVIDIA GPU (CUDA + PaddleOCR):
47
+ pnpm --filter @larkup/tool-video-intelligence runtime:start -- --gpu
48
+ curl http://127.0.0.1:8787/v1/health
49
+ ```
50
+
51
+ Published-package users run the same lifecycle command:
52
+
53
+ ```bash
54
+ npx @larkup/tool-video-intelligence start
55
+ ```
56
+
57
+ The local default builds the cross-platform CPU target with RapidOCR, binds only port `8787`, does not require an account, and keeps sources/state in Docker volumes. The GPU override uses the CUDA target with PaddleOCR. Set `LARKUP_VIDEO_REQUIRE_AUTH=true` and `LARKUP_VIDEO_ADMIN_TOKEN` when exposing a self-hosted endpoint. Do not expose the unauthenticated local configuration to a public network.
58
+
59
+ ### Runtime configuration
60
+
61
+ The package-level [`.env.example`](./.env.example) is the single configuration
62
+ surface for local Docker plus optional cloud GPU providers. It is passed into
63
+ Compose as the container environment, so a value changed there takes effect on
64
+ the next runtime restart. Never commit the generated `.env`.
65
+
66
+ ```bash
67
+ # Create packages/marketplace-tools/video-intelligence/.env once.
68
+ pnpm --filter @larkup/tool-video-intelligence exec larkup-video-intelligence config init
69
+
70
+ # Update a credential, request rate, or GPU selection.
71
+ pnpm --filter @larkup/tool-video-intelligence exec larkup-video-intelligence config set AI_GATEWAY_API_KEY ...
72
+ pnpm --filter @larkup/tool-video-intelligence exec larkup-video-intelligence config set LARKUP_VIDEO_REQUESTS_PER_MINUTE 240
73
+ pnpm --filter @larkup/tool-video-intelligence exec larkup-video-intelligence config set LARKUP_VIDEO_ACCELERATOR gpu
74
+ pnpm --filter @larkup/tool-video-intelligence runtime:start
75
+ ```
76
+
77
+ `config get KEY` reads a configured value and `config path` prints the exact
78
+ file location. The CLI only accepts documented keys from `.env.example`, which
79
+ prevents a misspelled credential or GPU variable from silently doing nothing.
80
+
81
+ ### Runtime choices in Larkup
82
+
83
+ The installed-tool settings card is driven by this tool's manifest and offers
84
+ three compatible runtimes:
85
+
86
+ - **Larkup Cloud** is the default. Paste a Larkup Cloud API key in Installed
87
+ Tools when your organization issues keys manually, or leave it empty when
88
+ automatic project provisioning is enabled. The same card has **Request
89
+ Larkup Cloud API key** for requesting access; monthly usage is shown only
90
+ for this metered mode.
91
+ - **Local runtime** detects Docker and uses it when available; otherwise it
92
+ installs and runs the native CPU runtime with `uv`. The card shows the
93
+ chosen engine, host suitability, install state, and explicit Install,
94
+ Start, and Stop controls. It generates a shared API key and lets you replace
95
+ `127.0.0.1` with a private LAN URL for trusted users.
96
+ - **Custom runtime** accepts a compatible `/v1` endpoint and bearer key. Use
97
+ the built-in Verify action before indexing through a self-hosted provider.
98
+
99
+ Every runtime requires an audio provider key plus agent/tool-brain and vision
100
+ credentials. The audio model is selected automatically for the provider. Agent
101
+ and vision controls start with the provider, model, and key saved under **AI
102
+ Models**, and each can be overridden independently in the tool settings. A
103
+ text-only provider such as DeepSeek can remain the agent while vision uses a
104
+ separate provider. Local mode injects these settings only into the local
105
+ process/container. Managed Cloud forwards them only in the active GPU job and
106
+ never stores them in DynamoDB or S3. Larkup Cloud supplies compute, not model
107
+ credits. The agent/tool-brain model may differ from the vision model.
108
+
109
+ For a Docker-free portable runtime, use the `uv` package in `runtime/`:
110
+
111
+ ```bash
112
+ # Install uv once: https://docs.astral.sh/uv/
113
+ npx @larkup/tool-video-intelligence native
114
+ ```
115
+
116
+ The Installed Tools card exposes this automatically selected native path as
117
+ part of **Local runtime**. It creates `./.larkup/video-intelligence/` for
118
+ state and downloaded models, binds to
119
+ `127.0.0.1` by default, and uses the same `/v1` API and SQLite-backed worker
120
+ queue as Docker. To use a LAN URL, set the card's local URL to an address on
121
+ the host and keep the generated key private. Configure optional AI/provider
122
+ credentials with `larkup-video-intelligence config set …` before starting.
123
+
124
+ ## Indexing contract
125
+
126
+ 1. Upload to `POST /v1/uploads`.
127
+ 2. Submit `POST /v1/jobs` with a typed indexing brief.
128
+ 3. Poll `GET /v1/jobs/{id}`.
129
+ 4. Index the returned timestamped transcript, OCR, object tracks, and answering guide.
130
+
131
+ The only indexing modes are `fast`, `balanced`, and `thorough`. They are bounded
132
+ latency/recall budgets, not fixed pipelines. A first planning call chooses useful
133
+ modalities, a model-free scout collects sparse chronological motion and optional
134
+ OCR signals while transcription runs in parallel, and a second planning call
135
+ chooses the final whole-source cadence plus denser source-supported priority
136
+ ranges. Every proposed number is clamped by the executor. The same Python
137
+ implementation runs locally and in managed cloud.
138
+
139
+ Progress reports measured frame/clip counters, never moves backwards, and adds a
140
+ remaining-time estimate calculated from the actual plan. Results include the
141
+ plan, model-call diagnostics, elapsed time, estimate error, and timestamped
142
+ evidence so a caller can audit both speed and extraction quality.
143
+
144
+ For managed cloud jobs, the Data-library asset is the canonical copy. A short-lived, KMS-encrypted processing copy is created only so the GPU worker can decode it; it is deleted when the job settles, including failed and cancelled jobs. Once the app has downloaded the evidence, it acknowledges the result and the cloud result object is deleted too. S3 lifecycle rules remove any abandoned processing source or result within one day as a safety bound.
145
+
146
+ For a complex chat question, the agent first searches active timestamped evidence. If it is incomplete, it may request one authorized, bounded cloud re-analysis (maximum 30 seconds per request) to add fresh OCR, visual detections, or anonymous tracks, then searches the resulting evidence again. This avoids treating RAG snippets as the final answer. The worker seeks directly to the approved range for model inference; source transfer and scale-to-zero GPU startup can still add latency for large videos.
147
+
148
+ ### Answer memory and corrections
149
+
150
+ Chat keeps a durable answer memory for exact repeated video questions. A result
151
+ is saved only after the active source evidence supports it, and is scoped to
152
+ that video's active knowledge revision. Reindexing or a bounded inspection
153
+ creates a new revision, so an older cached answer is never reused against new
154
+ evidence.
155
+
156
+ Unsupported answers are not cached. If the same unanswered question is asked
157
+ again, the app records the repeat and may perform a bounded reinspection of
158
+ the best candidate range instead of returning the earlier "unknown" result.
159
+
160
+ When a user explicitly corrects a video answer in chat, the assistant saves
161
+ that correction as an opt-in, user-confirmed answer for exact repeats. It is
162
+ kept separate from source evidence: it can make the next identical question
163
+ fast, but it never rewrites the indexed transcript, OCR, or visual evidence
164
+ and does not manufacture a citation.
165
+
166
+ ## Managed-cloud entitlement
167
+
168
+ The runtime does not know about Stripe or another payment provider. API keys carry a provider-neutral entitlement:
169
+
170
+ ```json
171
+ {
172
+ "plan": "access-code",
173
+ "sourceMinutesPerMonth": 600,
174
+ "maxConcurrentJobs": 2
175
+ }
176
+ ```
177
+
178
+ Monthly source-minute reservations and concurrency updates are atomic. A future subscription webhook only needs to create/update this entitlement; video processing does not change.
179
+
180
+ The dashboard warns at 80% usage and can send a temporary capacity request through Resend. Configure these server-only environment variables in `apps/web` to enable delivery:
181
+
182
+ ```bash
183
+ RESEND_API_KEY=...
184
+ LARKUP_USAGE_REQUEST_FROM='Larkup <usage@example.com>'
185
+ LARKUP_USAGE_REQUEST_TO='support@example.com'
186
+ ```
187
+
188
+ For managed jobs, the audio, brain, and vision credentials travel through the authenticated control plane only as a transient worker payload. They are not included in the persisted job item or result, and the worker restores a clean environment after completion. Provider failures do not fall back to a Larkup-funded model.
189
+
190
+ For a controlled pilot, set `AutoProvisioningEnabled=true`. The first `TrialDeviceLimit` new device IDs (100 by default) receive `TrialSourceMinutes` (600 minutes, or 10 hours, by default) each month; later devices receive `PostTrialSourceMinutes` (0 by default) and can use the dashboard's support request instead. This is an allowance and rate-limit system only—there is no customer-facing price or payment flow.
191
+
192
+ The support team can update a device's allowance, concurrency, or per-minute request limit without seeing its API key:
193
+
194
+ ```bash
195
+ curl -X POST "$VIDEO_ENDPOINT/v1/admin/devices/$USER_ID/entitlement" \
196
+ -H "Content-Type: application/json" \
197
+ -H "X-Larkup-Admin-Token: $VIDEO_ADMIN_TOKEN" \
198
+ -d '{"sourceMinutesPerMonth":60,"maxConcurrentJobs":1,"requestsPerMinute":60,"plan":"support-grant"}'
199
+ ```
200
+
201
+ For the common “add credits” workflow, use the support script. It calls the
202
+ authenticated control plane, which updates the DynamoDB device entitlement and
203
+ reconciles the current billing-period allowance atomically; it does not write
204
+ to a Neon database. The minutes value is the new total monthly allowance, not
205
+ an increment.
206
+
207
+ ```bash
208
+ export LARKUP_VIDEO_INTELLIGENCE_CLOUD_ENDPOINT='https://video.example.com'
209
+ export LARKUP_VIDEO_ADMIN_TOKEN='...'
210
+ bash scripts/grant-cloud-credits.sh <user-id> 120 support-grant
211
+ ```
212
+
213
+ `$USER_ID` is the generated ID shown in Installed Tools and included in the Resend support request. Each local Larkup installation receives a separate key, while DynamoDB stores only hashes of keys and installation identifiers plus aggregate usage.
214
+
215
+ Access codes remain available for support-issued or upgraded plans:
216
+
217
+ ```bash
218
+ curl -X POST "$VIDEO_ENDPOINT/v1/admin/access-codes" \
219
+ -H "Content-Type: application/json" \
220
+ -H "X-Larkup-Admin-Token: $VIDEO_ADMIN_TOKEN" \
221
+ -d '{"label":"pilot","sourceMinutesPerMonth":600,"maxConcurrentJobs":2,"maxUses":1}'
222
+ ```
223
+
224
+ Only hashes of access codes, API keys, and installation identifiers are stored. The raw device key is saved only in the local project's configuration so it can authenticate future cloud jobs.
225
+
226
+ ## AWS deployment
227
+
228
+ The production stack -- API Gateway + Lambda control plane, DynamoDB, S3 + KMS, and GPU dispatch through Modal/RunPod -- is real-deployed and smoke-tested end to end (control plane → GPU worker → S3 → job completion). Its source lives in the private, gitignored `deploy/` directory described above, not in this public checkout. `ProcessingEnabled` defaults to `false` -- a stack accepts no real jobs until explicitly turned on.
229
+
230
+ See `deploy/README.md` in a private checkout for the build/deploy, bootstrap, and RunPod image publish commands. Do not send a long-lived AWS secret through chat or store it in GitHub; a short AWS SSO session is sufficient for bootstrap, with GitHub assuming a narrow OIDC deployment role afterward.
231
+
232
+ ### Operator-level env vars
233
+
234
+ These are self-hosted worker/service variables. Managed Cloud receives the corresponding user values per job and has no platform-owned model-provider secrets (see `tool.manifest.json`'s `configSchema`):
235
+
236
+ | Var | Default | Purpose |
237
+ | ---------------------------------------------------- | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
238
+ | `LARKUP_VIDEO_VISION_PROVIDER` | `vercel_ai_gateway` | `vercel_ai_gateway`, `google`, or `openai`; defaults from AI Models and can be overridden per tool. |
239
+ | `LARKUP_VIDEO_VISION_API_KEY` | unset | User-owned selected provider key, supplied from AI Models or a per-tool override. |
240
+ | `LARKUP_VIDEO_SEMANTIC_VISION_MODEL` | `google/gemini-3.6-flash` | Bulk per-clip captioning model. Gemini is called through Google's native API when `LARKUP_VIDEO_VISION_PROVIDER=google`. |
241
+ | `LARKUP_VIDEO_AGENT_PROVIDER` | `vercel_ai_gateway` | Defaults from the AI Models chat provider and can be overridden per tool; supports Gateway, Google, OpenAI, DeepSeek, Mistral, Cohere, and Anthropic. |
242
+ | `LARKUP_VIDEO_AGENT_API_KEY` | unset | User-owned agent provider credential. |
243
+ | `LARKUP_VIDEO_AGENT_MODEL` | `openai/gpt-5-mini` | Tool-brain model that chooses modalities, sampling density, priority ranges, and extraction focus. |
244
+ | `LARKUP_VIDEO_GOOGLE_CONCURRENCY` | `4` | Maximum simultaneous native Gemini vision batches. Kept below Gateway concurrency to avoid direct-project burst limits. |
245
+ | `LARKUP_VIDEO_GOOGLE_MAX_IMAGES_PER_REQUEST` | `8` | Bounds native Gemini request size so multi-clip structured responses remain within interactive provider timeouts. |
246
+ | `LARKUP_VIDEO_GOOGLE_REQUESTS_PER_MINUTE` | `12` | Sliding-window request limit for native Gemini vision calls, leaving quota headroom for the agent model. |
247
+ | `LARKUP_VIDEO_REASONING_VISION_MODEL` | `google/gemini-3.6-flash` | Dense final-verification model for bounded source inspection. |
248
+ | `LARKUP_VIDEO_TRANSCRIPTION_PROVIDER` | unset | User-selected timestamped speech provider: `deepgram`, `openai`, `groq`, or `elevenlabs`. |
249
+ | `LARKUP_VIDEO_TRANSCRIPTION_FALLBACK` | unset | Managed Cloud keeps this empty so it never falls back to Larkup-funded inference. |
250
+ | `LARKUP_VIDEO_TRANSCRIPTION_CHUNK_SECONDS` | `180` | Audio window used for long hosted transcriptions. Windows keep request sizes bounded and are merged back onto the original source clock. |
251
+ | `LARKUP_VIDEO_TRANSCRIPTION_REQUEST_TIMEOUT_SECONDS` | `60` | Maximum wait for one hosted speech request before the configured fallback takes over, preventing a stalled provider from holding the progress UX for minutes. |
252
+ | `LARKUP_VIDEO_DEEPGRAM_AUTO_MODEL` | `nova-3` | User-selected Deepgram model used when the source language is unknown. |
253
+ | `LARKUP_VIDEO_TRANSCRIPTION_CONCURRENCY` | `3` | Maximum parallel hosted speech windows. The runtime keeps the merged transcript chronological even when requests finish out of order. |
254
+ | `LARKUP_VIDEO_GPU_PROVIDER` | `modal` | `modal` or `runpod`; the managed-cloud GPU dispatch registry, private (see `deploy/README.md`). |
255
+ | `LARKUP_VIDEO_EMBEDDING_PROVIDER` | `gateway-gemini-embedding-2` | `gateway-gemini-embedding-2` uses the configured AI Gateway key and Gemini's multimodal vector space for image-frame/text retrieval. `disabled`, DashScope `qwen3-vl-embedding`, `runpod-qwen3-vl-embedding`, and `huggingface-qwen3-vl-embedding` remain available. Live bounded answer verification skips embeddings entirely because vectors are not needed to return timestamped answer evidence. |
256
+ | `LARKUP_VIDEO_EMBEDDING_FALLBACK_PROVIDER` | `gateway-gemini-embedding-2` | Provider used automatically when the selected visual embedding service is unavailable. Set `disabled` to require the primary provider only. |
257
+ | `DASHSCOPE_API_KEY` | unset | Required when `LARKUP_VIDEO_EMBEDDING_PROVIDER=qwen3-vl-embedding`. |
258
+ | `DASHSCOPE_WORKSPACE_ID` | unset | From the Model Studio console's Workspace Details page. Required when `LARKUP_VIDEO_EMBEDDING_PROVIDER=qwen3-vl-embedding`. |
259
+ | `DASHSCOPE_REGION` | unset | The workspace's region, e.g. `eu-central-1` (same console page). Required when `LARKUP_VIDEO_EMBEDDING_PROVIDER=qwen3-vl-embedding`. |
260
+ | `LARKUP_VIDEO_RUNPOD_EMBEDDING_ENDPOINT_ID` | unset | Required when `LARKUP_VIDEO_EMBEDDING_PROVIDER=runpod-qwen3-vl-embedding` (also needs `RUNPOD_API_KEY`). |
261
+ | `LARKUP_VIDEO_HF_EMBEDDING_URL` | unset | Required when `LARKUP_VIDEO_EMBEDDING_PROVIDER=huggingface-qwen3-vl-embedding` (also needs `HF_TOKEN`). |
262
+ | `LARKUP_MEDIA_STORAGE` | `local` | Web app env var: `s3` switches `createStorageProvider()` to `S3StorageProvider` for canonical media (see `LARKUP_MEDIA_S3_BUCKET` etc.). |
263
+ | `WEBHOOK_SIGNING_SECRET` | unset | Signs outbound job-completion webhooks (`X-Larkup-Signature`). |
264
+ | `STALE_JOB_TIMEOUT_HOURS` | `6` | Force-fails a queued/running job older than this on the scheduled reconcile sweep. |
265
+
266
+ ## Verification
267
+
268
+ ```bash
269
+ pnpm --filter @larkup/tool-video-intelligence type-check
270
+ pnpm --filter @larkup/tool-video-intelligence test
271
+ pnpm --filter @larkup/marketplace test # S3StorageProvider, tool-loader, etc.
272
+ PYTHONPATH=runtime python3 -m unittest discover -s runtime/tests -p 'test_*.py'
273
+ docker build --target smoke -t larkup-video-smoke runtime
274
+ docker build --target cpu -t larkup-video-cpu runtime
275
+ ```
276
+
277
+ The AWS control plane and GPU provider tests/validation run privately -- see `deploy/README.md`.
278
+
279
+ The runtime is the default path for indexed videos. Removing this package, its
280
+ v3 catalog record, and the optional installed-tool entry cleanly removes the
281
+ implementation.
@@ -0,0 +1,14 @@
1
+ services:
2
+ video-intelligence:
3
+ build:
4
+ target: runtime
5
+ environment:
6
+ LARKUP_VIDEO_DEVICE: cuda
7
+ LARKUP_VIDEO_OCR_ENGINE: PaddleOCR
8
+ deploy:
9
+ resources:
10
+ reservations:
11
+ devices:
12
+ - driver: nvidia
13
+ count: 1
14
+ capabilities: [gpu]