@kedem/okdb 2.5.0 → 2.6.1
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/CHANGELOG.md +90 -0
- package/algorithm-worker-thread.js +1 -1
- package/bin/okdb.js +1 -1
- package/docs/auth-permissions.md +31 -5
- package/okdb-functions-sandbox-worker.js +1 -1
- package/okdb-http-worker-child.js +1 -1
- package/okdb-views-bootstrap-worker.js +1 -1
- package/okdb.js +1 -1
- package/package.json +1 -1
- package/public/admin-app.js +1 -1
- package/public/components/schema-edit-modal.ok.js +1 -0
- package/public/core/db/db-section.ok.html +1 -0
- package/public/core/db/modals/add-item-modal.ok.js +1 -0
- package/public/core/db/modals/create-fts-modal.ok.js +1 -0
- package/public/core/db/modals/create-index-modal.ok.js +1 -0
- package/public/core/db/parts/db-overview.ok.js +1 -0
- package/public/core/db/parts/edit-row.ok.js +1 -0
- package/public/core/db/parts/type-changelog.ok.js +1 -0
- package/public/core/db/parts/type-data-tab.ok.js +1 -0
- package/public/core/db/parts/type-list.ok.js +1 -0
- package/public/core/db/parts/type-manage-tab.ok.js +1 -0
- package/public/core/db/parts/type-schema-tab.ok.js +1 -0
- package/public/core/db/parts/type-viewer.ok.js +1 -0
- package/public/core/db/type-ops.js +1 -0
- package/public/core/docs/docs-page.ok.html +1 -0
- package/public/core/license/license-panel.ok.js +1 -0
- package/public/core/system/parts/system-log.ok.js +1 -0
- package/public/core/system/parts/system-processing-panel.ok.js +1 -0
- package/public/core/system/parts/system-storage-panel.ok.js +1 -0
- package/public/core/system/system-events-page.ok.js +1 -0
- package/public/core/system/system-logs-page.ok.js +1 -0
- package/public/core/system/system-overview-page.ok.html +1 -0
- package/public/core/system/system-runtime-page.ok.js +1 -0
- package/public/core/system/system-section.ok.html +1 -0
- package/public/features/api/api-panel.ok.js +1 -0
- package/public/features/api/index.js +1 -0
- package/public/features/auth/auth-panel.ok.js +1 -0
- package/public/features/auth/index.js +1 -0
- package/public/features/files/files-section.ok.html +1 -0
- package/public/features/files/index.js +1 -0
- package/public/features/files/parts/files-file-list.ok.js +1 -0
- package/public/features/files/parts/files-path-browser.ok.js +1 -0
- package/public/features/files/parts/files-preview.ok.js +1 -0
- package/public/features/files/parts/files-upload-panel.ok.js +1 -0
- package/public/features/functions/exports.js +1 -0
- package/public/features/functions/functions-section.ok.html +1 -0
- package/public/features/functions/functions-store.js +1 -0
- package/public/features/functions/index.js +1 -0
- package/public/features/functions/modals/function-modal.ok.js +1 -0
- package/public/features/functions/parts/function-detail.ok.js +1 -0
- package/public/features/functions/parts/function-logs.ok.js +1 -0
- package/public/features/functions/parts/function-runner.ok.js +1 -0
- package/public/features/pipelines/engine-ui-utils.js +1 -0
- package/public/features/pipelines/exports.js +1 -0
- package/public/features/pipelines/index.js +1 -0
- package/public/features/pipelines/modals/create-pipeline-modal.ok.js +1 -0
- package/public/features/pipelines/modals/edit-pipeline-modal.ok.js +1 -0
- package/public/features/pipelines/modals/engine-modal.ok.js +1 -0
- package/public/features/pipelines/parts/embed-create-panel.ok.js +1 -0
- package/public/features/pipelines/parts/embed-embedder-panel.ok.js +1 -0
- package/public/features/pipelines/parts/embed-indexer-panel.ok.js +1 -0
- package/public/features/pipelines/parts/embed-search-panel.ok.js +1 -0
- package/public/features/pipelines/parts/embed-worker-panel.ok.js +1 -0
- package/public/features/pipelines/parts/embeddings-engine-panel.ok.js +1 -0
- package/public/features/pipelines/parts/engine-declaration-editor.ok.js +1 -0
- package/public/features/pipelines/parts/engines-overview.ok.js +1 -0
- package/public/features/pipelines/parts/generic-engine-panel.ok.js +1 -0
- package/public/features/pipelines/parts/pipeline-create-panel.ok.js +1 -0
- package/public/features/pipelines/parts/pipeline-flow-strip.ok.js +1 -0
- package/public/features/pipelines/parts/type-pipelines-tab.ok.js +1 -0
- package/public/features/pipelines/pipelines-section.ok.html +1 -0
- package/public/features/queue/index.js +1 -0
- package/public/features/queue/modals/create-bucket-modal.ok.js +1 -0
- package/public/features/queue/modals/edit-bucket-modal.ok.js +1 -0
- package/public/features/queue/modals/edit-job-modal.ok.js +1 -0
- package/public/features/queue/modals/enqueue-job-modal.ok.js +1 -0
- package/public/features/queue/modals/job-type-modal.ok.js +1 -0
- package/public/features/queue/parts/job-log-panel.ok.js +1 -0
- package/public/features/queue/parts/queue-buckets.ok.js +1 -0
- package/public/features/queue/parts/queue-job-types.ok.js +1 -0
- package/public/features/queue/parts/queue-jobs.ok.js +1 -0
- package/public/features/queue/parts/queue-types.ok.js +1 -0
- package/public/features/queue/parts/queue-workers.ok.js +1 -0
- package/public/features/queue/queue-section.ok.html +1 -0
- package/public/features/sync/index.js +1 -0
- package/public/features/sync/sync-panel.ok.js +1 -0
- package/public/features/views/index.js +1 -0
- package/public/features/views/modals/create-view-modal.ok.js +1 -0
- package/public/features/views/parts/views-list.ok.js +1 -0
- package/public/features/views/parts/views-overview.ok.js +1 -0
- package/public/features/views/views-section.ok.html +1 -0
- package/public/features/views/views-store.js +1 -0
- package/public/index.html +9 -3
- package/public/modules/ok.js +1 -1
- package/public/shell/admin-shell.ok.html +3 -0
- package/public/shell/core-manifest.js +1 -0
- package/public/shell/shell-piece.ok.js +1 -0
- package/public/shell/shell-section-host.ok.js +1 -0
- package/public/shell/shell-section.ok.js +1 -0
- package/public/shell/shell-store.js +1 -0
- package/public/stores/auth-store.js +1 -1
- package/public/stores/okdb-store.js +1 -1
- package/public/stores/storage-store.js +1 -0
- package/public/styles.css +1 -1
- package/public/vendor/okjs/ok.esm.min.js +1 -1
- package/public/vendor/okjs/toolkit/components/ok-chart.ok.js +1 -1
- package/public/vendor/okjs/toolkit/components/ok-doc-viewer.ok.js +1 -1
- package/public/vendor/okjs/toolkit/components/ok-marked.ok.js +1 -1
- package/public/vendor/okjs/toolkit/components/ok-monaco.ok.js +1 -1
- package/public/vendor/okjs/toolkit/core/virtualized.ok.js +1 -1
- package/public/vendor/okjs/toolkit/editor/ok-live-shell.ok.js +1 -1
- package/public/vendor/okjs/toolkit/elements/ok-select.ok.js +1 -1
- package/public/vendor/okjs/toolkit/elements/ok-table.ok.js +1 -1
- package/public/components/admin-route-host.ok.js +0 -1
- package/public/components/field.html +0 -158
- package/public/layouts/_default.ok.html +0 -3
- package/public/sections/api/index.ok.html +0 -1
- package/public/sections/auth/index.ok.html +0 -1
- package/public/sections/auth/modals/perm-info-popover.ok.js +0 -1
- package/public/sections/db/index.ok.html +0 -1
- package/public/sections/db/modals/add-item-modal.ok.js +0 -1
- package/public/sections/db/modals/create-fts-modal.ok.js +0 -1
- package/public/sections/db/modals/create-index-modal.ok.js +0 -1
- package/public/sections/db/modals/create-pipeline-modal.ok.js +0 -1
- package/public/sections/db/modals/schema-edit-modal.ok.js +0 -1
- package/public/sections/db/parts/db-overview.ok.js +0 -1
- package/public/sections/db/parts/edit-row.ok.js +0 -1
- package/public/sections/db/parts/type-changelog.ok.js +0 -1
- package/public/sections/db/parts/type-list.ok.js +0 -1
- package/public/sections/db/parts/type-pipelines-tab.ok.js +0 -1
- package/public/sections/db/parts/type-schema-tab.ok.js +0 -1
- package/public/sections/db/parts/type-viewer.ok.js +0 -1
- package/public/sections/db/parts/type-violations-tab.ok.js +0 -1
- package/public/sections/docs/index.ok.html +0 -1
- package/public/sections/embeddings/index.ok.html +0 -1
- package/public/sections/embeddings/modals/edit-pipeline-modal.ok.js +0 -1
- package/public/sections/embeddings/parts/embed-create-panel.ok.js +0 -1
- package/public/sections/embeddings/parts/embed-embedder-panel.ok.js +0 -1
- package/public/sections/embeddings/parts/embed-engine-declaration-editor.ok.js +0 -1
- package/public/sections/embeddings/parts/embed-engine-list.ok.js +0 -1
- package/public/sections/embeddings/parts/embed-indexer-panel.ok.js +0 -1
- package/public/sections/embeddings/parts/embed-lifecycle-bar.ok.js +0 -1
- package/public/sections/embeddings/parts/embed-overview.ok.js +0 -1
- package/public/sections/embeddings/parts/embed-search-panel.ok.js +0 -1
- package/public/sections/embeddings/parts/embed-worker-panel.ok.js +0 -1
- package/public/sections/embeddings/parts/embeddings-engine-panel.ok.js +0 -1
- package/public/sections/embeddings/parts/engines-overview.ok.js +0 -1
- package/public/sections/embeddings/parts/pipeline-create-panel.ok.js +0 -1
- package/public/sections/embeddings/parts/pipeline-flow-strip.ok.js +0 -1
- package/public/sections/engines/engine-ui-utils.js +0 -1
- package/public/sections/engines/index.ok.html +0 -1
- package/public/sections/engines/modals/engine-modal.ok.js +0 -1
- package/public/sections/engines/parts/engine-declaration-editor.ok.js +0 -1
- package/public/sections/engines/parts/generic-engine-panel.ok.js +0 -1
- package/public/sections/files/index.ok.html +0 -1
- package/public/sections/files/parts/files-collection-list.ok.js +0 -1
- package/public/sections/files/parts/files-collection-panel.ok.js +0 -1
- package/public/sections/files/parts/files-file-list.ok.js +0 -1
- package/public/sections/files/parts/files-path-browser.ok.js +0 -1
- package/public/sections/files/parts/files-preview.ok.js +0 -1
- package/public/sections/files/parts/files-upload-panel.ok.js +0 -1
- package/public/sections/functions/index.ok.html +0 -1
- package/public/sections/functions/modals/function-modal.ok.js +0 -1
- package/public/sections/functions/parts/function-detail.ok.js +0 -1
- package/public/sections/functions/parts/function-logs.ok.js +0 -1
- package/public/sections/functions/parts/function-runner.ok.js +0 -1
- package/public/sections/license/index.ok.html +0 -1
- package/public/sections/license/parts/license-panel.ok.js +0 -1
- package/public/sections/queue/index.ok.html +0 -1
- package/public/sections/queue/modals/create-bucket-modal.ok.js +0 -1
- package/public/sections/queue/modals/edit-bucket-modal.ok.js +0 -1
- package/public/sections/queue/modals/edit-job-modal.ok.js +0 -1
- package/public/sections/queue/modals/enqueue-job-modal.ok.js +0 -1
- package/public/sections/queue/modals/job-type-modal.ok.js +0 -1
- package/public/sections/queue/parts/job-log-panel.ok.js +0 -1
- package/public/sections/queue/parts/ok-job-form.ok.js +0 -1
- package/public/sections/queue/parts/queue-buckets.ok.js +0 -1
- package/public/sections/queue/parts/queue-job-types.ok.js +0 -1
- package/public/sections/queue/parts/queue-jobs.ok.js +0 -1
- package/public/sections/queue/parts/queue-types.ok.js +0 -1
- package/public/sections/queue/parts/queue-workers.ok.js +0 -1
- package/public/sections/sync/index.ok.html +0 -5
- package/public/sections/sync/parts/sync-node-detail.ok.js +0 -1
- package/public/sections/system/index.ok.html +0 -1
- package/public/sections/system/parts/system-api-panel.ok.js +0 -1
- package/public/sections/system/parts/system-auth-panel.ok.js +0 -1
- package/public/sections/system/parts/system-log.ok.js +0 -1
- package/public/sections/system/parts/system-processing-panel.ok.js +0 -1
- package/public/sections/system/parts/system-status.ok.js +0 -1
- package/public/sections/system/parts/system-storage-panel.ok.js +0 -1
- package/public/sections/system/parts/system-sync-panel.ok.js +0 -1
- package/public/sections/views/index.ok.html +0 -1
- package/public/sections/views/modals/create-view-modal.ok.js +0 -1
- package/public/sections/views/parts/views-list.ok.js +0 -1
- package/public/sections/views/parts/views-overview.ok.js +0 -1
- package/public/stores/functions-store.js +0 -1
- /package/public/{sections → core}/db/parts/tm-timeline.ok.js +0 -0
- /package/public/{util → core/db}/sift-schema.js +0 -0
- /package/public/{view-models → core/db}/type-query-vm.js +0 -0
- /package/public/{sections → core}/system/modals/data-ops-modal.ok.js +0 -0
- /package/public/{sections → core}/system/parts/system-locks-panel.ok.js +0 -0
- /package/public/{sections → core}/system/parts/system-log-history.ok.js +0 -0
- /package/public/{sections → core}/system/parts/system-process-panel.ok.js +0 -0
- /package/public/{sections → core}/system/parts/system-runtime-overview.ok.js +0 -0
- /package/public/{sections → features}/api/parts/api-endpoint.ok.js +0 -0
- /package/public/{sections → features}/auth/modals/create-token-modal.ok.js +0 -0
- /package/public/{sections → features}/auth/modals/edit-token-modal.ok.js +0 -0
- /package/public/{sections → features}/auth/parts/token-detail.ok.js +0 -0
- /package/public/{sections → features}/auth/parts/token-list.ok.js +0 -0
- /package/public/{sections → features}/files/parts/files-blob-status.ok.js +0 -0
- /package/public/{sections → features}/files/parts/files-overview.ok.js +0 -0
- /package/public/{sections → features}/functions/parts/functions-list.ok.js +0 -0
- /package/public/{sections/engines → features/pipelines}/engine-panel-shared-style.js +0 -0
- /package/public/{sections/embeddings → features/pipelines}/modals/register-model-modal.ok.js +0 -0
- /package/public/{sections/embeddings → features/pipelines}/modals/replace-embedder-modal.ok.js +0 -0
- /package/public/{sections/embeddings → features/pipelines}/parts/embed-model-catalog.ok.js +0 -0
- /package/public/{sections/engines → features/pipelines}/parts/engine-lifecycle-actions.ok.js +0 -0
- /package/public/{sections/engines → features/pipelines}/parts/engine-panel-shell.ok.js +0 -0
- /package/public/{sections/engines → features/pipelines}/parts/engine-resource-card.ok.js +0 -0
- /package/public/{sections/engines → features/pipelines}/parts/engine-row-item.ok.js +0 -0
- /package/public/{sections/embeddings → features/pipelines}/parts/pipeline-try-search.ok.js +0 -0
- /package/public/{sections → features}/queue/parts/code-panel.ok.js +0 -0
- /package/public/{sections → features}/sync/modals/connect-peer-modal.ok.js +0 -0
- /package/public/{sections → features}/sync/parts/sync-retention.ok.js +0 -0
- /package/public/{sections → features}/sync/parts/sync-topology.ok.js +0 -0
- /package/public/{sections → features}/views/parts/view-detail.ok.js +0 -0
- /package/public/{sections/db → shell}/modals/create-env-modal.ok.js +0 -0
- /package/public/{sections/db → shell}/modals/demo-env-modal.ok.js +0 -0
- /package/public/{sections/db → shell}/modals/remove-env-modal.ok.js +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const t=()=>__ENV__.ADMIN_API.replace(/\/api$/,"")+"/license";export default{tag:"license-panel",context:e=>({status:null,loading:!0,error:null,unavailable:!1,showAddForm:!1,addInput:"",addLoading:!1,addError:null,activatingId:null,activateToken:"",activateLoading:!1,activateError:null,async load(){this.loading=!0,this.error=null,this.unavailable=!1;try{const e=await fetch(`${t()}/status`);if(!e.ok){const t=await e.json().catch(()=>({}));throw new Error(t?.error?.message||t?.error||"Failed to load license status")}const s=await e.json();this.status=s.data??s.result??s}catch(t){this.error=t?.message||String(t)}finally{this.loading=!1}},openAddForm(){this.showAddForm=!0,this.addInput="",this.addError=null},cancelAddForm(){this.showAddForm=!1,this.addError=null},async submitAdd(){if(this.addInput.trim()&&!this.addLoading){this.addLoading=!0,this.addError=null;try{const e=await fetch(`${t()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({input:this.addInput.trim()})}),s=await e.json();if(!e.ok){const t=s?.error?.message||s?.error||s?.data?.error||s?.result?.error||"Failed to add license";throw new Error("string"==typeof t?t:JSON.stringify(t))}this.showAddForm=!1,await this.load()}catch(t){this.addError=t?.message||String(t)}finally{this.addLoading=!1}}},copyPin(){const t=this.pinDisplay();t&&"—"!==t&&navigator.clipboard?.writeText&&navigator.clipboard.writeText(t).then(()=>e.$ok.shared?.toast?.success?.("PIN copied"),()=>e.$ok.shared?.toast?.error?.("Copy failed"))},usagePct:(t,e)=>e&&0!==e?Math.min(100,Math.round(t/e*100)):0,usageBarColor:t=>t>=90?"var(--okdb-danger,#f56565)":t>=75?"var(--okdb-warn,#edc94b)":"var(--okdb-success,#48bb78)",formatNum:t=>null==t?"—":Number(t).toLocaleString(),openActivate(t){this.activatingId=t,this.activateToken="",this.activateError=null},cancelActivate(){this.activatingId=null,this.activateError=null},async submitActivate(e){if(this.activateToken.trim()&&!this.activateLoading){this.activateLoading=!0,this.activateError=null;try{const s=await fetch(`${t()}/${encodeURIComponent(e)}/activate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({activation:this.activateToken.trim()})}),a=await s.json();if(!s.ok){const t=a?.error?.message||a?.error||a?.data?.error||a?.result?.error||"Activation failed";throw new Error("string"==typeof t?t:JSON.stringify(t))}this.activatingId=null,await this.load()}catch(t){this.activateError=t?.message||String(t)}finally{this.activateLoading=!1}}},async removeLicense(s){if(confirm("Remove this license?"))try{const a=await fetch(`${t()}/${encodeURIComponent(s)}`,{method:"DELETE"}),i=await a.json();if(!a.ok){const t=i?.error?.message||i?.error||i?.data?.error||i?.result?.error||"Remove failed";throw new Error("string"==typeof t?t:JSON.stringify(t))}e.$ok.shared?.toast?.success?.("License removed"),await this.load()}catch(t){e.$ok.shared?.toast?.error?.(t?.message||"Remove failed")}},formatDate:t=>t?new Date(t).toISOString().slice(0,10):"—",shortId:t=>t?t.slice(0,8)+"…":"—",featureSummary(t){if(!t)return"—";const e=Object.entries(t).filter(([,t])=>t).map(([t])=>t);return e.length?e[0]+(e.length>1?" +"+(e.length-1):""):"none"},pinDisplay(){const t=this.status?.pin;return t?Array.isArray(t)?0===t.length?"—":t.map(t=>"string"==typeof t?t:t?.pin).filter(Boolean).join(", ")||"—":t:"—"},hasActive(){return(this.status?.activeCount??0)>0},activeLicensee(){return this.status?.licenses?.find(t=>"active"===t.status)?.licensee??null},activeExpiry(){return this.status?.licenses?.find(t=>"active"===t.status)?.expiresAt??null},badgeStyle:t=>(({active:"background:var(--okdb-success-soft-bg,rgba(72,187,120,.12));border-color:var(--okdb-success-soft-border,rgba(72,187,120,.25));color:var(--okdb-success,#48bb78);",expired:"background:var(--okdb-danger-soft-bg,rgba(245,101,101,.1));border-color:var(--okdb-danger-soft-border,rgba(245,101,101,.25));color:var(--okdb-danger,#f56565);",invalid:"background:var(--okdb-danger-soft-bg,rgba(245,101,101,.1));border-color:var(--okdb-danger-soft-border,rgba(245,101,101,.25));color:var(--okdb-danger,#f56565);",pending:"background:rgba(237,201,75,.1);border-color:rgba(237,201,75,.3);color:#edc94b;",wrong_node:"background:rgba(237,137,54,.1);border-color:rgba(237,137,54,.3);color:#ed8936;"}[t]||"")+"font-size:10px;padding:2px 7px;border-radius:4px;border:1px solid;font-weight:500;text-transform:uppercase;letter-spacing:.04em;"),licensePin(t){const e=this.status?.pin;if(Array.isArray(e)){const s=e.find(e=>e?.licenseId===t?.id);if(s?.pin)return s.pin}return"string"==typeof t?.pin?t.pin:"—"}}),mount(){this.load()},style:"license-panel{display:block;padding:24px;max-width:860px}.lp-header{display:flex;align-items:center;justify-content:space-between;margin-bottom:20px}.lp-title{font-size:18px;font-weight:600}.lp-status-banner{padding:12px 16px;border-radius:10px;border:1px solid;font-size:13px;margin-bottom:20px;display:flex;align-items:center;gap:10px}.lp-status-banner--ok{background:var(--okdb-success-soft-bg, rgba(72,187,120,.08));border-color:var(--okdb-success-soft-border, rgba(72,187,120,.2));color:var(--okdb-success, #48bb78)}.lp-status-banner--warn{background:var(--okdb-danger-soft-bg, rgba(245,101,101,.08));border-color:var(--okdb-danger-soft-border, rgba(245,101,101,.2));color:var(--okdb-danger, #f56565)}.lp-pin-box{background:var(--okdb-app-surface-2, rgba(255,255,255,.04));border:1px solid var(--okdb-app-border);border-radius:8px;padding:12px 16px;margin-bottom:20px;font-size:12px}.lp-pin-label{opacity:.5;text-transform:uppercase;letter-spacing:.06em;font-size:10px;margin-bottom:4px}.lp-pin-value{font-family:monospace;font-size:15px;font-weight:600;letter-spacing:.08em}.lp-lic-cells,.lp-lic-header{display:grid;grid-template-columns:90px 1fr 90px 80px 80px auto;gap:0 10px;align-items:center;padding:6px 10px}.lp-lic-header{font-size:10px;text-transform:uppercase;letter-spacing:.06em;opacity:.45}.lp-lic-header,.lp-lic-row{border-bottom:1px solid var(--okdb-app-border)}.lp-lic-row:last-child{border-bottom:none}.lp-add-form{background:var(--okdb-app-surface-2, rgba(255,255,255,.03));border:1px solid var(--okdb-app-border);border-radius:10px;padding:16px;margin-bottom:20px;display:flex;flex-direction:column;gap:12px}.lp-form-label{font-size:10px;opacity:.5;text-transform:uppercase;letter-spacing:.06em;margin-bottom:4px}.lp-activate-row,.lp-btn{border:1px solid var(--okdb-app-border)}.lp-activate-row{background:var(--okdb-app-surface-2, rgba(255,255,255,.03));border-radius:8px;padding:10px 12px;display:flex;flex-direction:column;gap:8px;margin-top:4px}.lp-btn{padding:5px 12px;border-radius:6px;background:0 0;color:var(--okdb-app-fg-muted);font-size:12px;font-weight:500;cursor:pointer;transition:background .1s,color .1s}.lp-btn:hover{background:var(--okdb-app-surface-2);color:var(--okdb-app-fg-strong)}.lp-btn--primary{background:var(--okdb-sky-soft-bg, rgba(99,179,237,.1));border-color:var(--okdb-sky-soft-border, rgba(99,179,237,.25));color:var(--okdb-sky, #63b3ed)}.lp-btn--danger{background:var(--okdb-danger-soft-bg, rgba(245,101,101,.08));border-color:var(--okdb-danger-soft-border, rgba(245,101,101,.2));color:var(--okdb-danger, #f56565)}",template:'<div><if :="loading"><div style="font-size:13px; opacity:.5; padding:20px 0;">Loading…</div></if><if :="!loading && unavailable"><div style="font-size:13px; opacity:.6; padding:20px 0;">License system not available in this build.</div></if><if :="!loading && !unavailable"><div class="lp-header"><div class="lp-title">License</div><button class="lp-btn lp-btn--primary" @click="openAddForm()">+ Add License</button></div><if :="hasActive()"><div class="lp-status-banner lp-status-banner--ok"><span>✓ Licensed</span> <span>—</span> <span style="font-weight:600;">{{ activeLicensee() }}</span><if :="activeExpiry()"><span style="opacity:.7;">· Expires {{ formatDate(activeExpiry()) }}</span></if></div></if><if :="!hasActive()"><div class="lp-status-banner lp-status-banner--warn"><span>⚠ Free tier</span><if :="status && status.effective"><span style="opacity:.7; font-size:12px;">— envs={{ status.effective.limits.envs }}, types/env={{ status.effective.limits.typesPerEnv }}, writes={{ (status.effective.limits.maxWrites||0).toLocaleString() }}</span></if></div><if :="status && status.isLicensedBuild && pinDisplay() !== \'—\'"><div class="lp-pin-box"><div class="lp-pin-label">Node PIN — share this with your license provider</div><div style="display:flex; align-items:center; gap:10px;"><div class="lp-pin-value">{{ pinDisplay() }}</div><button class="lp-btn" style="font-size:11px; padding:3px 8px;" @click="copyPin()">Copy</button></div><div style="font-size:11px; opacity:.55; margin-top:6px;">How activation works: paste your <strong>license blob</strong> below → vendor signs an activation token bound to this PIN → paste the activation token to enable the license.</div></div></if><if :="status && status.isLicensedBuild && status.buildFingerprint"><div class="lp-pin-box" style="margin-top:-12px;"><div class="lp-pin-label">Build signing-key fingerprint</div><div style="font-family:monospace; font-size:12px;">{{ status.buildFingerprint }}</div><div style="font-size:11px; opacity:.55; margin-top:6px;">Your license must be signed by the private key paired with this fingerprint. If you see <em>"License signature invalid"</em>, the license was signed by a different keypair than the one this build uses.</div></div></if><if :="status && !status.isLicensedBuild"><div class="lp-pin-box" style="opacity:.6"><div class="lp-pin-label">Development build — license enforcement disabled</div><div style="font-size:12px; margin-top:4px;">Set <code>OKDB_LICENSED_BUILD=true</code> in <code>.env</code> to enable enforcement in dev, or run <code>npm run build:prod</code> for a production build.</div></div></if></if><if :="status && status.usage && status.effective"><div style="display:flex; flex-direction:column; gap:10px; margin-bottom:20px;"><if :="status.effective.limits.maxWrites"><div><div style="display:flex; justify-content:space-between; font-size:11px; opacity:.7; margin-bottom:4px;"><span>Writes</span> <span style="font-family:monospace;">{{ formatNum(status.usage.writes) }} / {{ formatNum(status.effective.limits.maxWrites) }}</span></div><div style="height:6px; background:var(--okdb-app-surface-2,rgba(255,255,255,.06)); border-radius:3px; overflow:hidden;"><div :style="\'height:100%;width:\' + usagePct(status.usage.writes, status.effective.limits.maxWrites) + \'%;background:\' + usageBarColor(usagePct(status.usage.writes, status.effective.limits.maxWrites)) + \';transition:width .2s;\'"/></div></div></if><if :="status.effective.limits.envs"><div><div style="display:flex; justify-content:space-between; font-size:11px; opacity:.7; margin-bottom:4px;"><span>Environments</span> <span style="font-family:monospace;">{{ status.usage.envs }} / {{ status.effective.limits.envs }}</span></div><div style="height:6px; background:var(--okdb-app-surface-2,rgba(255,255,255,.06)); border-radius:3px; overflow:hidden;"><div :style="\'height:100%;width:\' + usagePct(status.usage.envs, status.effective.limits.envs) + \'%;background:\' + usageBarColor(usagePct(status.usage.envs, status.effective.limits.envs)) + \';transition:width .2s;\'"/></div></div></if></div></if><if :="showAddForm"><div class="lp-add-form"><div style="font-size:13px; font-weight:600;">Add License or Activation Token</div><div style="font-size:11px; opacity:.6;">Paste either a <strong>license blob</strong> (issued by your vendor) or an <strong>activation token</strong> (vendor\'s response to your PIN). The server detects which it is.</div><div><textarea :value="addInput" @input="addInput = $event.target.value" rows="6" placeholder="Paste license blob or activation token here…" style="width:100%; font-family:monospace; font-size:11px; resize:vertical;"/></div><if :="addError"><div style="font-size:12px; color:var(--okdb-danger); background:var(--okdb-danger-soft-bg,rgba(245,101,101,.08)); border:1px solid var(--okdb-danger-soft-border,rgba(245,101,101,.2)); border-radius:6px; padding:8px 12px;">{{ addError }}</div></if><div style="display:flex; gap:8px; justify-content:flex-end;"><button class="lp-btn" @click="cancelAddForm()">Cancel</button> <button class="lp-btn lp-btn--primary" @click="submitAdd()" :disabled="!addInput.trim() || addLoading">{{ addLoading ? \'Submitting…\' : \'Submit\' }}</button></div></div></if><if :="status && status.effective"><div style="margin-top:20px; font-size:10px; text-transform:uppercase; letter-spacing:.06em; opacity:.45; margin-bottom:8px;">Current capabilities</div><table class="lp-table" style="margin-bottom:16px;"><thead><tr><th>Feature</th><th>Status</th><th>Limit</th></tr></thead><tbody><tr><td>Sync</td><td><span :style="status.effective.features.sync ? \'color:var(--okdb-success,#38a169)\' : \'opacity:.45\'">{{ status.effective.features.sync ? \'✓ enabled\' : \'✗ disabled\' }}</span></td><td style="font-family:monospace;">{{ status.effective.limits.syncPeers ? \'max \' + status.effective.limits.syncPeers + \' peers\' : (status.effective.features.sync ? \'unlimited\' : \'—\') }}</td></tr><tr><td>Embeddings</td><td><span :style="status.effective.features.embeddings ? \'color:var(--okdb-success,#38a169)\' : \'opacity:.45\'">{{ status.effective.features.embeddings ? \'✓ enabled\' : \'✗ disabled\' }}</span></td><td>—</td></tr><tr><td>Engines</td><td><span :style="status.effective.features.engines ? \'color:var(--okdb-success,#38a169)\' : \'opacity:.45\'">{{ status.effective.features.engines ? \'✓ enabled\' : \'✗ disabled\' }}</span></td><td>—</td></tr><tr><td>Full-text search</td><td><span :style="status.effective.features.fts ? \'color:var(--okdb-success,#38a169)\' : \'opacity:.45\'">{{ status.effective.features.fts ? \'✓ enabled\' : \'✗ disabled\' }}</span></td><td>—</td></tr><tr><td>Time machine</td><td><span :style="status.effective.features.timeMachine ? \'color:var(--okdb-success,#38a169)\' : \'opacity:.45\'">{{ status.effective.features.timeMachine ? \'✓ enabled\' : \'✗ disabled\' }}</span></td><td>—</td></tr><tr><td>Views</td><td><span :style="status.effective.features.views ? \'color:var(--okdb-success,#38a169)\' : \'opacity:.45\'">{{ status.effective.features.views ? \'✓ enabled\' : \'✗ disabled\' }}</span></td><td>—</td></tr><tr><td>MCP</td><td><span :style="status.effective.features.mcp ? \'color:var(--okdb-success,#38a169)\' : \'opacity:.45\'">{{ status.effective.features.mcp ? \'✓ enabled\' : \'✗ disabled\' }}</span></td><td>—</td></tr><tr><td>Files</td><td><span :style="status.effective.features.files ? \'color:var(--okdb-success,#38a169)\' : \'opacity:.45\'">{{ status.effective.features.files ? \'✓ enabled\' : \'✗ disabled\' }}</span></td><td>—</td></tr><tr><td>Environments</td><td><span style="color:var(--okdb-success,#38a169)">✓ enabled</span></td><td style="font-family:monospace;">{{ status.effective.limits.envs ? \'max \' + status.effective.limits.envs : \'unlimited\' }}</td></tr><tr><td>Types per env</td><td><span style="color:var(--okdb-success,#38a169)">✓ enabled</span></td><td style="font-family:monospace;">{{ status.effective.limits.typesPerEnv ? \'max \' + status.effective.limits.typesPerEnv : \'unlimited\' }}</td></tr><tr><td>Embeddings pipelines per env</td><td><span :style="status.effective.features.embeddings ? \'color:var(--okdb-success,#38a169)\' : \'opacity:.45\'">{{ status.effective.features.embeddings ? \'✓ enabled\' : \'✗ disabled\' }}</span></td><td style="font-family:monospace;">{{ status.effective.limits.pipelinesPerEnv ? \'max \' + status.effective.limits.pipelinesPerEnv : \'unlimited\' }}</td></tr><tr><td>Total writes</td><td><span style="color:var(--okdb-success,#38a169)">✓ enabled</span></td><td style="font-family:monospace;">{{ status.effective.limits.maxWrites ? (status.effective.limits.maxWrites).toLocaleString() + \' max\' : \'unlimited\' }}</td></tr></tbody></table></if><if :="status && status.licenses && status.licenses.length > 0"><div class="lp-lic-header"><span>ID</span><span>Licensee</span><span>Expires</span><span>Status</span><span>Features</span><span>Actions</span></div><each :of="status.licenses" let:lic><div class="lp-lic-row"><div class="lp-lic-cells"><span style="font-family:monospace; opacity:.7; font-size:11px;">{{ shortId(lic.id) }}</span> <span style="font-size:12px;">{{ lic.licensee || \'—\' }}</span> <span style="font-family:monospace; font-size:12px;">{{ formatDate(lic.expiresAt) }}</span> <span><span :style="badgeStyle(lic.status)">{{ lic.status }}</span></span> <span style="opacity:.7; font-size:12px;">{{ featureSummary(lic.features) }}</span><div style="display:flex; gap:6px; flex-wrap:wrap; align-items:center;"><if :="lic.status === \'pending\' || lic.status === \'wrong_node\'"><button class="lp-btn" style="font-size:11px;" @click="openActivate(lic.id)">Activate</button></if><button class="lp-btn lp-btn--danger" style="font-size:11px;" @click="removeLicense(lic.id)">Remove</button></div></div><if :="activatingId === lic.id"><div class="lp-activate-row"><div style="font-size:11px; opacity:.7;">PIN for this license: <span style="font-family:monospace; font-weight:600;">{{ licensePin(lic) }}</span></div><textarea :value="activateToken" @input="activateToken = $event.target.value" rows="3" placeholder="Paste activation token…" style="width:100%; font-family:monospace; font-size:11px; resize:vertical;"/><if :="activateError"><div style="font-size:11px; color:var(--okdb-danger);">{{ activateError }}</div></if><div style="display:flex; gap:6px; justify-content:flex-end;"><button class="lp-btn" style="font-size:11px;" @click="cancelActivate()">Cancel</button> <button class="lp-btn lp-btn--primary" style="font-size:11px;" @click="submitActivate(lic.id)" :disabled="!activateToken.trim() || activateLoading">{{ activateLoading ? \'Activating…\' : \'Activate\' }}</button></div></div></if></div></each></if><if :="error"><div style="font-size:13px; color:var(--okdb-danger); padding:12px 0;">{{ error }}</div></if></if></div>'};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<script type="module">import e from"./parts/queue-buckets.ok.js";import t from"./parts/queue-jobs.ok.js";import s from"./parts/queue-types.ok.js";import o from"./parts/queue-workers.ok.js";import i from"./parts/queue-job-types.ok.js";export default{tag:"queue-index",unwrap:!0,dependencies:[s,t,e,o,i],context:e=>({view:"jobs",selectedType:null,typesEl:null,jobsEl:null,onTypeSelected(e){const t=e.detail??null;this.selectedType!==t&&(this.selectedType=t,this.syncRouteState())},setView(e){["jobs","workers","buckets","types"].includes(e)||(e="jobs"),this.view!==e&&(this.view=e,this.syncRouteState())},applyRouteState(){const t=e.$vars?.$router,s=t?._search||{},o=["jobs","workers","buckets","types"].includes(s.view)?s.view:"jobs",i=s.type?String(s.type):null;this.view!==o&&(this.view=o),this.selectedType!==i&&(this.selectedType=i)},syncRouteState(){const t=e.$vars?.$router;if(!t?.resolve||!t?.replace)return;const s=t._search||{},o={...s};e.$ok?.stores?.okdb?.selectedEnv&&(o.env=e.$ok.stores.okdb.selectedEnv),this.view&&"jobs"!==this.view?o.view=this.view:delete o.view,this.selectedType?o.type=this.selectedType:delete o.type;const i=["jobs","workers","buckets","types"].includes(s.view)?s.view:"jobs",r=s.type?String(s.type):null,n=o.view?String(o.view):"jobs",l=o.type?String(o.type):null,p=s.env?String(s.env):null,u=o.env?String(o.env):null;i===n&&r===l&&p===u||t.replace(t.resolve(t._path||"/queue",o,t._anchor||""))},onJobsRefresh(){this.typesEl?.$scope?.$innerContext?.refresh?.()},async onEnvChanged(){this.selectedType=null,await(this.typesEl?.$scope?.$innerContext?.refresh?.()),await(this.jobsEl?.$scope?.$innerContext?.query?.load?.()),await(this.jobsEl?.$scope?.$innerContext?.loadStats?.())}}),init(e){this.applyRouteState(),e.$watch(()=>e.$ok.stores.okdb.selectedEnv,()=>this.onEnvChanged()),e.$watch(()=>[e.$vars?.$router?._search?.view??"",e.$vars?.$router?._search?.type??""].join("||"),()=>this.applyRouteState())}};</script><style>.queue-nav-btn{width:100%;text-align:left;padding:6px 10px;border-radius:6px;border:1px solid transparent;background:0 0;color:var(--okdb-app-fg-muted);font-size:12px;cursor:pointer;transition:background .12s,border-color .12s,color .12s}.queue-nav-btn:hover{background:var(--okdb-app-surface);border-color:var(--okdb-app-border);color:var(--okdb-app-fg-strong)}.queue-nav-btn--on{background:var(--okdb-app-surface);border-color:var(--okdb-accent);color:var(--okdb-app-fg-strong)}</style><template><component import="../../layouts/_default.ok.html"><template name="sidebar"><div style="display:flex;flex-direction:column;gap:10px;height:100%;min-height:0"><div style="display:flex;flex-direction:column;gap:4px"><button @click="setView('jobs')" :class="view==='jobs' ? 'queue-nav-btn queue-nav-btn--on' : 'queue-nav-btn'">Jobs</button> <button @click="setView('workers')" :class="view==='workers' ? 'queue-nav-btn queue-nav-btn--on' : 'queue-nav-btn'">Workers</button> <button @click="setView('buckets')" :class="view==='buckets' ? 'queue-nav-btn queue-nav-btn--on' : 'queue-nav-btn'">Buckets</button> <button @click="setView('types')" :class="view==='types' ? 'queue-nav-btn queue-nav-btn--on' : 'queue-nav-btn'">Types</button></div><div style="height:1px;background:var(--okdb-app-border);margin:4px 0"></div><if :="view === 'jobs' || view === 'workers'"><queue-types :ref="typesEl = $el" :selectedtype="selectedType" @type="onTypeSelected"/></if><if :="view === 'buckets'"><div style="opacity:.55;font-size:12px;line-height:1.7">Token buckets rate-limit job throughput.<br>Assign a bucket name to a job at enqueue time to control how many tokens are consumed per job.</div></if><if :="view === 'types'"><div style="opacity:.55;font-size:12px;line-height:1.7">Register job types to define defaults, limit concurrency, and pause or drain a type without touching individual jobs.</div></if><if :="view === 'workers'"><div style="height:1px;background:var(--okdb-app-border);margin:2px 0"></div><div style="opacity:.45;font-size:11px;line-height:1.6">Select a job type above to scope workers, or see all workers.</div></if></div></template><template name="default"><if :="view === 'jobs'"><queue-jobs :ref="jobsEl = $el" :type="selectedType" @refresh="onJobsRefresh" @go-to-buckets="setView('buckets')"/></if><if :="view === 'workers'"><queue-workers :jobtype="selectedType"/></if><if :="view === 'buckets'"><queue-buckets/></if><if :="view === 'types'"><queue-job-types/></if></template></component></template>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import e from"../../../stores/okdb-store.js";export default{tag:"create-bucket-modal",attr:{modal:{},onDone:{}},context:n=>({busy:!1,error:null,form:{id:"",capacity:100,tokens:100,refill_amount:0,refill_every:0},async save(){const t=String(this.form.id||"").trim();if(t){this.busy=!0,this.error=null;try{const r=await fetch(`${e.apiBase}/queue/bucket/add/${encodeURIComponent(t)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({capacity:Number(this.form.capacity)||0,tokens:Number(this.form.tokens)||0,refill_amount:Number(this.form.refill_amount)||0,refill_every:Number(this.form.refill_every)||0})}),i=await r.json();if(!r.ok)throw new Error(i?.error?.message||"Create failed");n.$ok.shared?.toast?.success?.(`Bucket "${t}" created`),await n.$attr.modal.close(),await(n.$attr.onDone?.(t))}catch(e){this.error=e?.message||"Create failed"}finally{this.busy=!1}}else this.error="Bucket ID is required"},cancel(){n.$attr.modal.close()}}),template:'\n<div style="min-width:320px; display:flex; flex-direction:column; gap:12px;">\n\n <if :="error">\n <div style="color:var(--okdb-danger); font-size:12px; padding:8px; border:1px solid var(--okdb-danger); border-radius:6px;">\n {{ error }}\n </div>\n </if>\n\n <div style="display:grid; grid-template-columns:130px 1fr; gap:8px 12px; align-items:center; font-size:13px;">\n\n <label style="opacity:.7;">Bucket ID</label>\n <input\n :value="form.id"\n @input="form.id = $el.value"\n placeholder="e.g. openai-api"\n style="font-family:monospace;"\n @keydown:enter="save()"\n />\n\n <label style="opacity:.7;">Capacity</label>\n <input type="number" min="1"\n :value="form.capacity"\n @input="form.capacity = Number($el.value)"\n />\n\n <label style="opacity:.7;">Initial Tokens</label>\n <input type="number" min="0"\n :value="form.tokens"\n @input="form.tokens = Number($el.value)"\n />\n\n <div style="grid-column:1/-1; height:1px; background:var(--okdb-app-border); margin:2px 0;"></div>\n\n <div style="grid-column:1/-1; font-size:11px; opacity:.5; text-transform:uppercase; letter-spacing:.05em;">\n Auto-Refill (optional)\n </div>\n\n <label style="opacity:.7;">Refill Amount</label>\n <input type="number" min="0"\n :value="form.refill_amount"\n @input="form.refill_amount = Number($el.value)"\n placeholder="0 = disabled"\n />\n\n <label style="opacity:.7;">Refill Every (ms)</label>\n <input type="number" min="0"\n :value="form.refill_every"\n @input="form.refill_every = Number($el.value)"\n placeholder="e.g. 60000 for 1 min"\n />\n\n </div>\n\n <div style="display:flex; gap:10px; justify-content:flex-end; margin-top:4px;">\n <button @click="cancel()">Cancel</button>\n <button @click="save()" :disabled="busy || !form.id">\n {{ busy ? \'Creating…\' : \'Create\' }}\n </button>\n </div>\n\n</div>\n'};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import e from"../../../stores/okdb-store.js";export default{tag:"edit-bucket-modal",attr:{modal:{},editMode:{},initialForm:{},onDone:{}},context(t){const n=t.$attr.initialForm??{};return{busy:!1,error:null,form:{id:n.id??"",capacity:n.capacity??100,tokens:n.tokens??100,refill_amount:n.refill_amount??0,refill_every:n.refill_every??0},get editMode(){return!!t.$attr.editMode},async save(){const n=String(this.form.id||"").trim();if(n){this.busy=!0,this.error=null;try{const i=this.editMode?`${e.apiBase}/queue/bucket/update/${encodeURIComponent(n)}`:`${e.apiBase}/queue/bucket/add/${encodeURIComponent(n)}`,a=await fetch(i,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({capacity:Number(this.form.capacity)||0,tokens:Number(this.form.tokens)??0,refill_amount:Number(this.form.refill_amount)||0,refill_every:Number(this.form.refill_every)||0})}),r=await a.json();if(!a.ok)throw new Error(r?.error?.message||"Save failed");t.$ok.shared?.toast?.success?.(this.editMode?"Bucket updated":"Bucket created"),await t.$attr.modal.close(),await(t.$attr.onDone?.())}catch(e){this.error=e?.message||"Save failed"}finally{this.busy=!1}}else this.error="Bucket ID is required"},cancel(){t.$attr.modal.close()}}},template:'\n<div style="min-width:320px; display:flex; flex-direction:column; gap:12px;">\n\n <if :="error">\n <div style="color:var(--okdb-danger); font-size:12px; padding:8px; border:1px solid var(--okdb-danger); border-radius:6px;">{{ error }}</div>\n </if>\n\n <div style="display:grid; grid-template-columns:120px 1fr; gap:8px 12px; align-items:center; font-size:13px;">\n\n <label style="opacity:.7;">Bucket ID</label>\n <input\n :value="form.id"\n @input="form.id = $el.value"\n :disabled="editMode"\n placeholder="e.g. openai-api"\n style="font-family:monospace;"\n @keydown:enter="save()"\n />\n\n <label style="opacity:.7;">Capacity</label>\n <input type="number" min="1" :value="form.capacity" @input="form.capacity = Number($el.value)" />\n\n <label style="opacity:.7;">Initial Tokens</label>\n <input type="number" min="0" :value="form.tokens" @input="form.tokens = Number($el.value)" />\n\n <div style="grid-column:1/-1; height:1px; background:var(--okdb-app-border); margin:4px 0;"></div>\n\n <div style="grid-column:1/-1; font-size:11px; opacity:.5; text-transform:uppercase; letter-spacing:.05em;">\n Auto-Refill (optional)\n </div>\n\n <label style="opacity:.7;">Refill Amount</label>\n <input type="number" min="0" :value="form.refill_amount"\n @input="form.refill_amount = Number($el.value)" placeholder="0 = disabled" />\n\n <label style="opacity:.7;">Refill Every (ms)</label>\n <input type="number" min="0" :value="form.refill_every"\n @input="form.refill_every = Number($el.value)" placeholder="e.g. 60000 for 1 min" />\n\n </div>\n\n <div style="display:flex; gap:10px; justify-content:flex-end; margin-top:4px;">\n <button @click="cancel()">Cancel</button>\n <button @click="save()" :disabled="busy || !form.id">\n {{ busy ? \'Saving…\' : (editMode ? \'Save\' : \'Create\') }}\n </button>\n </div>\n\n</div>\n'};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import e from"@toolkit/elements/ok-icon.ok.js";import t from"@toolkit/core/ok-overlay.ok.js";import n from"../../../components/ok-cron-input.ok.js";import a from"../../../components/ok-json-input.ok.js";import i from"./create-bucket-modal.ok.js";import s from"../../../stores/okdb-store.js";export default{tag:"edit-job-modal",dependencies:[n,a,i,t,e],attr:{modal:{},jobId:{},onDone:{}},context:e=>({busy:!1,loading:!1,job:null,type:"",payloadInit:{},payload:{},priority:0,maxTries:null,retryDelay:0,backoff:1,tags:"",buckets:[],cron:"",idempotencyKey:"",whenMode:"asap",whenDatetime:"",whenTs:null,progress:"",statusMessage:"",bucketOptions:[],async loadBuckets(){try{const e=await fetch(s.apiBase+"/queue/buckets"),t=await e.json();this.bucketOptions=t?.data??[]}catch{this.bucketOptions=[]}},async onBucketSelect(t,n){if("__create__"===n){const n=this;await e.$ok.shared.modal.open({owner:e,title:"Add Token Bucket",content:'<create-bucket-modal :modal="modal" :on-done="onDone" />',context:e=>({modal:e,onDone:async e=>{await n.loadBuckets(),n.buckets=n.buckets.map((n,a)=>a===t?{...n,id:e}:n)}})})}else this.buckets=this.buckets.map((e,a)=>a===t?{...e,id:n}:e)},setBucketTokens(e,t){const n=""===t?1:Math.max(1,parseInt(t)||1);this.buckets=this.buckets.map((t,a)=>a===e?{...t,tokens:n}:t)},addBucket(){this.buckets=[...this.buckets,{id:"",tokens:1}]},removeBucket(e){this.buckets=this.buckets.filter((t,n)=>n!==e)},getWhen(){if("asap"===this.whenMode)return null;if("datetime"===this.whenMode){const e=new Date(this.whenDatetime);return isNaN(e.getTime())?null:e.getTime()}return this.whenTs},_parseTags(e){if(!e)return;const t=String(e).split(",").map(e=>e.trim()).filter(Boolean);return t.length?t:void 0},applyJob(e){e&&(this.type=e.type??"",this.payloadInit=e.payload??{},this.payload=e.payload??{},this.priority=e.priority??0,this.maxTries=e.max_tries??null,this.retryDelay=e.retry_delay??0,this.backoff=e.backoff_multiplier??1,this.tags=Array.isArray(e.tags)?e.tags.join(", "):"",this.cron=e.cron??"",this.idempotencyKey=e?.idempotency_key||"",this.progress=e.progress??"",this.statusMessage=e.status_message??"",e.when&&e.when>Date.now()-1e3?(this.whenMode="timestamp",this.whenDatetime=new Date(e.when).toISOString().slice(0,16),this.whenTs=e.when):(this.whenMode="asap",this.whenDatetime="",this.whenTs=null),Array.isArray(e.buckets)&&e.buckets.length>0?this.buckets=e.buckets.map(e=>({id:e.id,tokens:e.tokens??1})):e.bucket?this.buckets=[{id:e.bucket,tokens:e.bucket_tokens??1}]:this.buckets=[])},async load(){this.loading=!0;try{const t=await fetch(s.apiBase+"/queue/job/"+encodeURIComponent(e.$attr.jobId)),n=await t.json();if(!t.ok)throw new Error(n?.error?.message||"Failed to load job");this.job=n?.data??null,this.applyJob(this.job)}catch(t){e.$ok.shared?.toast?.error?.(t?.message||"Failed to load job"),await e.$attr.modal.close()}finally{this.loading=!1}},async save(){if(this.job){this.busy=!0;try{const t=this.getWhen(),n=String(this.cron||"").trim()||null,a=this.buckets.filter(e=>e.id).map(e=>({id:e.id,tokens:e.tokens||1})),i=this._parseTags(this.tags),l={type:String(this.type||"").trim(),payload:this.payload,when:t,priority:Number(this.priority)||0,tags:i??this.job.tags,buckets:a,cron:n,max_tries:null!==this.maxTries&&""!==this.maxTries?Number(this.maxTries):null,retry_delay:Number(this.retryDelay)||0,backoff_multiplier:Number(this.backoff)||1,progress:this.progress||null,status_message:this.statusMessage||null,idempotency_key:this.idempotencyKey.trim()||null},o=await fetch(s.apiBase+"/queue/job/"+encodeURIComponent(this.job.id)+"/update",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)}),d=await o.json();if(!o.ok)throw new Error(d?.error?.message||"Failed to save job");e.$ok.shared?.toast?.success?.("Job updated"),await e.$attr.modal.close(),await(e.$attr.onDone?.(d?.data??null))}catch(t){e.$ok.shared?.toast?.error?.(t?.message||"Failed to save job")}finally{this.busy=!1}}},cancel(){e.$attr.modal.close()}}),async mount(){await Promise.all([this.load(),this.loadBuckets()])},template:'\n<div style="position:relative; min-width:720px; max-width:calc(100vw - 80px); display:flex; flex-direction:column; gap:12px;">\n <if :="busy || loading">\n <ok-overlay>\n <div class="loader-center">\n <ok-icon name="loader" class="spin" style="width:32px;height:32px;"></ok-icon>\n </div>\n </ok-overlay>\n </if>\n\n <div style="display:flex; gap:8px; align-items:center; flex-wrap:wrap; opacity:.8; font-size:12px;">\n <span>ID: <b>{{ job?.id }}</b></span>\n <span>Status: <b>{{ job?.status }}</b></span>\n <span>Tries: <b>{{ job?.tries }} / {{ job?.max_tries }}</b></span>\n </div>\n\n \x3c!-- Row 1: type + priority --\x3e\n <div style="display:flex; gap:8px; align-items:flex-end;">\n <div class="field" style="flex:1;"><label>Type</label>\n <input placeholder="e.g. email.send" :value="type" @input="type = $el.value" />\n </div>\n <div class="field" style="width:120px;"><label>Priority</label>\n <input type="number" placeholder="0" :value="priority" @input="priority = Number($el.value)" />\n </div>\n </div>\n\n \x3c!-- Row 2: tags + idempotency key --\x3e\n <div style="display:flex; gap:10px;">\n <div class="field" style="flex:1;"><label>Tags</label>\n <input placeholder="comma separated" :value="tags" @input="tags = $el.value" />\n </div>\n <div class="field" style="flex:1;"><label>Idempotency Key</label>\n <input placeholder="optional — prevents duplicate jobs" :value="idempotencyKey" @input="idempotencyKey = $el.value" />\n </div>\n </div>\n\n \x3c!-- Buckets --\x3e\n <div class="field">\n <label>Buckets <span style="opacity:.4; font-weight:400; font-size:11px;">(rate limiting)</span></label>\n <each :of="buckets" let:item="b" let:index="i">\n <div style="display:flex; gap:6px; align-items:center; margin-bottom:4px;">\n <select style="flex:1;" @change="onBucketSelect(i, $el.value)">\n <option value="">— none —</option>\n <option as="repeat" :of="bucketOptions" let:item="opt" :value="opt.id" :selected="opt.id === b.id">{{ opt.id }}</option>\n <option value="__create__">+ Create bucket…</option>\n </select>\n <input style="width:72px;" type="number" min="1" placeholder="tokens"\n :value="b.tokens"\n @input="setBucketTokens(i, $el.value)" />\n <button class="btn-ghost" @click="removeBucket(i)" title="Remove">✕</button>\n </div>\n </each>\n <button class="btn-ghost btn-ghost--sm" @click="addBucket()" style="margin-top:2px;">+ Add bucket</button>\n </div>\n\n \x3c!-- Row 3: when + max tries --\x3e\n <div style="display:flex; gap:8px; align-items:flex-end;">\n <div class="field" style="flex:1;">\n <label>When</label>\n <div style="display:flex; gap:4px; align-items:center;">\n <button :class="whenMode===\'asap\' ? \'mode-btn mode-btn--on\' : \'mode-btn\'" @click="whenMode=\'asap\'">ASAP</button>\n <button :class="whenMode===\'datetime\' ? \'mode-btn mode-btn--on\' : \'mode-btn\'" @click="whenMode=\'datetime\'">Date</button>\n <button :class="whenMode===\'timestamp\' ? \'mode-btn mode-btn--on\' : \'mode-btn\'" @click="whenMode=\'timestamp\'">TS</button>\n <if :="whenMode === \'datetime\'">\n <input type="datetime-local" style="flex:1;" :value="whenDatetime" @input="whenDatetime = $el.value" />\n </if>\n <if :="whenMode === \'timestamp\'">\n <input type="number" style="flex:1;" placeholder="ms timestamp" :value="whenTs" @input="whenTs = $el.value === \'\' ? null : Number($el.value)" />\n </if>\n <if :="whenMode === \'asap\'">\n <span style="opacity:.5; font-size:12px; padding:0 8px;">Run immediately</span>\n </if>\n </div>\n </div>\n <div class="field" style="width:120px;"><label>Max tries</label>\n <input type="number" placeholder="unlimited" :value="maxTries" @input="maxTries = $el.value === \'\' ? null : Number($el.value)" />\n </div>\n </div>\n\n \x3c!-- Row 4: retry delay + backoff + cron --\x3e\n <div style="display:flex; gap:8px; align-items:flex-end;">\n <div class="field" style="flex:1;"><label>Retry delay (ms)</label>\n <input type="number" placeholder="0" :value="retryDelay" @input="retryDelay = Number($el.value)" />\n </div>\n <div class="field" style="width:120px;"><label>Backoff multiplier</label>\n <input type="number" step="0.1" placeholder="1" :value="backoff" @input="backoff = Number($el.value)" />\n </div>\n <div class="field" style="flex:1;"><label>Cron</label>\n <ok-cron-input :value="cron" placeholder="optional" @change="cron = $event.detail" />\n </div>\n </div>\n\n \x3c!-- Row 5: progress + status message (edit-specific) --\x3e\n <div style="display:flex; gap:8px; align-items:flex-end;">\n <div class="field" style="flex:1;"><label>Progress</label>\n <input placeholder="—" :value="progress" @input="progress = $el.value" />\n </div>\n <div class="field" style="flex:1;"><label>Status message</label>\n <input placeholder="—" :value="statusMessage" @input="statusMessage = $el.value" />\n </div>\n </div>\n\n \x3c!-- Payload --\x3e\n <div style="display:flex; flex-direction:column; gap:6px;">\n <span style="opacity:.7; font-size:12px;">Payload</span>\n <ok-json-input\n mode="textarea"\n style="height:260px;"\n :value="payloadInit"\n @edit="payload = $event.detail"\n />\n </div>\n\n <div style="display:flex; gap:10px; justify-content:flex-end;">\n <button @click="cancel()">Cancel</button>\n <button @click="save()" :disabled="busy || loading || !type">Save</button>\n </div>\n</div>\n',style:".mode-btn{font-size:11px;padding:2px 8px;opacity:.6;border-radius:4px}.mode-btn--on{opacity:1;background:color-mix(in srgb,var(--okdb-accent) 13%,transparent);border-color:color-mix(in srgb,var(--okdb-accent) 33%,transparent);color:var(--okdb-accent)}.btn-ghost{background:0 0;border:1px solid var(--okdb-app-border);border-radius:5px;color:inherit;cursor:pointer;opacity:.6;padding:2px 8px;font-size:12px}.btn-ghost:hover{opacity:1;border-color:color-mix(in srgb,var(--okdb-accent) 33%,transparent)}.btn-ghost--sm{font-size:11px;padding:1px 7px}"};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import e from"@toolkit/elements/ok-icon.ok.js";import t from"@toolkit/core/ok-overlay.ok.js";import n from"../../../components/ok-cron-input.ok.js";import a from"../../../components/ok-json-input.ok.js";import i from"../../../components/field-path-input.ok.js";import s from"./create-bucket-modal.ok.js";import l from"../../../stores/okdb-store.js";export default{tag:"enqueue-job-modal",dependencies:[n,a,i,s,t,e],attr:{modal:{},initialType:{},onDone:{}},context:e=>({busy:!1,type:e.$attr.initialType??"",payloadInit:{},payload:{},priority:0,maxTries:null,retryDelay:0,backoff:1,tags:"",buckets:[{id:"",tokens:1}],cron:"",idempotencyKey:"",whenMode:"asap",whenDatetime:"",whenTs:null,doneTtl:null,failedTtl:null,bucketOptions:[],registeredTypes:[],typeItems:[],typeIsRegistered:!1,typeStatus:null,typeSchema:null,_fromType:{},payloadErrors:[],_payloadTouched:!1,_syncTypeData(){const e=this.registeredTypes.find(e=>e.id===this.type)??null;this.typeIsRegistered=!!e,this.typeStatus=e?.status??null,this.typeSchema=e?.payload_schema??null,this.typeItems=this.registeredTypes.map(e=>({path:e.id,types:e.status&&"active"!==e.status?[e.status]:[],hint:null}))},_set(e,t){if(this[e]=t,this._fromType[e]){const t={...this._fromType};delete t[e],this._fromType=t}},async loadBuckets(){const[e,t]=await Promise.all([fetch(l.apiBase+"/queue/buckets").catch(()=>null),fetch(l.apiBase+"/queue/job-types").catch(()=>null)]);if(e?.ok){const t=await e.json().catch(()=>({}));this.bucketOptions=t?.result??t?.data??[]}if(t?.ok){const e=await t.json().catch(()=>({}));this.registeredTypes=e?.result??e?.data??[]}this._syncTypeData()},applyTypeDefaults(e){const t=this.registeredTypes.find(t=>t.id===e);if(!t)return!1;const n=t.defaults??{},a={};return null!=n.max_tries&&(this.maxTries=n.max_tries,a.maxTries=!0),null!=n.retry_delay&&(this.retryDelay=n.retry_delay,a.retryDelay=!0),null!=n.backoff_multiplier&&(this.backoff=n.backoff_multiplier,a.backoff=!0),null!=n.priority&&(this.priority=n.priority,a.priority=!0),null!=n.done_ttl&&(this.doneTtl=n.done_ttl,a.doneTtl=!0),null!=n.failed_ttl&&(this.failedTtl=n.failed_ttl,a.failedTtl=!0),Array.isArray(n.buckets)&&n.buckets.length&&(this.buckets=n.buckets.map(e=>({id:e.id,tokens:e.tokens??1})),a.buckets=!0),this._fromType=a,!0},onTypeSelected(e){null!=e&&(this.type=e,this._syncTypeData(),this.applyTypeDefaults(e)||e||(this._fromType={}),this._revalidatePayload())},async onBucketSelect(t,n){if(this._fromType.buckets&&(this._fromType={...this._fromType,buckets:!1}),"__create__"===n){const n=this;await e.$ok.shared.modal.open({owner:e,title:"Add Token Bucket",content:'<create-bucket-modal :modal="modal" :on-done="onDone" />',context:e=>({modal:e,onDone:async e=>{await n.loadBuckets(),n.buckets=n.buckets.map((n,a)=>a===t?{...n,id:e}:n)}})})}else this.buckets=this.buckets.map((e,a)=>a===t?{...e,id:n}:e)},setBucketTokens(e,t){this._fromType.buckets&&(this._fromType={...this._fromType,buckets:!1});const n=""===t?1:Math.max(1,parseInt(t)||1);this.buckets=this.buckets.map((t,a)=>a===e?{...t,tokens:n}:t)},addBucket(){this._fromType.buckets&&(this._fromType={...this._fromType,buckets:!1}),this.buckets=[...this.buckets,{id:"",tokens:1}]},removeBucket(e){this._fromType.buckets&&(this._fromType={...this._fromType,buckets:!1}),this.buckets=this.buckets.filter((t,n)=>n!==e)},onPayloadChange(e){this.payload=e,this._payloadTouched=!0,this._revalidatePayload()},_revalidatePayload(){const e=this.typeSchema;this.payloadErrors=e?.definition?this._validatePayload(this.payload,e.definition):[]},_validatePayload(e,t){const n=[],a=(e,t,i)=>{if(t&&"object"==typeof t&&!t.$ref){if(t.type){const a=Array.isArray(t.type)?t.type:[t.type],s=null===e?"null":Array.isArray(e)?"array":typeof e;if(!a.some(t=>t===s||"integer"===t&&"number"===s&&Number.isInteger(e)))return void n.push({path:i||"(root)",msg:`expected ${a.join(" | ")}, got ${s}`})}if(t.enum&&!t.enum.some(t=>JSON.stringify(t)===JSON.stringify(e))&&n.push({path:i||"(root)",msg:`must be one of [${t.enum.map(e=>JSON.stringify(e)).join(", ")}]`}),"string"==typeof e&&(null!=t.minLength&&e.length<t.minLength&&n.push({path:i||"(root)",msg:`minLength: ${t.minLength}`}),null!=t.maxLength&&e.length>t.maxLength&&n.push({path:i||"(root)",msg:`maxLength: ${t.maxLength}`}),t.pattern))try{new RegExp(t.pattern).test(e)||n.push({path:i||"(root)",msg:"pattern mismatch"})}catch{}if("number"==typeof e&&(null!=t.minimum&&e<t.minimum&&n.push({path:i||"(root)",msg:`>= ${t.minimum}`}),null!=t.maximum&&e>t.maximum&&n.push({path:i||"(root)",msg:`<= ${t.maximum}`})),"object"==typeof e&&null!==e&&!Array.isArray(e)){for(const a of t.required??[])a in e||n.push({path:i?`${i}.${a}`:a,msg:"required"});if(t.properties){for(const[n,s]of Object.entries(t.properties))n in e&&a(e[n],s,i?`${i}.${n}`:n);if(!1===t.additionalProperties)for(const a of Object.keys(e))a in t.properties||n.push({path:i?`${i}.${a}`:a,msg:"additional property not allowed"})}}if(Array.isArray(e)&&t.items&&e.forEach((e,n)=>a(e,t.items,`${i||""}[${n}]`)),t.allOf)for(const n of t.allOf)a(e,n,i)}};return a(e,t,""),n},getWhen(){if("asap"===this.whenMode)return null;if("datetime"===this.whenMode){const e=new Date(this.whenDatetime);return isNaN(e.getTime())?null:e.getTime()}return this.whenTs},_parseTags(e){if(!e)return;const t=String(e).split(",").map(e=>e.trim()).filter(Boolean);return t.length?t:void 0},async submit(){if(!this.type)return void e.$ok.shared?.toast?.error?.("Please enter a job type");if(this.typeSchema?.definition){const t=this._validatePayload(this.payload,this.typeSchema.definition);if(t.length)return this._payloadTouched=!0,this.payloadErrors=t,void e.$ok.shared?.toast?.error?.("Payload does not match the job type schema")}const t=this.getWhen(),n=String(this.cron||"").trim()||null,a=this.buckets.filter(e=>e.id).map(e=>({id:e.id,tokens:e.tokens||1})),i=this._parseTags(this.tags),s={};null!=t&&(s.when=t),this.priority&&(s.priority=Number(this.priority)),null!==this.maxTries&&""!==this.maxTries&&(s.max_tries=Number(this.maxTries)),this.retryDelay&&(s.retry_delay=Number(this.retryDelay)),1!==this.backoff&&(s.backoff_multiplier=Number(this.backoff)),i&&(s.tags=i),a.length&&(s.buckets=a),n&&(s.cron=n),this.idempotencyKey.trim()&&(s.idempotency_key=this.idempotencyKey.trim()),null!==this.doneTtl&&""!==this.doneTtl&&(s.done_ttl=Number(this.doneTtl)),null!==this.failedTtl&&""!==this.failedTtl&&(s.failed_ttl=Number(this.failedTtl)),this.busy=!0;try{const t=await fetch(l.apiBase+"/queue/enqueue/"+encodeURIComponent(this.type),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({payload:this.payload,options:s})});if(!t.ok){const e=await t.json().catch(()=>({}));throw new Error(e?.error?.message||e?.message||"enqueue failed")}await e.$attr.modal.close(),await(e.$attr.onDone?.())}catch(t){e.$ok.shared?.toast?.error?.(t.message||"Failed to enqueue job")}finally{this.busy=!1}},cancel(){e.$attr.modal.close()}}),async mount(e){await this.loadBuckets(),this.type&&this.applyTypeDefaults(this.type)},template:'\n<div style="position:relative; min-width:720px; max-width:calc(100vw - 80px); display:flex; flex-direction:column; gap:12px;">\n\n <if :="busy">\n <ok-overlay>\n <div class="loader-center">\n <ok-icon name="loader" class="spin" style="width:32px;height:32px;"></ok-icon>\n </div>\n </ok-overlay>\n </if>\n\n \x3c!-- Row 1: type + priority --\x3e\n <div style="display:flex; gap:8px; align-items:flex-end;">\n <div class="field" style="flex:1;">\n <label style="display:flex; align-items:center; gap:6px;">\n Type\n <if :="typeIsRegistered && typeStatus === \'active\'">\n <span class="type-pill type-pill--ok">registered</span>\n </if>\n <if :="typeStatus === \'paused\'">\n <span class="type-pill type-pill--warn">paused</span>\n </if>\n <if :="typeStatus === \'draining\'">\n <span class="type-pill type-pill--info">draining</span>\n </if>\n </label>\n <field-path-input\n :allow-custom="true"\n :value="type"\n :items="typeItems"\n placeholder="e.g. email.send"\n @change="onTypeSelected($event.detail)"\n />\n </div>\n <div class="field" style="width:120px;">\n <label style="display:flex; align-items:center; gap:5px;">\n Priority\n <if :="_fromType.priority"><span class="auto-badge">auto</span></if>\n </label>\n <input type="number" placeholder="0" :value="priority" @input="_set(\'priority\', Number($el.value))" />\n </div>\n </div>\n\n \x3c!-- Row 2: tags + idempotency key --\x3e\n <div style="display:flex; gap:10px;">\n <div class="field" style="flex:1;"><label>Tags</label>\n <input placeholder="comma separated" :value="tags" @input="tags = $el.value" />\n </div>\n <div class="field" style="flex:1;"><label>Idempotency Key</label>\n <input placeholder="optional — prevents duplicate jobs" :value="idempotencyKey" @input="idempotencyKey = $el.value" />\n </div>\n </div>\n\n \x3c!-- Buckets --\x3e\n <div class="field">\n <label style="display:flex; align-items:center; gap:5px;">\n Buckets <span style="opacity:.4; font-weight:400; font-size:11px;">(rate limiting)</span>\n <if :="_fromType.buckets"><span class="auto-badge">auto</span></if>\n </label>\n <each :of="buckets" let:item="b" let:index="i">\n <div style="display:flex; gap:6px; align-items:center; margin-bottom:4px;">\n <select style="flex:1;" @change="onBucketSelect(i, $el.value)">\n <option value="">— none —</option>\n <option as="repeat" :of="bucketOptions" let:item="opt" :value="opt.id" :selected="opt.id === b.id">{{ opt.id }}</option>\n <option value="__create__">+ Create bucket…</option>\n </select>\n <input style="width:72px;" type="number" min="1" placeholder="tokens"\n :value="b.tokens"\n @input="setBucketTokens(i, $el.value)" />\n <button class="btn-ghost" @click="removeBucket(i)" title="Remove">✕</button>\n </div>\n </each>\n <button class="btn-ghost btn-ghost--sm" @click="addBucket()" style="margin-top:2px;">+ Add bucket</button>\n </div>\n\n \x3c!-- Row 3: when + max tries --\x3e\n <div style="display:flex; gap:8px; align-items:flex-end;">\n <div class="field" style="flex:1;">\n <label>When</label>\n <div style="display:flex; gap:4px; align-items:center;">\n <button :class="whenMode===\'asap\' ? \'mode-btn mode-btn--on\' : \'mode-btn\'" @click="whenMode=\'asap\'">ASAP</button>\n <button :class="whenMode===\'datetime\' ? \'mode-btn mode-btn--on\' : \'mode-btn\'" @click="whenMode=\'datetime\'">Date</button>\n <button :class="whenMode===\'timestamp\' ? \'mode-btn mode-btn--on\' : \'mode-btn\'" @click="whenMode=\'timestamp\'">TS</button>\n <if :="whenMode === \'datetime\'">\n <input type="datetime-local" style="flex:1;" :value="whenDatetime" @input="whenDatetime = $el.value" />\n </if>\n <if :="whenMode === \'timestamp\'">\n <input type="number" style="flex:1;" placeholder="ms timestamp" :value="whenTs" @input="whenTs = $el.value === \'\' ? null : Number($el.value)" />\n </if>\n <if :="whenMode === \'asap\'">\n <span style="opacity:.5; font-size:12px; padding:0 8px;">Run immediately</span>\n </if>\n </div>\n </div>\n <div class="field" style="width:120px;">\n <label style="display:flex; align-items:center; gap:5px;">\n Max tries\n <if :="_fromType.maxTries"><span class="auto-badge">auto</span></if>\n </label>\n <input type="number" placeholder="unlimited" :value="maxTries" @input="_set(\'maxTries\', $el.value === \'\' ? null : Number($el.value))" />\n </div>\n </div>\n\n \x3c!-- Row 4: retry delay + backoff + cron --\x3e\n <div style="display:flex; gap:8px; align-items:flex-end;">\n <div class="field" style="flex:1;">\n <label style="display:flex; align-items:center; gap:5px;">\n Retry delay (ms)\n <if :="_fromType.retryDelay"><span class="auto-badge">auto</span></if>\n </label>\n <input type="number" placeholder="0" :value="retryDelay" @input="_set(\'retryDelay\', Number($el.value))" />\n </div>\n <div class="field" style="width:120px;">\n <label style="display:flex; align-items:center; gap:5px;">\n Backoff multiplier\n <if :="_fromType.backoff"><span class="auto-badge">auto</span></if>\n </label>\n <input type="number" step="0.1" placeholder="1" :value="backoff" @input="_set(\'backoff\', Number($el.value))" />\n </div>\n <div class="field" style="flex:1;"><label>Cron</label>\n <ok-cron-input :value="cron" placeholder="optional" @change="cron = $event.detail" />\n </div>\n </div>\n\n \x3c!-- Row 5: retention TTLs --\x3e\n <div style="display:flex; gap:8px; align-items:flex-end;">\n <div class="field" style="flex:1;">\n <label style="display:flex; align-items:center; gap:5px;">\n Done TTL (ms)\n <if :="_fromType.doneTtl"><span class="auto-badge">auto</span></if>\n </label>\n <input type="number" min="0" placeholder="0 = delete immediately, blank = keep forever" :value="doneTtl"\n @input="_set(\'doneTtl\', $el.value === \'\' ? null : Number($el.value))" />\n </div>\n <div class="field" style="flex:1;">\n <label style="display:flex; align-items:center; gap:5px;">\n Failed TTL (ms)\n <if :="_fromType.failedTtl"><span class="auto-badge">auto</span></if>\n </label>\n <input type="number" min="0" placeholder="blank = keep forever" :value="failedTtl"\n @input="_set(\'failedTtl\', $el.value === \'\' ? null : Number($el.value))" />\n </div>\n </div>\n\n \x3c!-- Payload --\x3e\n <div style="display:flex; flex-direction:column; gap:6px;">\n <div style="display:flex; align-items:center; gap:8px;">\n <span style="opacity:.7; font-size:12px;">Payload</span>\n <if :="typeSchema">\n <span class="type-pill type-pill--schema">schema</span>\n <if :="payloadErrors.length === 0 && _payloadTouched">\n <span class="type-pill type-pill--ok" style="font-size:10px;">valid</span>\n </if>\n </if>\n </div>\n <ok-json-input\n mode="textarea"\n style="height:220px;"\n :value="payloadInit"\n @edit="onPayloadChange($event.detail)"\n />\n <if :="_payloadTouched && payloadErrors.length > 0">\n <div class="schema-errors">\n <each :of="payloadErrors" let:item="err">\n <div class="schema-error-row">\n <span class="schema-error-path">{{ err.path }}</span>\n <span class="schema-error-msg">{{ err.msg }}</span>\n </div>\n </each>\n </div>\n </if>\n </div>\n\n \x3c!-- Footer --\x3e\n <div style="display:flex; gap:10px; justify-content:flex-end;">\n <button @click="cancel()">Cancel</button>\n <button @click="submit()" :disabled="!type || busy">Enqueue</button>\n </div>\n\n</div>\n',style:".mode-btn{font-size:11px;padding:2px 8px;opacity:.6;border-radius:4px}.mode-btn--on{opacity:1;background:color-mix(in srgb,var(--okdb-accent) 13%,transparent);border-color:color-mix(in srgb,var(--okdb-accent) 33%,transparent);color:var(--okdb-accent)}.btn-ghost{background:0 0;border:1px solid var(--okdb-app-border);border-radius:5px;color:inherit;cursor:pointer;opacity:.6;padding:2px 8px;font-size:12px}.btn-ghost:hover{opacity:1;border-color:color-mix(in srgb,var(--okdb-accent) 33%,transparent)}.btn-ghost--sm{font-size:11px;padding:1px 7px}.type-pill{font-size:10px;padding:1px 6px;border-radius:999px;border:1px solid;font-weight:400}.type-pill--ok{border-color:color-mix(in srgb,var(--okdb-accent) 33%,transparent);color:var(--okdb-accent)}.type-pill--warn{border-color:#f59e0b;color:#f59e0b}.type-pill--info{border-color:#3b82f6;color:#3b82f6}.type-pill--schema{border-color:color-mix(in srgb,var(--okdb-accent) 33%,transparent);color:var(--okdb-accent)}.auto-badge{font-size:9px;padding:1px 5px;border-radius:999px;font-weight:600;letter-spacing:.04em;background:color-mix(in srgb,var(--okdb-accent) 12%,transparent);border:1px solid color-mix(in srgb,var(--okdb-accent) 25%,transparent);color:var(--okdb-accent);text-transform:uppercase}.schema-errors{display:flex;flex-direction:column;gap:3px;padding:8px 10px;border-radius:6px;border:1px solid color-mix(in srgb,#ef4444 40%,transparent);background:color-mix(in srgb,#ef4444 6%,transparent);font-size:11px;max-height:120px;overflow-y:auto}.schema-error-row{display:flex;gap:8px;align-items:baseline}.schema-error-path{font-family:monospace;color:#f87171;flex-shrink:0}.schema-error-msg{color:#fca5a5;opacity:.8}"};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import e from"@toolkit/core/ok-overlay.ok.js";import t from"@toolkit/elements/ok-icon.ok.js";import n from"./create-bucket-modal.ok.js";import i from"../../db/modals/schema-edit-modal.ok.js";import a from"../../../stores/okdb-store.js";export default{tag:"job-type-modal",dependencies:[e,t,n,i],attr:{modal:{},jobType:{},bucketOptions:{},onDone:{}},context:e=>({busy:!1,id:"",status:"active",maxConcurrency:"",defMaxTries:"",defRetryDelay:"",defBackoff:"",defPriority:"",defTtl:"",defDoneTtl:"",defFailedTtl:"",defBuckets:[{id:"",tokens:1}],bucketOptions:[],get isEdit(){return!!e.$attr.jobType},get hasSchema(){return!!e.$attr.jobType?.payload_schema},get schemaEnforce(){return e.$attr.jobType?.payload_schema?.enforce??!1},init(){this.bucketOptions=Array.isArray(e.$attr.bucketOptions)?e.$attr.bucketOptions:[];const t=e.$attr.jobType;if(!t)return;this.id=t.id??"",this.status=t.status??"active",this.maxConcurrency=null!=t.max_concurrency?String(t.max_concurrency):"";const n=t.defaults??{};this.defMaxTries=null!=n.max_tries?String(n.max_tries):"",this.defRetryDelay=null!=n.retry_delay?String(n.retry_delay):"",this.defBackoff=null!=n.backoff_multiplier?String(n.backoff_multiplier):"",this.defPriority=null!=n.priority?String(n.priority):"",this.defTtl=null!=n.ttl?String(n.ttl):"",this.defDoneTtl=null!=n.done_ttl?String(n.done_ttl):"",this.defFailedTtl=null!=n.failed_ttl?String(n.failed_ttl):"",this.defBuckets=Array.isArray(n.buckets)&&n.buckets.length?n.buckets.map(e=>({id:e.id,tokens:e.tokens??1})):[{id:"",tokens:1}]},parseOptInt(e){const t=parseInt(e);return isNaN(t)?null:t},parseOptFloat(e){const t=parseFloat(e);return isNaN(t)?null:t},async onBucketSelect(t,n){if("__create__"===n){const n=this;await e.$ok.shared.modal.open({owner:e,title:"Add Token Bucket",content:'<create-bucket-modal :modal="modal" :on-done="onDone" />',context:e=>({modal:e,onDone:async e=>{try{const e=await fetch(a.apiBase+"/queue/buckets"),t=await e.json();n.bucketOptions=t?.result??t?.data??[]}catch{}n.defBuckets=n.defBuckets.map((n,i)=>i===t?{...n,id:e}:n)}})})}else this.defBuckets=this.defBuckets.map((e,i)=>i===t?{...e,id:n}:e)},setBucketTokens(e,t){const n=""===t?1:Math.max(1,parseInt(t)||1);this.defBuckets=this.defBuckets.map((t,i)=>i===e?{...t,tokens:n}:t)},addBucket(){this.defBuckets=[...this.defBuckets,{id:"",tokens:1}]},removeBucket(e){this.defBuckets=this.defBuckets.filter((t,n)=>n!==e)},openSchema(){const t=this.id.trim()||(e.$attr.jobType?.id??"");if(!t)return void e.$ok.shared?.toast?.error?.("Save the job type first before editing its schema");const n=a.apiBase+"/queue/job-type/"+encodeURIComponent(t)+"/schema",i=a.apiBase+"/queue/job-type/"+encodeURIComponent(t)+"/sample-payloads";e.$ok.shared.modal.open({owner:e,title:`Payload Schema · ${t}`,canDrag:!0,content:'<schema-edit-modal :modal="modal" :type="type" :schema="schema" :save-url="saveUrl" :samples-url="samplesUrl" :hide-enforce="true" :on-done="onDone" />',context:a=>({modal:a,type:t,schema:e.$attr.jobType?.payload_schema??null,saveUrl:n,samplesUrl:i,onDone:()=>e.$attr.onDone?.()})})},async submit(){const t=this.id.trim();if(!t)return void e.$ok.shared?.toast?.error?.("Job type name is required");const n=this.defBuckets.filter(e=>e.id).map(e=>({id:e.id,tokens:e.tokens||1})),i={status:this.status},l=this.parseOptInt(this.maxConcurrency);null!=l&&(i.max_concurrency=l);const s={},o=this.parseOptInt(this.defMaxTries);null!=o&&(s.max_tries=o);const d=this.parseOptInt(this.defRetryDelay);null!=d&&(s.retry_delay=d);const r=this.parseOptFloat(this.defBackoff);null!=r&&(s.backoff_multiplier=r);const p=this.parseOptInt(this.defPriority);null!=p&&(s.priority=p);const c=this.parseOptInt(this.defTtl);null!=c&&(s.ttl=c);const u=this.parseOptInt(this.defDoneTtl);null!=u&&(s.done_ttl=u);const f=this.parseOptInt(this.defFailedTtl);null!=f&&(s.failed_ttl=f),n.length&&(s.buckets=n),Object.keys(s).length&&(i.defaults=s),this.busy=!0;try{const n=this.isEdit?a.apiBase+"/queue/job-type/"+encodeURIComponent(t):a.apiBase+"/queue/job-type",l=this.isEdit?"PUT":"POST",s=this.isEdit?i:{id:t,...i};if(!(await fetch(n,{method:l,headers:{"Content-Type":"application/json"},body:JSON.stringify(s)})).ok)throw new Error("failed");await e.$attr.modal.close(),await(e.$attr.onDone?.())}catch{e.$ok.shared?.toast?.error?.("Failed to save job type")}finally{this.busy=!1}},cancel(){e.$attr.modal.close()}}),mount(){this.init()},template:'\n<div style="position:relative; min-width:600px; max-width:calc(100vw - 80px); display:flex; flex-direction:column; gap:14px;">\n\n <if :="busy">\n <ok-overlay>\n <div style="display:flex;align-items:center;justify-content:center;height:100%;">\n <ok-icon name="loader" class="spin" style="width:28px;height:28px;"></ok-icon>\n </div>\n </ok-overlay>\n </if>\n\n \x3c!-- name + status + concurrency --\x3e\n <div style="display:flex; gap:8px; align-items:flex-end;">\n <div class="field" style="flex:1;">\n <label>Type name</label>\n <input placeholder="e.g. email.send" :value="id" @input="id = $el.value" :disabled="isEdit" />\n </div>\n <div class="field" style="width:150px;">\n <label>Status</label>\n <select :value="status" @change="status = $el.value">\n <option value="active">Active</option>\n <option value="paused">Paused</option>\n <option value="draining">Draining</option>\n </select>\n </div>\n <div class="field" style="width:140px;">\n <label>Max concurrency</label>\n <input type="number" min="1" placeholder="unlimited" :value="maxConcurrency" @input="maxConcurrency = $el.value" />\n </div>\n </div>\n\n <div style="height:1px; background:var(--okdb-app-border);"></div>\n <div style="font-size:11px; font-weight:600; text-transform:uppercase; letter-spacing:.06em; opacity:.5;">Defaults (applied when enqueueing without explicit values)</div>\n\n \x3c!-- retry defaults --\x3e\n <div style="display:flex; gap:8px; align-items:flex-end;">\n <div class="field" style="flex:1;">\n <label>Max tries</label>\n <input type="number" min="1" placeholder="queue default" :value="defMaxTries" @input="defMaxTries = $el.value" />\n </div>\n <div class="field" style="flex:1;">\n <label>Retry delay (ms)</label>\n <input type="number" min="0" placeholder="0" :value="defRetryDelay" @input="defRetryDelay = $el.value" />\n </div>\n <div class="field" style="flex:1;">\n <label>Backoff multiplier</label>\n <input type="number" min="1" step="0.1" placeholder="1" :value="defBackoff" @input="defBackoff = $el.value" />\n </div>\n <div class="field" style="width:110px;">\n <label>Priority</label>\n <input type="number" placeholder="0" :value="defPriority" @input="defPriority = $el.value" />\n </div>\n </div>\n\n \x3c!-- TTLs --\x3e\n <div style="display:flex; gap:8px; align-items:flex-end;">\n <div class="field" style="flex:1;">\n <label>Claim TTL (ms)</label>\n <input type="number" min="0" placeholder="queue default" :value="defTtl" @input="defTtl = $el.value" />\n </div>\n <div class="field" style="flex:1;">\n <label>Done TTL (ms)</label>\n <input type="number" min="0" placeholder="keep forever" :value="defDoneTtl" @input="defDoneTtl = $el.value" />\n </div>\n <div class="field" style="flex:1;">\n <label>Failed TTL (ms)</label>\n <input type="number" min="0" placeholder="keep forever" :value="defFailedTtl" @input="defFailedTtl = $el.value" />\n </div>\n </div>\n\n \x3c!-- default buckets --\x3e\n <div class="field">\n <label>Default buckets <span style="opacity:.4; font-weight:400; font-size:11px;">(rate limiting)</span></label>\n <each :of="defBuckets" let:item="b" let:index="i">\n <div style="display:flex; gap:6px; align-items:center; margin-bottom:4px;">\n <select style="flex:1;" @change="onBucketSelect(i, $el.value)">\n <option value="">— none —</option>\n <option as="repeat" :of="bucketOptions" let:item="opt" :value="opt.id" :selected="opt.id === b.id">{{ opt.id }}</option>\n <option value="__create__">+ Create bucket…</option>\n </select>\n <input style="width:72px;" type="number" min="1" placeholder="tokens"\n :value="b.tokens" @input="setBucketTokens(i, $el.value)" />\n <button class="btn-ghost" @click="removeBucket(i)" title="Remove">✕</button>\n </div>\n </each>\n <button class="btn-ghost btn-ghost--sm" @click="addBucket()">+ Add bucket</button>\n </div>\n\n \x3c!-- schema row (only shown in edit mode since we need the type to exist first) --\x3e\n <if :="isEdit">\n <div style="display:flex; align-items:center; gap:10px; padding:8px 12px; border:1px solid var(--okdb-app-border); border-radius:6px; background:var(--okdb-app-bg-deep);">\n <div style="flex:1; font-size:12px;">\n <span style="font-weight:600;">Payload Schema</span>\n <if :="hasSchema">\n <span style="margin-left:8px; font-size:10px; padding:1px 6px; border-radius:999px; border:1px solid color-mix(in srgb, var(--okdb-accent) 33%, transparent); color:var(--okdb-accent);">defined</span>\n <if :="schemaEnforce">\n <span style="margin-left:4px; font-size:10px; padding:1px 6px; border-radius:999px; border:1px solid #ef4444; color:#ef4444;">enforced</span>\n </if>\n </if>\n <if :="!hasSchema">\n <span style="margin-left:8px; opacity:.4; font-size:11px;">none</span>\n </if>\n </div>\n <button class="btn-ghost" @click="openSchema()">Edit schema…</button>\n </div>\n </if>\n <if :="!isEdit">\n <div style="font-size:11px; opacity:.45; padding:0 2px;">Save the type first, then edit its payload schema.</div>\n </if>\n\n \x3c!-- footer --\x3e\n <div style="display:flex; gap:10px; justify-content:flex-end;">\n <button @click="cancel()">Cancel</button>\n <button @click="submit()" :disabled="!id.trim() || busy">{{ isEdit ? \'Save\' : \'Register\' }}</button>\n </div>\n\n</div>\n',style:".btn-ghost{background:0 0;border:1px solid var(--okdb-app-border);border-radius:5px;color:inherit;cursor:pointer;opacity:.6;padding:2px 8px;font-size:12px}.btn-ghost:hover{opacity:1;border-color:color-mix(in srgb,var(--okdb-accent) 33%,transparent)}.btn-ghost--sm{font-size:11px;padding:1px 7px}"};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import e from"../../../stores/events-store.js";const t={info:"var(--okdb-accent)",warn:"var(--okdb-warning)",error:"var(--okdb-danger)",debug:"var(--okdb-app-fg-muted)"},l=Number.MAX_SAFE_INTEGER;export default{tag:"job-log-panel",attr:{jobId:{default:null},env:{default:null},job:{default:null},attempt:{default:null}},context(o){const n=()=>`${__ENV__.API}/env/${encodeURIComponent(o.$attr.env||"default")}/queue`;return{entries:[],cursor:null,loading:!1,error:null,level:null,source:"all",autoScroll:!0,_listRef:null,_unsubs:[],_scrollTimer:null,get syntheticEntries(){const e=o.$attr.job;if(!e)return[];const t=e.id,n=[];n.push({key:[t,0,0],value:{level:"info",message:`enqueued · priority ${e.priority??0} · type ${e.type}`,ts:e.created,_synthetic:!0}});const s=e.tries??0;return"running"===e.status&&s>=1?n.push({key:[t,s,-1],value:{level:"info",message:`attempt ${s} running`,ts:e.updated,_synthetic:!0}}):"pending"===e.status&&s>=1?n.push({key:[t,s,l],value:{level:"warn",message:`attempt ${s} failed — retry scheduled`,ts:e.updated,_synthetic:!0}}):"failed"===e.status?n.push({key:[t,s,l],value:{level:"error",message:`failed: ${e.status_message||e.status_code||"unknown"}`,ts:e.finished,_synthetic:!0}}):"done"===e.status&&n.push({key:[t,s,l],value:{level:"info",message:"done",ts:e.finished,_synthetic:!0}}),null!=o.$attr.attempt?n.filter(e=>e.key[1]===Number(o.$attr.attempt)):n},get mergedEntries(){const e=[...this.syntheticEntries,...this.entries];return e.sort((e,t)=>e.key[1]-t.key[1]||e.key[2]-t.key[2]),e},get filteredEntries(){let e=this.mergedEntries;return"log"===this.source?e=e.filter(e=>!e.value._synthetic):"event"===this.source&&(e=e.filter(e=>e.value._synthetic)),this.level&&(e=e.filter(e=>e.value.level===this.level)),e},get hasMore(){return null!=this.cursor},async load(){if(o.$attr.jobId){this.loading=!0,this.error=null;try{const e=new URLSearchParams;null!=o.$attr.attempt&&e.set("attempt",String(o.$attr.attempt)),e.set("limit","500");const t=await fetch(`${n()}/job/${encodeURIComponent(o.$attr.jobId)}/logs?${e}`),l=await t.json();if(!t.ok)throw new Error(l?.error?.message||`HTTP ${t.status}`);this.entries=l.data||[],this.cursor=null}catch(e){this.error=e?.message||String(e)}finally{this.loading=!1}this._scheduleScroll()}},async loadMore(){if(this.cursor)try{const e=new URLSearchParams;null!=o.$attr.attempt&&e.set("attempt",String(o.$attr.attempt)),e.set("limit","500"),e.set("cursor",this.cursor);const t=await fetch(`${n()}/job/${encodeURIComponent(o.$attr.jobId)}/logs?${e}`),l=await t.json();if(!t.ok)throw new Error(l?.error?.message||`HTTP ${t.status}`);this.entries=[...this.entries,...l.data||[]],this.cursor=null}catch(e){this.error=e?.message||String(e)}},setLevel(e){this.level=this.level===e?null:e},setSource(e){this.source=e},levelColor:e=>t[e]||"var(--okdb-app-fg-muted)",fmtTime(e){if(!e)return"";const t=new Date(e);return t.toTimeString().slice(0,8)+"."+String(t.getMilliseconds()).padStart(3,"0")},fmtFields(e){try{return JSON.stringify(e)}catch{return""}},_scheduleScroll(){this.autoScroll&&this._listRef&&(clearTimeout(this._scrollTimer),this._scrollTimer=setTimeout(()=>{this._listRef&&(this._listRef.scrollTop=this._listRef.scrollHeight)},0))},onScroll(){const e=this._listRef;e&&(this.autoScroll=e.scrollTop+e.clientHeight>=e.scrollHeight-8)},_subscribeLive(){this._unsubs=[e.on("queue:log",e=>{e&&e.id===o.$attr.jobId&&(null!=o.$attr.attempt&&e.attempt!==Number(o.$attr.attempt)||(this.entries=[...this.entries,{key:[e.id,e.attempt,e.seq],value:{level:e.level,message:e.message,fields:null,ts:Date.now()}}],this._scheduleScroll()))})]}}},async init(e){await this.load(),e.$watch(()=>[e.$attr.jobId,e.$attr.attempt],()=>this.load())},mount(){this._subscribeLive()},unmount(){clearTimeout(this._scrollTimer);for(const e of this._unsubs)e();this._unsubs=[]},template:'\n <div class="joblog">\n <div class="joblog__toolbar">\n <span class="joblog__title">Logs</span>\n <div class="joblog__pills">\n <button @click="setSource(\'all\')" :class="source===\'all\' ? \'pill pill--on\' : \'pill\'">All</button>\n <button @click="setSource(\'log\')" :class="source===\'log\' ? \'pill pill--on\' : \'pill\'">Logs</button>\n <button @click="setSource(\'event\')" :class="source===\'event\' ? \'pill pill--on\' : \'pill\'">Lifecycle</button>\n </div>\n <span class="joblog__sep"></span>\n <div class="joblog__pills">\n <button @click="setLevel(null)" :class="level==null ? \'pill pill--on\' : \'pill\'">·</button>\n <button @click="setLevel(\'info\')" :class="level===\'info\' ? \'pill pill--on\' : \'pill\'" style="color:var(--okdb-accent)">info</button>\n <button @click="setLevel(\'warn\')" :class="level===\'warn\' ? \'pill pill--on\' : \'pill\'" style="color:var(--okdb-warning)">warn</button>\n <button @click="setLevel(\'error\')" :class="level===\'error\' ? \'pill pill--on\' : \'pill\'" style="color:var(--okdb-danger)">error</button>\n <button @click="setLevel(\'debug\')" :class="level===\'debug\' ? \'pill pill--on\' : \'pill\'" style="color:var(--okdb-app-fg-muted)">debug</button>\n </div>\n <span class="joblog__spacer"></span>\n <button @click="autoScroll = !autoScroll" :class="autoScroll ? \'pill pill--on\' : \'pill\'" title="Auto-scroll to newest">↓ Auto</button>\n <button @click="load()" class="pill" :disabled="loading">Refresh</button>\n <span class="joblog__count">{{ filteredEntries.length }}</span>\n </div>\n\n <if :="error">\n <div class="joblog__msgline joblog__error">{{ error }}</div>\n </if>\n <if :="!error && loading && entries.length === 0">\n <div class="joblog__msgline">Loading…</div>\n </if>\n <if :="!error && !loading && filteredEntries.length === 0">\n <div class="joblog__msgline">No log entries.</div>\n </if>\n\n <div class="joblog__list" :ref="_listRef = $el" @scroll="onScroll()">\n <each :of="filteredEntries" let:item="entry">\n <div :class="entry.value._synthetic ? \'joblog__row joblog__row--synthetic\' : \'joblog__row\'">\n <span class="joblog__ts">{{ fmtTime(entry.value.ts) }}</span>\n <span class="joblog__level" :style="\'color:\' + levelColor(entry.value.level)">{{ entry.value.level }}</span>\n <if :="$attr.attempt == null">\n <span class="joblog__attempt">#{{ entry.key[1] }}</span>\n </if>\n <span class="joblog__msg">\n <if :="entry.value._synthetic">⟡ </if>{{ entry.value.message }}\n </span>\n <if :="entry.value.fields">\n <span class="joblog__fields" :title="fmtFields(entry.value.fields)">{{ fmtFields(entry.value.fields) }}</span>\n </if>\n </div>\n </each>\n <if :="hasMore">\n <button @click="loadMore()" class="pill joblog__more">Load older…</button>\n </if>\n </div>\n </div>\n ',style:"\n [tag] { display: block; }\n .joblog {\n display: flex;\n flex-direction: column;\n min-height: 160px;\n max-height: 420px;\n background: var(--okdb-app-bg-deep);\n border: 1px solid var(--okdb-app-border);\n border-radius: 8px;\n overflow: hidden;\n }\n .joblog__toolbar {\n display: flex;\n align-items: center;\n gap: 6px;\n padding: 6px 8px;\n background: var(--okdb-app-surface);\n border-bottom: 1px solid var(--okdb-app-border);\n flex-wrap: wrap;\n flex-shrink: 0;\n }\n .joblog__title { font-weight: 600; font-size: 12px; margin-right: 2px; }\n .joblog__pills { display: flex; gap: 3px; }\n .joblog__sep { width: 1px; height: 16px; background: var(--okdb-app-border); }\n .joblog__spacer { flex: 1; }\n .joblog__count { font-size: 11px; opacity: .4; }\n\n .pill {\n border: 1px solid var(--okdb-app-border);\n background: transparent;\n padding: 2px 8px;\n border-radius: 999px;\n font-size: 11px;\n cursor: pointer;\n color: var(--okdb-app-fg-faint);\n transition: border-color .12s, color .12s, background .12s;\n white-space: nowrap;\n }\n .pill:hover { border-color: var(--okdb-app-fg-muted); color: var(--okdb-app-fg-muted); }\n .pill--on { border-color: var(--okdb-accent); background: var(--okdb-app-surface-2); color: var(--okdb-accent); }\n\n .joblog__list {\n flex: 1;\n overflow-y: auto;\n font-family: var(--font-mono, monospace);\n font-size: 12px;\n padding: 2px 0;\n min-height: 0;\n }\n .joblog__row {\n display: flex;\n gap: 8px;\n padding: 2px 10px;\n border-bottom: 1px solid var(--okdb-app-bg-deep);\n align-items: baseline;\n min-height: 20px;\n }\n .joblog__row:hover { background: var(--okdb-app-surface); }\n .joblog__row--synthetic { font-style: italic; opacity: .8; }\n .joblog__ts { color: var(--okdb-app-fg-muted); flex-shrink: 0; font-size: 11px; user-select: none; width: 86px; }\n .joblog__level { width: 40px; flex-shrink: 0; font-weight: bold; font-size: 10px; text-transform: uppercase; letter-spacing: .04em; }\n .joblog__attempt { color: var(--okdb-app-fg-muted); flex-shrink: 0; font-size: 11px; width: 28px; }\n .joblog__msg { flex: 1; white-space: pre-wrap; word-break: break-word; color: var(--okdb-app-fg); min-width: 0; }\n .joblog__fields { color: var(--okdb-app-fg-muted); font-size: 11px; max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex-shrink: 0; }\n .joblog__msgline { padding: 18px 12px; opacity: .5; font-style: italic; font-size: 12px; }\n .joblog__error { color: var(--okdb-danger); opacity: .8; }\n .joblog__more { margin: 8px auto; display: block; }\n "};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import e from"../../../components/ok-cron-input.ok.js";import t from"../../../components/ok-json-input.ok.js";import n from"../modals/create-bucket-modal.ok.js";import i from"../../../stores/okdb-store.js";export default{tag:"ok-job-form",dependencies:[e,t,n],attr:{job:{},initialType:{}},context:e=>({type:"",payloadInit:{},payload:{},when:null,whenMode:"asap",whenDatetime:"",whenTs:null,priority:0,maxTries:null,retryDelay:0,backoff:1,tags:"",buckets:[],cron:"",idempotencyKey:"",bucketOptions:[],async loadBuckets(){try{const e=await fetch(i.apiBase+"/queue/buckets"),t=await e.json();this.bucketOptions=t?.data??[]}catch{this.bucketOptions=[]}},async onBucketSelect(t,n){if("__create__"===n){const n=this;await e.$ok.shared.modal.open({owner:e,title:"Add Token Bucket",content:'<create-bucket-modal :modal="modal" :on-done="onDone" />',context:e=>({modal:e,onDone:async e=>{await n.loadBuckets(),n.buckets=n.buckets.map((n,i)=>i===t?{...n,id:e}:n)}})})}else this.buckets=this.buckets.map((e,i)=>i===t?{...e,id:n}:e)},setBucketTokens(e,t){const n=""===t?1:Math.max(1,parseInt(t)||1);this.buckets=this.buckets.map((t,i)=>i===e?{...t,tokens:n}:t)},addBucket(){this.buckets=[...this.buckets,{id:"",tokens:1}]},removeBucket(e){this.buckets=this.buckets.filter((t,n)=>n!==e)},getWhen(){if("asap"===this.whenMode)return null;if("datetime"===this.whenMode){const e=new Date(this.whenDatetime);return isNaN(e.getTime())?null:e.getTime()}return this.whenTs},_parseTags(e){if(!e)return;const t=String(e).split(",").map(e=>e.trim()).filter(Boolean);return t.length?t:void 0},_emitChange(){const t=this.getWhen(),n=String(this.cron||"").trim();e.$el.dispatchEvent(new CustomEvent("form-change",{bubbles:!1,detail:{type:String(this.type||"").trim(),payload:this.payload,priority:Number(this.priority)||0,retry_delay:Number(this.retryDelay)||0,backoff_multiplier:Number(this.backoff)||1,max_tries:null!==this.maxTries&&""!==this.maxTries?Number(this.maxTries):null,buckets:this.buckets.filter(e=>e.id).map(e=>({id:e.id,tokens:e.tokens||1})),when:t,cron:n||null,tags:this._parseTags(this.tags),idempotency_key:this.idempotencyKey||null}}))},_populateFromJob(e){if(!e)return this.type="",this.payloadInit={},this.payload={},this.when=null,this.whenMode="asap",this.whenDatetime="",this.whenTs=null,this.priority=0,this.maxTries=null,this.retryDelay=0,this.backoff=1,this.tags="",this.buckets=[{id:"",tokens:1}],this.cron="",this.idempotencyKey="",void this._emitChange();this.type=e?.type??"",this.payloadInit=e?.payload??{},this.payload=e?.payload??{},this.when=e?.when??null,this.priority=e?.priority??0,this.maxTries=e?.max_tries??null,this.retryDelay=e?.retry_delay??0,this.backoff=e?.backoff_multiplier??1,this.tags=Array.isArray(e?.tags)?e.tags.join(", "):"",this.cron=e?.cron??"",this.idempotencyKey=e?.idempotency_key||"",e?.when&&e.when>Date.now()-1e3?(this.whenMode="timestamp",this.whenDatetime=new Date(e.when).toISOString().slice(0,16),this.whenTs=e.when):(this.whenMode="asap",this.whenDatetime="",this.whenTs=null),Array.isArray(e?.buckets)&&e.buckets.length>0?this.buckets=e.buckets.map(e=>({id:e.id,tokens:e.tokens??1})):this.buckets=e?.bucket?[{id:e.bucket,tokens:e.bucket_tokens??1}]:[],this._emitChange()}}),async mount(e){await this.loadBuckets(),this._populateFromJob(e.$attr.job??null),e.$attr.initialType&&(this.type=e.$attr.initialType),setTimeout(()=>this._emitChange(),0)},watch:{job(e){this._populateFromJob(e)},type(){this._emitChange()},payload(){this._emitChange()},priority(){this._emitChange()},retryDelay(){this._emitChange()},backoff(){this._emitChange()},maxTries(){this._emitChange()},buckets(){this._emitChange()},whenMode(){this._emitChange()},whenDatetime(){this._emitChange()},whenTs(){this._emitChange()},cron(){this._emitChange()},tags(){this._emitChange()},idempotencyKey(){this._emitChange()}},template:'\n<div style="display:flex; flex-direction:column; gap:10px;">\n\n \x3c!-- Row 1: type + priority --\x3e\n <div style="display:flex; gap:8px; align-items:flex-end;">\n <div class="field" style="flex:1;"><label>Type</label>\n <input placeholder="e.g. email.send" :value="type" @input="type = $el.value" />\n </div>\n <div class="field" style="width:120px;"><label>Priority</label>\n <input type="number" placeholder="0" :value="priority" @input="priority = Number($el.value)" />\n </div>\n </div>\n\n \x3c!-- Row 2: tags + idempotency key --\x3e\n <div style="display:flex; gap:8px; align-items:flex-end;">\n <div class="field" style="flex:1;"><label>Tags</label>\n <input placeholder="comma separated" :value="tags" @input="tags = $el.value" />\n </div>\n <div class="field" style="flex:1;">\n <label>Idempotency Key</label>\n <input type="text" placeholder="optional — prevents duplicate jobs"\n :value="idempotencyKey"\n @input="idempotencyKey = $el.value" />\n </div>\n </div>\n\n \x3c!-- Buckets --\x3e\n <div class="field">\n <label>Buckets <span style="opacity:.4; font-weight:400; font-size:11px;">(rate limiting)</span></label>\n <each :of="buckets" let:item="b" let:index="i">\n <div style="display:flex; gap:6px; align-items:center; margin-bottom:4px;">\n <select style="flex:1;" @change="onBucketSelect(i, $el.value)">\n <option value="">— none —</option>\n <option as="repeat" :of="bucketOptions" let:item="opt" :value="opt.id" :selected="opt.id === b.id">{{ opt.id }}</option>\n <option value="__create__">+ Create bucket…</option>\n </select>\n <input style="width:72px;" type="number" min="1" placeholder="tokens"\n :value="b.tokens"\n @input="setBucketTokens(i, $el.value)" />\n <button class="btn-ghost" @click="removeBucket(i)" title="Remove">✕</button>\n </div>\n </each>\n <button class="btn-ghost btn-ghost--sm" @click="addBucket()" style="margin-top:2px;">+ Add bucket</button>\n </div>\n\n \x3c!-- Row 3: when + max tries --\x3e\n <div style="display:flex; gap:8px; align-items:flex-end;">\n <div class="field" style="flex:1;">\n <label>When</label>\n <div style="display:flex; gap:4px; align-items:center;">\n <button :class="whenMode===\'asap\' ? \'mode-btn mode-btn--on\' : \'mode-btn\'" @click="whenMode=\'asap\'">ASAP</button>\n <button :class="whenMode===\'datetime\' ? \'mode-btn mode-btn--on\' : \'mode-btn\'" @click="whenMode=\'datetime\'">Date</button>\n <button :class="whenMode===\'timestamp\' ? \'mode-btn mode-btn--on\' : \'mode-btn\'" @click="whenMode=\'timestamp\'">TS</button>\n <if :="whenMode === \'datetime\'">\n <input type="datetime-local" style="flex:1;" :value="whenDatetime" @input="whenDatetime = $el.value" />\n </if>\n <if :="whenMode === \'timestamp\'">\n <input type="number" style="flex:1;" placeholder="ms timestamp" :value="whenTs" @input="whenTs = $el.value === \'\' ? null : Number($el.value)" />\n </if>\n <if :="whenMode === \'asap\'">\n <span style="opacity:.5; font-size:12px; padding:0 8px;">Run immediately</span>\n </if>\n </div>\n </div>\n <div class="field" style="width:120px;"><label>Max tries</label>\n <input type="number" placeholder="unlimited" :value="maxTries" @input="maxTries = $el.value === \'\' ? null : Number($el.value)" />\n </div>\n </div>\n\n \x3c!-- Row 4: retry delay + backoff + cron --\x3e\n <div style="display:flex; gap:8px; align-items:flex-end;">\n <div class="field" style="flex:1;"><label>Retry delay (ms)</label>\n <input type="number" placeholder="0" :value="retryDelay" @input="retryDelay = Number($el.value)" />\n </div>\n <div class="field" style="width:120px;"><label>Backoff multiplier</label>\n <input type="number" step="0.1" placeholder="1" :value="backoff" @input="backoff = Number($el.value)" />\n </div>\n <div class="field" style="flex:1;"><label>Cron</label>\n <ok-cron-input :value="cron" placeholder="optional" @change="cron = $event.detail" />\n </div>\n </div>\n\n \x3c!-- Payload --\x3e\n <div style="display:flex; flex-direction:column; gap:6px;">\n <span style="opacity:.7; font-size:12px;">Payload</span>\n <ok-json-input\n mode="textarea"\n style="height:260px;"\n :value="payloadInit"\n @edit="payload = $event.detail"\n />\n </div>\n\n</div>\n',style:".mode-btn{font-size:11px;padding:2px 8px;opacity:.6;border-radius:4px}.mode-btn--on{opacity:1;background:color-mix(in srgb,var(--okdb-accent) 13%,transparent);border-color:color-mix(in srgb,var(--okdb-accent) 33%,transparent);color:var(--okdb-accent)}.btn-ghost{background:0 0;border:1px solid var(--okdb-app-border);border-radius:5px;color:inherit;cursor:pointer;opacity:.6;padding:2px 8px;font-size:12px}.btn-ghost:hover{opacity:1;border-color:color-mix(in srgb,var(--okdb-accent) 33%,transparent)}.btn-ghost--sm{font-size:11px;padding:1px 7px}"};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import e from"../modals/edit-bucket-modal.ok.js";import t from"../../../stores/okdb-store.js";export default{tag:"queue-buckets",dependencies:[e],context:e=>({busy:!1,buckets:[],error:null,async load(){this.busy=!0,this.error=null;try{const e=await fetch(`${t.apiBase}/queue/buckets`),o=await e.json();if(!e.ok)throw new Error(o?.error?.message||"Failed to load buckets");this.buckets=o.data??[]}catch(e){this.error=e?.message||String(e),this.buckets=[]}finally{this.busy=!1}},async openCreate(){await e.$ok.shared.modal.open({owner:e,title:"Add Token Bucket",content:'<edit-bucket-modal :modal="modal" :edit-mode="editMode" :initial-form="initialForm" :on-done="onDone" />',context:e=>({modal:e,editMode:!1,initialForm:{},onDone:async()=>{await this.load()}})})},async openEdit(t){await e.$ok.shared.modal.open({owner:e,title:"Edit Bucket",content:'<edit-bucket-modal :modal="modal" :edit-mode="editMode" :initial-form="initialForm" :on-done="onDone" />',context:e=>({modal:e,editMode:!0,initialForm:{id:t.id,capacity:t.capacity,tokens:t.tokens,refill_amount:t.refill_amount??0,refill_every:t.refill_every??0},onDone:async()=>{await this.load()}})})},async remove(o){if(await e.$ok.shared.modal.confirm(`Delete bucket "<b>${o.id}</b>"?`))try{if(!(await fetch(`${t.apiBase}/queue/bucket/remove/${encodeURIComponent(o.id)}`,{method:"POST"})).ok)throw new Error("Delete failed");e.$ok.shared?.toast?.info?.(`Deleted "${o.id}"`),await this.load()}catch(t){e.$ok.shared?.toast?.error?.(t?.message||"Delete failed")}},async refill(o){try{if(!(await fetch(`${t.apiBase}/queue/bucket/update/${encodeURIComponent(o.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tokens:o.capacity})})).ok)throw new Error("Refill failed");e.$ok.shared?.toast?.success?.(`Refilled "${o.id}"`),await this.load()}catch(t){e.$ok.shared?.toast?.error?.(t?.message||"Refill failed")}},tokenPct:e=>e.capacity?Math.min(100,Math.round(e.tokens/e.capacity*100)):0,pctColor:e=>e>60?"var(--okdb-success)":e>25?"var(--okdb-warning)":"var(--okdb-danger)",refillLabel(e){if(!e.refill_every||!e.refill_amount)return"No refill";const t=e.refill_every;let o;return o=t>=36e5?`${(t/36e5).toFixed(1)}h`:t>=6e4?`${Math.round(t/6e4)}m`:`${Math.round(t/1e3)}s`,`+${e.refill_amount} / ${o}`}}),async mount(e){await this.load(),e.$watch(()=>e.$ok.stores.okdb.selectedEnv,()=>this.load())},template:'\n<div style="display:flex; flex-direction:column; gap:16px; height:100%; min-height:0;">\n\n \x3c!-- Toolbar --\x3e\n <div style="display:flex; gap:8px; align-items:center;">\n <div style="font-weight:600; font-size:16px;">Token Buckets</div>\n <div style="margin-left:auto; display:flex; gap:8px;">\n <button @click="load()" :disabled="busy">↻ Refresh</button>\n <button @click="openCreate()" style="background:color-mix(in srgb, var(--okdb-accent) 13%, transparent); border-color:var(--okdb-accent); color:var(--okdb-accent);">+ Add Bucket</button>\n </div>\n </div>\n\n <if :="error">\n <div style="color:var(--okdb-danger); font-size:13px; padding:10px 12px; border:1px solid var(--okdb-danger); border-radius:8px;">{{error}}</div>\n </if>\n\n \x3c!-- Empty state --\x3e\n <if :="!busy && buckets.length === 0 && !error">\n <div style="opacity:.55; font-size:13px; line-height:1.8; padding:16px 0;">\n No token buckets defined.<br>\n Token buckets let you rate-limit queue job processing per bucket ID.\n </div>\n </if>\n\n \x3c!-- Bucket cards --\x3e\n <div style="display:grid; grid-template-columns:repeat(auto-fill,minmax(280px,1fr)); gap:12px; overflow:auto; min-height:0;">\n <for :="buckets" let:b>\n <div style="\n background:var(--okdb-app-surface);\n border:1px solid var(--okdb-app-border);\n border-radius:12px;\n padding:14px 16px;\n display:flex;\n flex-direction:column;\n gap:10px;\n ">\n \x3c!-- Header --\x3e\n <div style="display:flex; align-items:center; gap:8px;">\n <div style="font-weight:600; font-family:monospace; font-size:13px; flex:1; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;">\n {{b.id}}\n </div>\n <button @click="openEdit(b)" style="font-size:11px; padding:3px 8px; opacity:.8;">Edit</button>\n <button @click="remove(b)" style="font-size:11px; padding:3px 8px; color:var(--okdb-danger); opacity:.8;">✕</button>\n </div>\n\n \x3c!-- Token bar --\x3e\n <div>\n <div style="display:flex; justify-content:space-between; font-size:12px; margin-bottom:4px;">\n <span style="opacity:.7;">Tokens</span>\n <span :style="\'color:\' + pctColor(tokenPct(b))">\n {{b.tokens}} / {{b.capacity}} ({{tokenPct(b)}}%)\n </span>\n </div>\n <div style="height:6px; background:var(--okdb-app-border); border-radius:999px; overflow:hidden;">\n <div\n :style="\'height:100%; border-radius:999px; width:\' + tokenPct(b) + \'%; background:\' + pctColor(tokenPct(b)) + \'; transition:width 0.3s;\'"\n ></div>\n </div>\n </div>\n\n \x3c!-- Stats row --\x3e\n <div style="display:flex; gap:12px; font-size:12px; opacity:.75;">\n <span>Refill: <b>{{refillLabel(b)}}</b></span>\n </div>\n\n \x3c!-- Actions --\x3e\n <div style="display:flex; gap:6px;">\n <button @click="refill(b)" style="font-size:11px; flex:1;" :disabled="b.tokens >= b.capacity">\n Refill to Full\n </button>\n </div>\n </div>\n </for>\n </div>\n\n</div>\n'};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import t from"../../../stores/okdb-store.js";import e from"../modals/job-type-modal.ok.js";import o from"../modals/enqueue-job-modal.ok.js";const n={active:"Active",paused:"Paused",draining:"Draining"},a={active:"color-mix(in srgb, #22c55e 80%, transparent)",paused:"color-mix(in srgb, #f59e0b 80%, transparent)",draining:"color-mix(in srgb, #3b82f6 80%, transparent)"};export default{tag:"queue-job-types",dependencies:[e,o],context:e=>({busy:!1,loadError:null,types:[],bucketOptions:[],async load(){this.busy=!0,this.loadError=null;try{const[e,o]=await Promise.all([fetch(t.apiBase+"/queue/job-types"),fetch(t.apiBase+"/queue/buckets").catch(()=>null)]);if(!e.ok){const t=await e.json().catch(()=>({}));throw new Error(t?.error?.message??t?.message??`HTTP ${e.status}`)}const n=await e.json();this.types=n?.result??n?.data??[];const a=o?.ok?await o.json().catch(()=>({})):{};this.bucketOptions=a?.result??a?.data??[]}catch(t){console.error("queue-job-types load error",t),this.loadError=t.message||"Failed to load",this.types=[]}finally{this.busy=!1}},statusLabel:t=>n[t]??t,statusColor:t=>a[t]??"var(--okdb-app-fg-muted)",formatDefaults(t){const e=t.defaults??{},o=[];return null!=e.max_tries&&o.push(`tries:${e.max_tries}`),null!=e.retry_delay&&o.push(`delay:${e.retry_delay}ms`),null!=e.priority&&o.push(`pri:${e.priority}`),null!=e.ttl&&o.push(`ttl:${e.ttl}ms`),null!=t.max_concurrency&&o.push(`concurrency:${t.max_concurrency}`),o.join(" · ")||"—"},openCreate(){const t=this;e.$ok.shared.modal.open({owner:e,title:"Register Job Type",content:'<job-type-modal :modal="modal" :job-type="null" :bucket-options="bucketOptions" :on-done="onDone" />',context:e=>({modal:e,bucketOptions:t.bucketOptions,onDone:()=>t.load()})})},openEdit(t){e.$ok.shared.modal.open({owner:e,title:`Edit: ${t.id}`,content:'<job-type-modal :modal="modal" :job-type="jobType" :bucket-options="bucketOptions" :on-done="onDone" />',context:e=>({modal:e,jobType:t,bucketOptions:this.bucketOptions,onDone:()=>this.load()})})},async setStatus(o,n){try{if(!(await fetch(t.apiBase+"/queue/job-type/"+encodeURIComponent(o.id)+"/"+n,{method:"POST"})).ok)throw new Error("failed");await this.load()}catch{e.$ok.shared?.toast?.error?.(`Failed to ${n} job type`)}},openEnqueue(t){e.$ok.shared.modal.open({owner:e,title:"Enqueue Job",content:'<enqueue-job-modal :modal="modal" :initial-type="initialType" :on-done="onDone" />',context:o=>({modal:o,initialType:t.id,onDone:()=>e.$ok.shared?.toast?.success?.("Job enqueued")})})},async remove(o){if(await e.$ok.shared.modal.confirm(`Remove job type "${o.id}"? Existing jobs are unaffected.`))try{if(!(await fetch(t.apiBase+"/queue/job-type/"+encodeURIComponent(o.id),{method:"DELETE"})).ok)throw new Error("failed");await this.load()}catch{e.$ok.shared?.toast?.error?.("Failed to remove job type")}}}),async mount(e){await this.load(),e.$watch(()=>t.selectedEnv,()=>{this.types=[],this.load()})},template:'\n<div style="display:flex; flex-direction:column; gap:16px; padding:16px 0;">\n\n \x3c!-- header --\x3e\n <div style="display:flex; align-items:center; gap:10px;">\n <div style="font-size:14px; font-weight:600; flex:1;">Registered Job Types</div>\n <button @click="load" :disabled="busy" style="opacity:.6; font-size:11px; padding:2px 8px;">↻</button>\n <button @click="openCreate()" style="font-size:12px; padding:4px 12px;">+ Register type</button>\n </div>\n\n \x3c!-- error state --\x3e\n <if :="loadError">\n <div style="color:#ef4444; font-size:12px; padding:8px 12px; border:1px solid #ef4444; border-radius:6px; background:color-mix(in srgb, #ef4444 8%, transparent);">\n Failed to load job types: {{ loadError }}\n </div>\n </if>\n\n \x3c!-- empty state --\x3e\n <if :="!busy && !loadError && types.length === 0">\n <div style="opacity:.45; font-size:13px; line-height:1.8; padding:32px 0; text-align:center;">\n No registered job types.<br>\n <span style="font-size:12px;">Register a type to set defaults, control concurrency, and pause/resume claiming.</span>\n </div>\n </if>\n\n \x3c!-- types list --\x3e\n <div style="display:flex; flex-direction:column; gap:8px;">\n <each :of="types" let:item="jt">\n <div class="jt-card">\n <div style="display:flex; align-items:center; gap:10px; flex-wrap:wrap;">\n <span style="font-size:13px; font-weight:600; flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;">{{ jt.id }}</span>\n <span class="status-badge" :style="\'border-color:\' + statusColor(jt.status) + \'; color:\' + statusColor(jt.status)">\n {{ statusLabel(jt.status) }}\n </span>\n <if :="jt.payload_schema">\n <span class="status-badge" style="border-color:var(--okdb-accent); color:var(--okdb-accent);">schema</span>\n <if :="jt.payload_schema.enforce">\n <span class="status-badge" style="border-color:#ef4444; color:#ef4444;">enforced</span>\n </if>\n </if>\n \x3c!-- lifecycle actions --\x3e\n <if :="jt.status !== \'paused\'">\n <button class="act-btn" @click="setStatus(jt, \'pause\')" title="Pause — stop workers from claiming new jobs">⏸ Pause</button>\n </if>\n <if :="jt.status === \'paused\'">\n <button class="act-btn act-btn--accent" @click="setStatus(jt, \'resume\')" title="Resume normal claiming">▶ Resume</button>\n </if>\n <if :="jt.status !== \'draining\'">\n <button class="act-btn" @click="setStatus(jt, \'drain\')" title="Drain — stop new enqueues, let queue empty">⬇ Drain</button>\n </if>\n <if :="jt.status === \'draining\'">\n <button class="act-btn act-btn--accent" @click="setStatus(jt, \'resume\')">▶ Resume</button>\n </if>\n <button class="act-btn act-btn--enqueue" @click="openEnqueue(jt)">+ Enqueue</button>\n <button class="act-btn" @click="openEdit(jt)">Edit</button>\n <button class="act-btn act-btn--danger" @click="remove(jt)">Remove</button>\n </div>\n <div style="font-size:11px; opacity:.55; margin-top:4px; font-family:monospace;">{{ formatDefaults(jt) }}</div>\n </div>\n </each>\n </div>\n\n</div>\n',style:".jt-card{border:1px solid var(--okdb-app-border);border-radius:8px;padding:10px 14px;background:var(--okdb-app-surface)}.status-badge{font-size:10px;padding:2px 8px;border-radius:999px;border:1px solid;font-weight:600;letter-spacing:.04em}.act-btn{font-size:11px;padding:2px 8px;border-radius:5px;border:1px solid var(--okdb-app-border);background:0 0;cursor:pointer;color:var(--okdb-app-fg-muted)}.act-btn:hover{border-color:var(--okdb-app-fg-muted);color:var(--okdb-app-fg)}.act-btn--accent,.act-btn--enqueue{border-color:color-mix(in srgb,var(--okdb-accent) 40%,transparent);color:var(--okdb-accent)}.act-btn--danger:hover{border-color:#ef4444;color:#ef4444}.act-btn--enqueue{border-color:color-mix(in srgb,var(--okdb-accent) 30%,transparent)}.act-btn--enqueue:hover{border-color:var(--okdb-accent)}"};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import e from"@toolkit/elements/ok-icon.ok.js";import t from"@toolkit/elements/ok-table.ok.js";import o from"@toolkit/core/ok-overlay.ok.js";import a from"../modals/edit-job-modal.ok.js";import s from"../modals/enqueue-job-modal.ok.js";import n from"./code-panel.ok.js";import i from"./job-log-panel.ok.js";import r from"../../../stores/events-store.js";import l from"../../../stores/okdb-store.js";const d=new Set;export default{tag:"queue-jobs",dependencies:[e,t,o,s,a,n,i],attr:{type:{}},context:e=>({query:function({apiBase:e,pageSize:t=50}){return{busy:!1,values:[],total:0,hasNext:!1,hasPrev:!1,pageSize:t,loadError:null,type:null,status:null,sort:"when",direction:"asc",_cursors:[null],_pageIdx:0,_nextCursor:null,resetPaging(){this._cursors=[null],this._pageIdx=0,this._nextCursor=null,this.hasNext=!1,this.hasPrev=!1},async load(){const t="function"==typeof e?e():e,o=this._cursors[this._pageIdx];this.busy=!0,this.loadError=null;try{const e=new URLSearchParams({limit:String(this.pageSize),sort:this.sort??"when",direction:this.direction??"asc"});this.type&&e.set("type",this.type),this.status&&e.set("status",this.status),null!=o&&e.set("cursor","string"==typeof o?o:JSON.stringify(o));const a=await fetch(`${t}/queue/jobs?${e}`),s=await a.json();if(!a.ok)throw new Error(s?.error?.message||`HTTP ${a.status}`);const n=s.result??s.data??s;this.values=Array.isArray(n.items)?n.items:Array.isArray(n)?n:[],this._nextCursor=n.cursor??null,this.hasNext=null!=this._nextCursor,this.hasPrev=this._pageIdx>0}catch(e){this.loadError=e?.message||String(e),this.values=[]}finally{this.busy=!1}},async nextPage(){this.hasNext&&!this.busy&&(this._pageIdx+1>=this._cursors.length&&this._cursors.push(this._nextCursor),this._pageIdx++,await this.load())},async prevPage(){this.hasPrev&&!this.busy&&(this._pageIdx--,await this.load())}}}({apiBase:()=>l.apiBase,pageSize:50}),type:null,status:null,sortMode:"when",direction:"asc",stats:null,_statsTimer:null,async loadStats(){try{const e=await fetch(l.apiBase+"/queue/stats");if(e.ok){const t=await e.json();this.stats=t.result??t.data??null}}catch{}},_jobCache:{},jobMetaText(e){const{payload:t,...o}=e;return JSON.stringify(o,null,2)},errorText:e=>JSON.stringify({status_code:e.status_code??null,status_message:e.status_message??null,error_stack:e.error_stack??null},null,2),payloadText(e){const t=this._jobCache[e.id];return void 0===t?(d.has(e.id)||(d.add(e.id),queueMicrotask(()=>this._fetchJobPayload(e.id))),""):"__error__"===t?"// failed to load payload":JSON.stringify(t?.payload??null,null,2)},async _fetchJobPayload(e){let t="__error__";try{const o=await fetch(`${l.apiBase}/queue/job/${encodeURIComponent(e)}`);if(o.ok){const e=await o.json();t=e?.result??e?.data??null}}catch{}finally{d.delete(e),this._jobCache={...this._jobCache,[e]:t}}},_scheduleStats(){clearTimeout(this._statsTimer),this._statsTimer=setTimeout(()=>this.loadStats(),400)},statusCount(e){if(!this.stats)return"";const t=this.type;return e?t?this.stats.byType?.[t]?.byStatus?.[e]??0:this.stats.byStatus?.[e]??0:t?this.stats.byType?.[t]?.total??0:this.stats.total??0},applyTypeAttr(){var t;this.type=null==(t=e.$attr.type)||""===t?null:String(t),this._applyFilterAndReload()},setStatus(e){this.status=null==e||""===e?null:e,this._applyFilterAndReload()},setSort(e){this.sortMode=e,this._applySort(),this.query.resetPaging(),this.query.load()},toggleDirection(){this.direction="asc"===this.direction?"desc":"asc",this._applySort(),this.query.resetPaging(),this.query.load()},_applySort(){this.query.sort=this.sortMode,this.query.direction=this.direction},_applyFilterAndReload(){this.query.type=this.type,this.query.status=this.status,this._applySort(),this.query.resetPaging(),this.query.load()},async refresh(){clearTimeout(this._liveTimer),this.pendingUpdates=0;try{await fetch(l.apiBase+"/queue/reconcile",{method:"POST"})}catch{}await this.query.load(),await this.loadStats(),e.$dispatch("refresh")},async openEnqueue(){const t=this;await e.$ok.shared.modal.open({owner:e,title:"Enqueue Job",content:'<enqueue-job-modal :modal="modal" :initial-type="initialType" :on-done="onDone" />',context:o=>({modal:o,initialType:t.type||"",onDone:async()=>{e.$ok.shared?.toast?.success?.("Job enqueued"),await t.refresh()}})})},async openEditJob(t){const o=this;await e.$ok.shared.modal.open({owner:e,title:`Edit Job ${t.id.slice(0,8)}`,content:'<edit-job-modal :modal="modal" :job-id="jobId" :on-done="onDone" />',context:e=>({modal:e,jobId:t.id,onDone:async()=>{await o.refresh()}})})},async deleteJob(t){if(await e.$ok.shared.modal.confirm(`Delete job <code>${t.id.slice(0,8)}</code>?`)){t._busy=!0;try{if(!(await fetch(l.apiBase+"/queue/job/"+t.id+"/remove",{method:"POST"})).ok)throw new Error("remove failed");const o=this.query.values.indexOf(t);o>=0&&this.query.values.splice(o,1),e.$ok.shared.toast?.info("Deleted "+t.id.slice(0,8)),e.$dispatch("refresh"),this._scheduleStats()}catch{e.$ok.shared.toast?.error("Delete failed")}finally{t._busy=!1}}},async cancelJob(t){if(await e.$ok.shared.modal.confirm(`Cancel job <code>${t.id.slice(0,8)}</code>?`)){t._busy=!0;try{if(!(await fetch(l.apiBase+"/queue/job/"+t.id+"/cancel",{method:"POST"})).ok)throw new Error("cancel failed");e.$ok.shared.toast?.info("Cancelled "+t.id.slice(0,8)),await this.refresh()}catch{e.$ok.shared.toast?.error("Cancel failed")}finally{t._busy=!1}}},async retryJob(t){if(await e.$ok.shared.modal.confirm(`Retry job <code>${t.id.slice(0,8)}</code>?`)){t._busy=!0;try{const o=await fetch(l.apiBase+"/queue/job/"+t.id+"/retry",{method:"POST"}),a=await o.json();if(!o.ok)throw new Error(a?.error?.message||"retry failed");e.$ok.shared.toast?.success("Retried "+t.id.slice(0,8)),await this.refresh()}catch(t){e.$ok.shared.toast?.error("Retry failed: "+(t?.message||t))}finally{t._busy=!1}}},bulkBusy:!1,async retryAllFailed(){if(await e.$ok.shared.modal.confirm(`Retry all failed jobs${this.type?` for type "<b>${this.type}</b>"`:""}?`)){this.bulkBusy=!0;try{const t={limit:5e3};this.type&&(t.type=this.type);const o=await fetch(l.apiBase+"/queue/retryFailed",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),a=await o.json();if(!o.ok)throw new Error(a?.error?.message||"failed");e.$ok.shared?.toast?.success?.(`Retried ${a.data.retried} failed jobs`),await this.refresh()}catch(t){e.$ok.shared?.toast?.error?.("Bulk retry failed: "+(t?.message||t))}finally{this.bulkBusy=!1}}},async deleteAllDone(){if(await e.$ok.shared.modal.confirm(`Clear all "done" jobs${this.type?` for type "<b>${this.type}</b>"`:""}?<br><br>This cannot be undone.`)){this.bulkBusy=!0;try{const t={limit:5e4};this.type&&(t.type=this.type);const o=await fetch(l.apiBase+"/queue/clearDone",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),a=await o.json();if(!o.ok)throw new Error(a?.error?.message||"failed");e.$ok.shared?.toast?.info?.(`Cleared ${a.data.deleted} done jobs`),await this.refresh()}catch(t){e.$ok.shared?.toast?.error?.("Clear done failed: "+(t?.message||t))}finally{this.bulkBusy=!1}}},async deleteAllFailed(){if(await e.$ok.shared.modal.confirm(`Delete all "failed" jobs${this.type?` for type "<b>${this.type}</b>"`:""}?<br><br>This cannot be undone.`)){this.bulkBusy=!0;try{const t={limit:5e4};this.type&&(t.type=this.type);const o=await fetch(l.apiBase+"/queue/clearFailed",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),a=await o.json();if(!o.ok)throw new Error(a?.error?.message||"failed");e.$ok.shared?.toast?.info?.(`Cleared ${a.data.deleted} failed jobs`),await this.refresh()}catch(t){e.$ok.shared?.toast?.error?.("Clear failed jobs error: "+(t?.message||t))}finally{this.bulkBusy=!1}}},async clearStuck(){if(await e.$ok.shared.modal.confirm(`Delete all stuck (expired-claim) running jobs${this.type?` for type "<b>${this.type}</b>"`:""}?<br><br>Stuck jobs are running jobs whose TTL has expired. They will be permanently deleted, not re-queued.`)){this.bulkBusy=!0;try{const t={limit:5e4};this.type&&(t.type=this.type);const o=await fetch(l.apiBase+"/queue/clearStuck",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),a=await o.json();if(!o.ok)throw new Error(a?.error?.message||"failed");e.$ok.shared?.toast?.info?.(`Cleared ${a.data.deleted} stuck jobs`),await this.refresh()}catch(t){e.$ok.shared?.toast?.error?.("Clear stuck failed: "+(t?.message||t))}finally{this.bulkBusy=!1}}},isStatusOn(e){return(this.status??null)===(e??null)},statusBadgeStyle(e){const t={pending:"var(--okdb-warning)",running:"var(--okdb-info)",done:"var(--okdb-success)",failed:"var(--okdb-danger)"}[e]||"#9ca3af";return`color:${t}; border-color:${t};`},formatWhen(e){if(!e)return"—";const t=e-Date.now(),o=Math.abs(t),a=Math.round(o/1e3);if(a<5)return t<=0?"now":"in a moment";if(a<60)return t<0?`${a}s ago`:`in ${a}s`;const s=Math.round(a/60);if(s<60)return t<0?`${s}m ago`:`in ${s}m`;const n=Math.round(s/60);if(n<24)return t<0?`${n}h ago`:`in ${n}h`;const i=Math.round(n/24);return t<0?`${i}d ago`:`in ${i}d`},shortId:e=>(e||"").slice(0,8),_unsubs:[],_liveTimer:null,pendingUpdates:0,_scheduleLiveReload(){this.pendingUpdates++,clearTimeout(this._liveTimer),this._liveTimer=setTimeout(async()=>{await this.query.load(),await this.loadStats(),this._jobCache={},e.$dispatch("refresh"),this.pendingUpdates=0},3e3)}}),async init(e){this.applyTypeAttr(),e.$watch(()=>e.$attr.type,()=>this.applyTypeAttr()),e.$watch(()=>e.$ok.stores.okdb.selectedEnv,()=>{this.stats=null,this.query.resetPaging(),Promise.all([this.query.load(),this.loadStats()])}),await Promise.all([this.query.load(),this.loadStats()])},mount(){const e=()=>this._scheduleLiveReload();this._unsubs=[r.on("queue:enqueued",e),r.on("queue:done",e),r.on("queue:failed",e),r.on("queue:retry",e),r.on("queue:removed",e),r.on("queue:reconciled",e)]},unmount(){clearTimeout(this._liveTimer),clearTimeout(this._statsTimer);for(const e of this._unsubs)e();this._unsubs=[]},template:'\n<div style="display:flex; flex-direction:column; height:100%; min-height:0; gap:10px;">\n\n \x3c!-- ── Row 1: Status filters + Enqueue ── --\x3e\n <div style="display:flex; gap:6px; align-items:center; flex-wrap:wrap;">\n <button @click="setStatus(null)" :class="isStatusOn(null) ? \'pill pill--on\' : \'pill\'">All<span class="pill-count">{{ statusCount(null) }}</span></button>\n <button @click="setStatus(\'pending\')" :class="isStatusOn(\'pending\') ? \'pill pill--on pill--p\' : \'pill pill--p\'">Pending<span class="pill-count">{{ statusCount(\'pending\') }}</span></button>\n <button @click="setStatus(\'running\')" :class="isStatusOn(\'running\') ? \'pill pill--on pill--r\' : \'pill pill--r\'">Running<span class="pill-count">{{ statusCount(\'running\') }}</span></button>\n <button @click="setStatus(\'failed\')" :class="isStatusOn(\'failed\') ? \'pill pill--on pill--f\' : \'pill pill--f\'">Failed<span class="pill-count">{{ statusCount(\'failed\') }}</span></button>\n <button @click="setStatus(\'done\')" :class="isStatusOn(\'done\') ? \'pill pill--on pill--d\' : \'pill pill--d\'">Done<span class="pill-count">{{ statusCount(\'done\') }}</span></button>\n\n <div style="flex:1;"></div>\n\n <select @change="setSort($el.value)" :value="sortMode" style="font-size:12px;">\n <option value="when">Sort: When</option>\n <option value="priority">Sort: Priority</option>\n </select>\n <button @click="toggleDirection" style="font-size:12px; min-width:32px;" title="Toggle sort direction">\n {{ direction === \'asc\' ? \'▲\' : \'▼\' }}\n </button>\n\n <button @click="openEnqueue"\n style="background:color-mix(in srgb, var(--okdb-accent) 13%, transparent); border-color:color-mix(in srgb, var(--okdb-accent) 33%, transparent); color:var(--okdb-accent); font-weight:600; padding:4px 14px; font-size:12px; white-space:nowrap;">\n + Enqueue\n </button>\n </div>\n\n \x3c!-- ── Row 2: Bulk actions ── --\x3e\n <div style="display:flex; gap:6px; align-items:center; flex-wrap:wrap; padding:5px 0; border-top:1px solid var(--okdb-app-surface-2); border-bottom:1px solid var(--okdb-app-surface-2);">\n <button @click="retryAllFailed()" :disabled="bulkBusy"\n style="font-size:12px; color:var(--okdb-warning); border-color:color-mix(in srgb, var(--okdb-warning) 20%, transparent); background:transparent; padding:3px 10px;"\n title="Reset all failed jobs back to pending">\n ↺ Retry Failed\n </button>\n <div style="width:1px; height:16px; background:var(--okdb-app-border);"></div>\n <button @click="deleteAllDone()" :disabled="bulkBusy"\n style="font-size:12px; color:var(--okdb-success); border-color:color-mix(in srgb, var(--okdb-success) 20%, transparent); background:transparent; padding:3px 10px;"\n title="Delete all done jobs in one index pass">\n ✕ Clear Done\n </button>\n <button @click="deleteAllFailed()" :disabled="bulkBusy"\n style="font-size:12px; color:var(--okdb-danger); border-color:color-mix(in srgb, var(--okdb-danger) 20%, transparent); background:transparent; padding:3px 10px;"\n title="Permanently delete all failed jobs">\n ✕ Clear Failed\n </button>\n <button @click="clearStuck()" :disabled="bulkBusy"\n style="font-size:12px; color:var(--okdb-app-fg-muted); border-color:color-mix(in srgb, var(--okdb-app-fg-muted) 20%, transparent); background:transparent; padding:3px 10px;"\n title="Delete running jobs whose claim TTL has expired (permanently, not re-queued)">\n ✕ Clear Stuck\n </button>\n <if :="pendingUpdates > 0">\n <span style="font-size:11px; color:var(--okdb-warning); opacity:.8; margin-left:4px;">\n ⟳ {{ pendingUpdates }} pending\n </span>\n </if>\n </div>\n\n \x3c!-- Table --\x3e\n <div style="display:flex; flex-direction:column; position:relative; flex:1; min-height:0;">\n <if :="query.busy">\n <ok-overlay>\n <div class="loader-center">\n <ok-icon name="loader" class="spin" style="width:32px;height:32px;"></ok-icon>\n </div>\n </ok-overlay>\n </if>\n\n <if :="query.loadError && !query.busy">\n <div style="color:var(--okdb-danger); padding:12px 14px; border:1px solid color-mix(in srgb, var(--okdb-danger) 33%, transparent); border-radius:8px; margin-bottom:8px; font-size:13px; display:flex; align-items:center; gap:10px;">\n <span style="flex:1;">{{ query.loadError }}</span>\n <button @click="query.load()" style="font-size:11px; color:var(--okdb-danger); border-color:color-mix(in srgb, var(--okdb-danger) 33%, transparent); padding:3px 10px;">Retry</button>\n </div>\n </if>\n\n <ok-table :data="query.values" no-scroll style="flex:1; min-height:0; overflow:auto;">\n <columns>\n <column width="80px" no-resize>\n <header>Status</header>\n <cell let:row>\n <span class="status-badge" :style="statusBadgeStyle(row.status)">{{ row.status }}</span>\n </cell>\n </column>\n <column width="1fr">\n <header>Type + Metadata</header>\n <cell let:row>\n <div style="display:flex; flex-direction:column; gap:2px;">\n <div>{{ row.type }}</div>\n <div style="display:flex; gap:4px; flex-wrap:wrap;">\n <if :="row.tags && row.tags.length > 0">\n <span style="display:inline-block; font-size:11px; padding:1px 6px; background:var(--okdb-app-bg-deep); border-radius:3px; opacity:.7;">{{ row.tags.join(\', \') }}</span>\n </if>\n <if :="row.progress">\n <span style="display:inline-block; font-size:11px; padding:1px 6px; background:var(--okdb-app-bg-deep); border-radius:3px; opacity:.7;">{{ row.progress }}</span>\n </if>\n <if :="row.cron">\n <span style="display:inline-block; font-size:11px; padding:1px 6px; background:var(--okdb-app-bg-deep); border-radius:3px; opacity:.7; color:var(--okdb-indigo);">cron: {{ row.cron }}</span>\n </if>\n <if :="row.idempotency_key">\n <span style="display:inline-block; font-size:11px; padding:1px 6px; background:var(--okdb-app-bg-deep); border-radius:3px; opacity:.7; color:#34d399;">key: {{ row.idempotency_key }}</span>\n </if>\n </div>\n </div>\n </cell>\n </column>\n <column width="130px" no-resize>\n <header>When</header>\n <cell let:row>{{ formatWhen(row.when) }}</cell>\n </column>\n <column width="70px" no-resize>\n <header>Tries</header>\n <cell let:row>\n <span :style="row.tries >= row.max_tries && row.max_tries > 0 ? \'color:var(--okdb-danger);\' : \'\'">\n {{ row.tries }} / {{ row.max_tries }}\n </span>\n </cell>\n </column>\n <column width="180px" no-resize>\n <header>Actions</header>\n <cell let:row>\n <button @click="openEditJob(row)" :disabled="row._busy" style="font-size:11px;">Edit</button>\n <button @click="retryJob(row)" :disabled="row._busy" style="font-size:11px;">Retry</button>\n <if :="row.status === \'pending\' || row.status === \'running\'">\n <button @click="cancelJob(row)" :disabled="row._busy" style="font-size:11px;">Cancel</button>\n </if>\n <button @click="deleteJob(row)" :disabled="row._busy" style="color:#ff6c6b; font-size:11px;">Delete</button>\n </cell>\n </column>\n </columns>\n\n <expanded let:row>\n <div style="padding:10px; font-size:12px; display:flex; flex-direction:column; gap:6px;">\n <if :="row.error_stack || row.status_message">\n <div>\n <if :="row.status_message">\n <div style="white-space:pre-wrap; opacity:.9; margin-bottom:6px;">{{ row.status_message }}</div>\n </if>\n <if :="row.error_stack">\n <pre style="white-space:pre-wrap; opacity:.85; max-height:220px; overflow:auto; background:var(--okdb-app-bg-deep); padding:8px; border-radius:4px;">{{ row.error_stack }}</pre>\n </if>\n </div>\n </if>\n <div style="display:flex; flex-wrap:wrap; gap:12px; opacity:.8; font-size:11px;">\n <span>ID: <b>{{ row.id }}</b></span>\n <span>Status code: <b>{{ row.status_code || \'—\' }}</b></span>\n <span>Max tries: <b>{{ row.max_tries ?? \'—\' }}</b></span>\n <span>Retry delay: <b>{{ row.retry_delay ?? 0 }}ms</b></span>\n <span>Backoff: <b>{{ row.backoff_multiplier ?? 1 }}</b></span>\n <span>Priority: <b>{{ row.priority ?? 0 }}</b></span>\n <span :="row.bucket" style="display:inline;">Bucket: <b>{{ row.bucket || \'—\' }}</b></span>\n <span>Claim expires: <b>{{ formatWhen(row.claim_expires) }}</b></span>\n </div>\n <div style="display:flex; flex-direction:column; gap:8px; margin-top:6px;">\n <code-panel :title="\'Job\'" :lang="\'json\'" :text="jobMetaText(row)"></code-panel>\n <code-panel :title="\'Payload\'" :lang="\'json\'" :text="payloadText(row)"></code-panel>\n <if :="row.status === \'failed\'">\n <code-panel :title="\'Error\'" :lang="\'json\'" :text="errorText(row)"></code-panel>\n </if>\n <job-log-panel :job-id="row.id" :env="$ok.stores.okdb.selectedEnv" :job="row"></job-log-panel>\n </div>\n </div>\n </expanded>\n </ok-table>\n\n \x3c!-- Pagination --\x3e\n <div class="ok-pager">\n <button @click="query.prevPage()" :disabled="!query.hasPrev || query.busy">‹ Prev</button>\n <span>{{ statusCount(status) }} total · {{ query.pageSize }}/page</span>\n <button @click="query.nextPage()" :disabled="!query.hasNext || query.busy">Next ›</button>\n </div>\n </div>\n\n</div>\n',style:".pill{display:inline-flex;align-items:center;gap:5px;border:1px solid var(--okdb-app-border);background:var(--okdb-app-surface);padding:4px 10px;border-radius:999px;font-size:12px;cursor:pointer;color:var(--okdb-app-fg-muted);transition:border-color .12s,color .12s}.pill:hover{border-color:#3b4754;color:var(--okdb-app-fg)}.pill--on{box-shadow:0 0 0 1px rgba(255,255,255,.07) inset}.pill--p.pill--on{color:var(--okdb-warning);border-color:var(--okdb-warning)}.pill--r.pill--on{color:var(--okdb-info);border-color:var(--okdb-info)}.pill--f.pill--on{color:var(--okdb-danger);border-color:var(--okdb-danger)}.pill--d.pill--on{color:var(--okdb-success);border-color:var(--okdb-success)}.pill-count{font-size:11px;opacity:.65;font-variant-numeric:tabular-nums}.status-badge{display:inline-block;padding:2px 8px;border-radius:999px;font-size:11px;border:1px solid;white-space:nowrap}"};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import t from"../../../stores/events-store.js";import e from"../../../stores/okdb-store.js";const s={paused:"#f59e0b",draining:"#3b82f6"};export default{tag:"queue-types",attr:{selectedtype:{}},context:t=>({busy:!1,total:0,typesData:[],workerCounts:{},registeredTypes:{},filterText:"",_unsubs:[],_reloadTimer:null,selectedType:null,async load(){this.busy=!0;try{const[s,o,a]=await Promise.all([fetch(e.apiBase+"/queue/types"),fetch(e.apiBase+"/engines?type=queue-worker").catch(()=>null),fetch(e.apiBase+"/queue/job-types").catch(()=>null)]);if(!s.ok)throw new Error("types failed");const n=await s.json(),r=n?.result??n?.data??null,i=o?.ok?await o.json().catch(()=>({})):null,l=i?.result??i?.data??[],p={};for(const t of l){const e=t?.config?.job_type;e&&(p[e]=(p[e]??0)+1)}if(this.workerCounts=p,a?.ok){const t=await a.json().catch(()=>({})),e=t?.result??[];this.registeredTypes=Object.fromEntries(e.map(t=>[t.id,t]))}this.total=r?.total??0,this.typesData=Array.isArray(r?.types)?r.types.slice().sort((t,e)=>String(t?.type||"").localeCompare(String(e?.type||""))).map(t=>({...t,workerCount:p[t?.type]??0})):[],this.typesData.length||await this.loadFromStats(),this._mergeRegisteredTypes(),this.selectedType&&!this.typesData.some(t=>t?.type===this.selectedType)&&(this.selectedType=null,t.$dispatch("type",null))}catch(t){console.error("queue-types load error",t),await this.loadFromStats(),this._mergeRegisteredTypes()}finally{this.busy=!1}},_mergeRegisteredTypes(){const t=new Set(this.typesData.map(t=>t?.type));for(const e of Object.keys(this.registeredTypes))t.has(e)||this.typesData.push({type:e,total:0,byStatus:{},workerCount:this.workerCounts[e]??0});this.typesData.sort((t,e)=>String(t?.type||"").localeCompare(String(e?.type||"")))},async loadFromStats(){try{const t=await fetch(e.apiBase+"/queue/stats");if(!t.ok)throw new Error("stats failed");const s=await t.json(),o=s?.result??s?.data??null,a=o?.byType||{};this.total=o?.total??0,this.typesData=Object.keys(a).sort((t,e)=>t.localeCompare(e)).map(t=>({type:t,total:a[t]?.total??0,byStatus:a[t]?.byStatus||{},workerCount:this.workerCounts?.[t]??0}))}catch(t){console.error("queue-types stats fallback error",t),this.total=0,this.typesData=[]}},get types(){const t=(this.filterText||"").trim().toLowerCase();return t?this.typesData.filter(e=>String(e?.type||"").toLowerCase().includes(t)):this.typesData},totalFor(t){return t?this.typesData.find(e=>e?.type===t)?.total??0:this.total},totalWorkers(){return Object.values(this.workerCounts||{}).reduce((t,e)=>t+Number(e||0),0)},jtStatus(t){return this.registeredTypes[t]?.status??null},jtStatusColor(t){return s[this.jtStatus(t)]??null},selectType(e){this.selectedType=e??null,t.$dispatch("type",this.selectedType)},async refresh(){await this.load()},clearFilter(){this.filterText=""},_scheduleLoad(){clearTimeout(this._reloadTimer),this._reloadTimer=setTimeout(()=>this.load(),400)}}),async mount(s){await this.load(),this.selectedType=s.$attr.selectedtype??null;const o=()=>this._scheduleLoad();this._unsubs=[t.on("queue:enqueued",o),t.on("queue:done",o),t.on("queue:failed",o),t.on("queue:retry",o),t.on("queue:removed",o),t.on("queue:reconciled",o),t.on("engine:started",o),t.on("engine:stopped",o),t.on("engine:error",o),t.on("engine:uninstalled",o)],s.$watch(()=>e.selectedEnv,()=>{this.total=0,this.typesData=[],this.filterText="",this.selectedType=null,s.$dispatch("type",null),this.load()}),s.$watch(()=>s.$attr.selectedtype,t=>{this.selectedType=t??null})},unmount(){clearTimeout(this._reloadTimer);for(const t of this._unsubs)t();this._unsubs=[]},template:'\n<div style="display:flex; flex-direction:column; gap:8px; min-height:0;">\n\n <div style="display:flex; align-items:center; justify-content:space-between; gap:8px;">\n <div style="display:flex; align-items:center; gap:6px; flex-wrap:wrap;">\n <div style="font-weight:600; font-size:12px; opacity:.7; text-transform:uppercase; letter-spacing:.05em;">Types</div>\n <if :="totalWorkers() > 0">\n <span style="font-size:10px; padding:1px 6px; border-radius:999px; border:1px solid color-mix(in srgb, var(--okdb-accent) 27%, transparent); color:var(--okdb-accent); background:color-mix(in srgb, var(--okdb-accent) 7%, transparent);">⚙ {{ totalWorkers() }}</span>\n </if>\n </div>\n <button @click="load" :disabled="busy" style="opacity:.6; font-size:11px; padding:2px 6px;">↻</button>\n </div>\n\n <div style="display:flex; align-items:center; gap:6px;">\n <input\n :value="filterText"\n @input="filterText = $event.target.value"\n placeholder="Filter types…"\n style="width:100%; min-width:0; padding:6px 8px; border-radius:6px; border:1px solid var(--okdb-app-border); background:var(--okdb-app-bg-deep); color:var(--okdb-app-fg-strong); font-size:12px;"\n />\n <if :="filterText">\n <button @click="clearFilter()" style="opacity:.7; font-size:11px; padding:5px 7px;">✕</button>\n </if>\n </div>\n\n \x3c!-- Types list --\x3e\n <div style="display:flex; flex-direction:column; gap:3px; overflow:auto; min-height:0; padding-right:4px;">\n <button\n @click="selectType(null)"\n :class="selectedType == null ? \'type-row type-row--on\' : \'type-row\'">\n <span style="display:flex; align-items:center; gap:6px; min-width:0; flex:1; text-align:left;">\n <span style="white-space:nowrap; overflow:hidden; text-overflow:ellipsis;">All types</span>\n <if :="totalWorkers() > 0"><span class="worker-chip">⚙ {{ totalWorkers() }}</span></if>\n </span>\n <span style="opacity:.55; font-size:11px;">{{ totalFor(null) }}</span>\n </button>\n\n <each :of="types" let:item="item">\n <button\n @click="selectType(item.type)"\n :class="selectedType === item.type ? \'type-row type-row--on\' : \'type-row\'">\n <span style="display:flex; align-items:center; gap:6px; min-width:0; flex:1; text-align:left;">\n <if :="jtStatusColor(item.type)">\n <span :style="\'width:6px;height:6px;border-radius:50%;background:\' + jtStatusColor(item.type) + \';flex-shrink:0;\'" :title="jtStatus(item.type)"></span>\n </if>\n <span style="white-space:nowrap; overflow:hidden; text-overflow:ellipsis;">{{ item.type }}</span>\n <if :="item.workerCount > 0"><span class="worker-chip">⚙ {{ item.workerCount }}</span></if>\n </span>\n <span style="opacity:.55; font-size:11px;">{{ item.total }}</span>\n </button>\n </each>\n\n <if :="!busy && types.length === 0">\n <div style="opacity:.5; font-size:12px; padding:6px 8px; line-height:1.5;">\n {{ filterText ? \'No types match this filter.\' : \'No queued job types in this environment.\' }}\n </div>\n </if>\n </div>\n\n</div>\n',style:".type-row{display:flex;align-items:center;justify-content:space-between;gap:6px;padding:5px 8px;border-radius:5px;font-size:12px;border:1px solid transparent;background:0 0;cursor:pointer;width:100%;color:var(--okdb-app-fg-muted);transition:background .12s,border-color .12s,color .12s}.type-row--on,.type-row:hover{background:var(--okdb-app-surface);border-color:var(--okdb-app-border);color:var(--okdb-app-fg)}.type-row--on{border-color:var(--okdb-accent);color:var(--okdb-app-fg-strong)}.worker-chip{display:inline-flex;align-items:center;gap:4px;padding:1px 6px;border-radius:999px;border:1px solid color-mix(in srgb,var(--okdb-accent) 20%,transparent);color:var(--okdb-accent);background:color-mix(in srgb,var(--okdb-accent) 5%,transparent);font-size:10px;flex-shrink:0}"};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import e from"../../../stores/events-store.js";import n from"../../../stores/okdb-store.js";import t from"../../../components/ok-js-input.ok.js";import i from"../../../components/ok-json-input.ok.js";import r from"../../engines/modals/engine-modal.ok.js";import o from"../../engines/parts/engine-row-item.ok.js";import{openFunctionRoute as a}from"../../engines/engine-ui-utils.js";const s="async (ctx) => {\n // ctx.payload — the raw job payload (whatever was enqueued)\n // ctx.job — queue job context\n // ctx.job.id, ctx.job.type, ctx.job.tries, ctx.job.tags, ...\n // ctx.job.heartbeat() — keep the job alive\n // ctx.job.markProgress(msg) — report progress\n // ctx.env — env facade: put, get, query, txn, ...\n // ctx.log — structured logger: ctx.log.info(msg, data)\n\n return { ok: true };\n}",p=[/(^|[^\w$.])require\s*\(/,/(^|[^\w$.])import\b/,/(^|[^\w$.])console\b/,/(^|[^\w$.])process\b/];function d(e){const n=(e||"").replace(/\r\n/g,"\n").trim();if(!n)return{ok:!1,message:"Source required"};if(!/^(async\s+)?\(\s*[A-Za-z_$][\w$]*\s*\)\s*=>/.test(n))return{ok:!1,message:"Must be (ctx) => { … }"};for(const e of p)if(e.test(n))return{ok:!1,message:"Forbidden pattern"};try{new Function(`return (${n});`)()}catch(e){return{ok:!1,message:e.message}}return{ok:!0,normalized:n}}function l(e="job"){return{id:`${e}-preview-1`,type:e,action:"process",priority:"normal",sample:!0,data:{note:"Example queue payload"}}}function c(e){try{return JSON.stringify(e,null,2)}catch{return String(e??"")}}export default{tag:"queue-workers",dependencies:[t,i,r,o],attr:{jobtype:{}},context:e=>({workers:[],busy:!1,error:null,_unsubs:[],showCreate:!1,creating:!1,createError:null,createSuccess:null,fnName:"",fnSource:s,fnValidation:d(s),fnMode:"new",existingFn:"",functions:[],concurrency:1,pollInterval:100,advanced:!1,samplePayload:l("job"),previewRunning:!1,previewResult:null,previewError:null,get jobType(){return e.$attr.jobtype||""},get envName(){return n.selectedEnv||"default"},get apiBase(){return n.apiBase},get handlerName(){return"existing"===this.fnMode?this.existingFn:this.fnName.trim()},get hasBoundJobType(){return!!this.jobType},get canCreate(){return!(!this.jobType||!this.handlerName||"new"===this.fnMode&&!this.fnValidation.ok)},get previewOk(){return!!this.previewResult&&"error"!==this.previewResult.status&&!this.previewResult.error},get previewLogs(){return Array.isArray(this.previewResult?.logs)?this.previewResult.logs:[]},get previewDuration(){return this.previewResult?.execution?.durationMs??null},get totalProcessed(){return(this.workers??[]).reduce((e,n)=>e+Number(n?.stats?.processed??0),0)},get totalFailed(){return(this.workers??[]).reduce((e,n)=>e+Number(n?.stats?.failed??0),0)},async load(){if(!this.jobType)return this.workers=[],this.error=null,void(this.busy=!1);this.busy=!0,this.error=null;try{const e=await fetch(`${this.apiBase}/engines?type=queue-worker`),n=await e.json(),t=n?.result??n?.data??[];this.workers=t.filter(e=>e.config?.job_type===this.jobType)}catch(e){this.error=e?.message||String(e)}finally{this.busy=!1}},async loadFunctions(){try{const e=await fetch(`${this.apiBase}/functions`),n=await e.json();this.functions=(n?.result??n?.data??[]).map(e=>e.name??e.key??e).filter(Boolean).sort()}catch{this.functions=[]}},openCreate(){this.jobType&&(this.showCreate=!0,this.createError=null,this.createSuccess=null,this.fnName="",this.fnSource=s,this.fnValidation=d(s),this.fnMode="new",this.existingFn="",this.previewResult=null,this.previewError=null,this.concurrency=1,this.pollInterval=100,this.samplePayload=l(this.jobType),this.loadFunctions())},cancelCreate(){this.showCreate=!1,this.createError=null},pickExistingFn(){this.fnMode="existing",this.loadFunctions()},pickNewFn(){this.fnMode="new",this.fnSource?.trim()||(this.fnSource=s,this.fnValidation=d(this.fnSource))},updateSource(e){this.fnSource=e??"",this.fnValidation=d(this.fnSource)},async preview(){if(this.fnValidation.ok&&!this.previewRunning){this.previewRunning=!0,this.previewResult=null,this.previewError=null;try{const e=await fetch(`${this.apiBase}/functions/preview`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({source:this.fnValidation.normalized,payload:this.samplePayload,jobContext:{id:"__preview__",type:this.jobType,tries:1,created:Date.now(),tags:null,priority:0}})}),n=await e.json();this.previewResult=n?.result??n?.data??null}catch(e){this.previewError=e?.message||String(e)}finally{this.previewRunning=!1}}},async create(){if(this.canCreate&&!this.creating){this.creating=!0,this.createError=null;try{if("new"===this.fnMode){const e=await fetch(`${this.apiBase}/functions`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:this.fnName.trim(),source:this.fnValidation.normalized,enabled:!0,metadata:{description:`Queue worker for ${this.jobType}`}})}),n=await e.json();if(!e.ok)throw new Error(n?.error?.message||"Failed to create function")}const e=`${this.jobType}-${this.handlerName}`,n=await fetch(`${this.apiBase}/engines`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"queue-worker",name:e,config:{job_type:this.jobType,handler:{kind:"function",name:this.handlerName},concurrency:Number(this.concurrency)||1,pollInterval:Number(this.pollInterval)||100}})}),t=await n.json();if(!n.ok)throw new Error(t?.error?.message||`Failed (${n.status})`);this.createSuccess=`Worker "${e}" created`,this.showCreate=!1,await this.load()}catch(e){this.createError=e?.message||String(e)}finally{this.creating=!1}}},async doAction(n,t){try{const i=await fetch(`${this.apiBase}/engines/${encodeURIComponent(n.type)}/${encodeURIComponent(n.name)}/${t}`,{method:"POST"}),r=await i.json().catch(()=>({}));if(!i.ok)throw new Error(r?.error?.message||`${t} failed`);const o="pause"===t?"Worker paused":"resume"===t?"Worker resumed":"restart"===t?"Worker restarted":`Worker ${t}d`;e.$ok.shared?.toast?.info?.(o),await this.load()}catch(n){e.$ok.shared?.toast?.error?.(n?.message||`${t} failed`)}},async doDelete(e){if(confirm(`Delete worker "${e.name}"?`))try{await fetch(`${this.apiBase}/engines/${encodeURIComponent(e.type)}/${encodeURIComponent(e.name)}`,{method:"DELETE"}),await this.load()}catch{}},async openWorkerModal(n){if(!n)return;const t=this;await e.$ok.shared.modal.open({owner:e,title:`Edit Worker · ${n.name}`,canDrag:!0,content:'<engine-modal :modal="modal" :engine="engine" :env="envName" :on-done="onDone" />',context:e=>({modal:e,engine:n,envName:t.envName,onDone:async()=>{await t.load()}})})},openWorkerFunction(n,t){t?.stopPropagation?.();const i=n?.config?.handler?.name;i&&a(e,i)},stateColor(e){const n=e?.stats?.state??e?.status;return"online"===n?"var(--okdb-success)":"error"===n?"var(--okdb-danger)":"paused"===n?"#818cf8":"building"===n?"#facc15":"var(--okdb-app-fg-muted)"},stateLabel:e=>e?.stats?.state??e?.status??"—",previewStatusColor:e=>e?"error"===e.status||e.error?"var(--okdb-danger)":"var(--okdb-success)":"var(--okdb-app-fg-muted)",formatJson:c}),async mount(t){await this.load();const i=()=>this.load();this._unsubs=[e.on("engine:started",i),e.on("engine:stopped",i),e.on("engine:error",i)],t.$watch(()=>t.$attr.jobtype,()=>{this.showCreate=!1,this.previewResult=null,this.previewError=null,this.samplePayload=l(t.$attr.jobtype||"job"),this.load()}),t.$watch(()=>n.selectedEnv,()=>{this.showCreate=!1,this.load()})},unmount(){for(const e of this._unsubs)e();this._unsubs=[]},template:'\n<div style="display:flex;flex-direction:column;gap:14px;flex:1;overflow:auto;padding-right:4px;">\n\n \x3c!-- Header --\x3e\n <div style="display:flex;align-items:center;gap:8px;flex-wrap:wrap;">\n <div style="font-weight:600;font-size:15px;">\n Queue Workers\n </div>\n <if :="jobType">\n <span style="font-size:11px;padding:2px 8px;border-radius:999px;background:color-mix(in srgb, var(--okdb-accent) 9%, transparent);border:1px solid color-mix(in srgb, var(--okdb-accent) 27%, transparent);color:var(--okdb-accent);">\n bound to {{ jobType }}\n </span>\n </if>\n <if :="workers.length > 0">\n <span style="font-size:11px;padding:2px 8px;border-radius:999px;background:color-mix(in srgb, var(--okdb-accent) 9%, transparent);border:1px solid color-mix(in srgb, var(--okdb-accent) 27%, transparent);color:var(--okdb-accent);">\n {{ workers.length }} worker{{ workers.length !== 1 ? \'s\' : \'\' }}\n </span>\n </if>\n <div style="flex:1;"></div>\n <button @click="load()" :disabled="busy" style="font-size:11px;padding:3px 8px;opacity:.6;">↻</button>\n <if :="!showCreate && hasBoundJobType">\n <button @click="openCreate()"\n style="font-size:12px;padding:5px 14px;background:color-mix(in srgb, var(--okdb-accent) 13%, transparent);border-color:var(--okdb-accent);color:var(--okdb-accent);font-weight:600;">\n + Add Worker\n </button>\n </if>\n </div>\n\n <if :="jobType">\n <div style="display:flex;align-items:flex-start;gap:12px;flex-wrap:wrap;padding:12px 14px;border:1px solid var(--okdb-app-border);border-radius:10px;background:var(--okdb-app-bg-deep);">\n <div style="display:flex;flex-direction:column;gap:4px;min-width:220px;">\n <div style="font-size:10px;text-transform:uppercase;letter-spacing:.06em;opacity:.45;">Scope</div>\n <div style="font-size:14px;font-weight:600;">{{ jobType }}</div>\n <div style="font-size:12px;opacity:.55;line-height:1.6;">\n Workers here are explicitly tied to this queue job type. They are not general-purpose consumers.\n </div>\n </div>\n <div style="display:flex;gap:18px;flex-wrap:wrap;font-size:11px;opacity:.65;">\n <span>workers: <b style="color:var(--okdb-app-fg-strong);opacity:1;">{{ workers.length }}</b></span>\n <span>processed: <b style="color:var(--okdb-success);opacity:1;">{{ totalProcessed }}</b></span>\n <if :="totalFailed > 0"><span>failed: <b style="color:var(--okdb-danger);opacity:1;">{{ totalFailed }}</b></span></if>\n </div>\n </div>\n </if>\n\n <if :="createSuccess && !showCreate">\n <div style="color:var(--okdb-success);font-size:12px;padding:6px 10px;border:1px solid color-mix(in srgb, var(--okdb-success) 20%, transparent);border-radius:6px;">\n ✓ {{ createSuccess }}\n </div>\n </if>\n <if :="error">\n <div style="color:var(--okdb-danger);font-size:12px;padding:6px 10px;border:1px solid color-mix(in srgb, var(--okdb-danger) 20%, transparent);border-radius:6px;">{{ error }}</div>\n </if>\n\n <if :="!hasBoundJobType && !showCreate">\n <div style="padding:32px 24px;background:var(--okdb-app-bg-deep);border:1px solid var(--okdb-app-border);border-radius:10px;display:flex;flex-direction:column;gap:12px;align-items:center;text-align:center;">\n <div style="font-size:34px;opacity:.18;">⇶</div>\n <div style="font-size:14px;font-weight:600;opacity:.72;">Select a queue job type</div>\n <div style="font-size:12px;opacity:.48;line-height:1.8;max-width:430px;">\n Queue workers are managed per job type. Pick a type from the sidebar to view its workers,\n create a new one, and test it against sample job payloads.\n </div>\n </div>\n </if>\n\n \x3c!-- Worker list --\x3e\n <if :="!showCreate">\n <if :="hasBoundJobType && !busy && workers.length === 0">\n <div style="padding:28px 20px;background:var(--okdb-app-bg-deep);border:1px solid var(--okdb-app-border);border-radius:10px;text-align:center;display:flex;flex-direction:column;gap:10px;align-items:center;">\n <div style="font-size:32px;opacity:.2;">⚙</div>\n <div style="font-size:14px;font-weight:600;opacity:.7;">No workers yet for "{{ jobType }}"</div>\n <div style="font-size:12px;opacity:.45;max-width:420px;line-height:1.7;">\n Create a worker bound to this queue job type. The worker will consume only <code>{{ jobType }}</code>\n jobs and run a specific function handler.\n </div>\n <button @click="openCreate()"\n style="margin-top:4px;font-size:12px;padding:6px 18px;background:color-mix(in srgb, var(--okdb-accent) 13%, transparent);border-color:var(--okdb-accent);color:var(--okdb-accent);font-weight:600;">\n + Add Worker\n </button>\n </div>\n </if>\n\n <each :of="workers" let:item="w">\n <div style="background:var(--okdb-app-surface);border:1px solid var(--okdb-app-border);border-radius:12px;padding:14px 16px;display:flex;flex-direction:column;gap:10px;">\n <div style="display:flex;align-items:center;gap:8px;min-width:0;">\n <engine-row-item\n :engine="w"\n label="Worker"\n label-color="var(--okdb-accent)"\n :subtitle="stateLabel(w)"\n @select="openWorkerModal($event.detail)"\n />\n <button @click="doAction(w,\'pause\')" title="Pause" style="font-size:11px;padding:2px 7px;color:var(--okdb-warning);border-color:color-mix(in srgb, var(--okdb-warning) 33%, transparent);">⏸</button>\n <button @click="doAction(w,\'resume\')" title="Resume" style="font-size:11px;padding:2px 7px;color:var(--okdb-success);border-color:color-mix(in srgb, var(--okdb-success) 33%, transparent);">▶</button>\n <button @click="doAction(w,\'restart\')" title="Restart" style="font-size:11px;padding:2px 7px;opacity:.6;">↺</button>\n <button @click="doDelete(w)" title="Delete" style="font-size:11px;padding:2px 7px;color:var(--okdb-danger);border-color:color-mix(in srgb, var(--okdb-danger) 20%, transparent);">🗑</button>\n </div>\n <div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(160px,1fr));gap:10px 14px;font-size:11px;">\n <div><div style="opacity:.4;text-transform:uppercase;letter-spacing:.05em;font-size:10px;">Job type</div><div style="margin-top:3px;color:var(--okdb-app-fg-strong);">{{ w.config?.job_type || \'—\' }}</div></div>\n <div>\n <div style="opacity:.4;text-transform:uppercase;letter-spacing:.05em;font-size:10px;">Handler</div>\n <div style="margin-top:3px;">\n <if :="w.config?.handler?.name">\n <button @click="openWorkerFunction(w, $event)" title="Open this handler in the Functions section." style="background:none;border:none;padding:0;color:var(--okdb-accent);font-size:11px;text-decoration:underline;text-underline-offset:2px;cursor:pointer;">ƒ {{ w.config?.handler?.name }} ↗</button>\n </if>\n <if :="!w.config?.handler?.name">\n <span style="color:var(--okdb-app-fg-strong);">—</span>\n </if>\n </div>\n </div>\n <div><div style="opacity:.4;text-transform:uppercase;letter-spacing:.05em;font-size:10px;">Concurrency</div><div style="margin-top:3px;color:var(--okdb-app-fg-strong);">{{ w.config?.concurrency ?? 1 }}</div></div>\n <div><div style="opacity:.4;text-transform:uppercase;letter-spacing:.05em;font-size:10px;">Poll interval</div><div style="margin-top:3px;color:var(--okdb-app-fg-strong);">{{ w.config?.pollInterval ?? 100 }} ms</div></div>\n <if :="w.stats">\n <div><div style="opacity:.4;text-transform:uppercase;letter-spacing:.05em;font-size:10px;">Processed</div><div style="margin-top:3px;color:var(--okdb-success);">{{ w.stats.processed ?? 0 }}</div></div>\n <div><div style="opacity:.4;text-transform:uppercase;letter-spacing:.05em;font-size:10px;">Failed</div><div :style="\'margin-top:3px;color:\' + ((w.stats.failed ?? 0) > 0 ? \'var(--okdb-danger)\' : \'var(--okdb-app-fg-strong)\')">{{ w.stats.failed ?? 0 }}</div></div>\n </if>\n </div>\n <if :="w.stats?.error">\n <div style="color:var(--okdb-danger);font-size:11px;padding:4px 8px;border:1px solid color-mix(in srgb, var(--okdb-danger) 20%, transparent);border-radius:4px;font-family:monospace;">{{ w.stats.error }}</div>\n </if>\n </div>\n </each>\n </if>\n\n \x3c!-- Create panel --\x3e\n <if :="showCreate">\n <div style="background:var(--okdb-app-surface);border:1px solid var(--okdb-app-border);border-radius:12px;padding:18px;display:flex;flex-direction:column;gap:16px;">\n <div style="font-weight:600;font-size:14px;display:flex;align-items:center;gap:8px;">\n <span>New Queue Worker</span>\n <span style="font-size:12px;color:var(--okdb-accent);opacity:.8;">bound to {{ jobType }}</span>\n <div style="flex:1;"></div>\n <button @click="cancelCreate()" style="font-size:11px;padding:2px 8px;opacity:.6;">✕ Cancel</button>\n </div>\n\n <div style="display:grid;grid-template-columns:minmax(0,1.35fr) minmax(320px,.95fr);gap:16px;align-items:start;">\n <div style="display:flex;flex-direction:column;gap:14px;min-width:0;">\n <div style="padding:14px;border:1px solid var(--okdb-app-border);border-radius:10px;background:var(--okdb-app-bg-deep);display:flex;flex-direction:column;gap:12px;">\n <div style="font-size:10px;text-transform:uppercase;letter-spacing:.06em;opacity:.45;">Binding</div>\n <div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(180px,1fr));gap:10px 14px;">\n <div><div style="font-size:10px;opacity:.4;text-transform:uppercase;letter-spacing:.05em;">Environment</div><div style="margin-top:3px;color:var(--okdb-app-fg-strong);">{{ envName }}</div></div>\n <div><div style="font-size:10px;opacity:.4;text-transform:uppercase;letter-spacing:.05em;">Job type</div><div style="margin-top:3px;color:var(--okdb-accent);font-weight:600;">{{ jobType }}</div></div>\n </div>\n <div style="font-size:11px;opacity:.5;line-height:1.6;">\n This worker will consume only <code>{{ jobType }}</code> jobs. The job type is fixed by the queue sidebar selection.\n </div>\n </div>\n\n <div style="padding:14px;border:1px solid var(--okdb-app-border);border-radius:10px;background:var(--okdb-app-bg-deep);display:flex;flex-direction:column;gap:12px;">\n <div style="display:flex;align-items:center;gap:8px;flex-wrap:wrap;">\n <div style="font-size:10px;text-transform:uppercase;letter-spacing:.06em;opacity:.45;">Handler</div>\n <div style="display:flex;gap:6px;">\n <button @click="pickNewFn()"\n :style="fnMode===\'new\' ? \'font-size:11px;padding:2px 10px;border-color:var(--okdb-accent);color:var(--okdb-accent);background:color-mix(in srgb, var(--okdb-accent) 7%, transparent);\' : \'font-size:11px;padding:2px 10px;opacity:.55;\'">\n Write new\n </button>\n <button @click="pickExistingFn()"\n :style="fnMode===\'existing\' ? \'font-size:11px;padding:2px 10px;border-color:var(--okdb-accent);color:var(--okdb-accent);background:color-mix(in srgb, var(--okdb-accent) 7%, transparent);\' : \'font-size:11px;padding:2px 10px;opacity:.55;\'">\n Pick existing\n </button>\n </div>\n </div>\n\n <if :="fnMode === \'new\'">\n <div style="display:grid;grid-template-columns:120px 1fr;gap:10px;align-items:center;font-size:13px;">\n <span style="opacity:.6;">Function name</span>\n <input :value="fnName" @input="fnName = $event.target.value"\n placeholder="e.g. handleOrderJob"\n style="background:var(--okdb-app-bg-deep);border:1px solid var(--okdb-app-border);border-radius:6px;padding:6px 8px;color:inherit;font-size:13px;width:100%;box-sizing:border-box;" />\n </div>\n\n <div style="display:flex;flex-direction:column;gap:6px;min-width:0;min-height:0;">\n <div style="font-size:10px;text-transform:uppercase;letter-spacing:.06em;opacity:.45;">Implementation</div>\n <div style="display:flex;flex-direction:column;min-height:420px;border:1px solid var(--okdb-app-border);border-radius:10px;overflow:hidden;background:#10171e;">\n <div style="display:flex;align-items:center;justify-content:space-between;gap:10px;padding:10px 12px;border-bottom:1px solid var(--okdb-app-border);">\n <div style="font-size:10px;text-transform:uppercase;letter-spacing:.06em;opacity:.45;">Worker handler</div>\n <div style="font-size:10px;opacity:.4;font-family:monospace;">async (ctx) => { }</div>\n </div>\n <div style="flex:1;min-height:0;background:#0d1318;display:flex;">\n <ok-js-input :value="fnSource" @edit="updateSource($event.detail)" style="display:block;" />\n </div>\n </div>\n <if :="fnValidation.ok">\n <div style="color:#86efac;font-size:11px;">✓ Valid function source</div>\n </if>\n <if :="!fnValidation.ok && fnSource.trim()">\n <div style="color:var(--okdb-danger);font-size:11px;">{{ fnValidation.message }}</div>\n </if>\n </div>\n </if>\n\n <if :="fnMode === \'existing\'">\n <div style="display:grid;grid-template-columns:120px 1fr;gap:10px;align-items:center;font-size:13px;">\n <span style="opacity:.6;">Function</span>\n <select :value="existingFn" @change="existingFn = $event.target.value"\n style="background:var(--okdb-app-bg-deep);border:1px solid var(--okdb-app-border);border-radius:6px;padding:6px 8px;color:inherit;font-size:13px;width:100%;box-sizing:border-box;">\n <option value="">— select function —</option>\n <each :of="functions" let:item="fn"><option :value="fn">{{ fn }}</option></each>\n </select>\n </div>\n <div style="font-size:11px;opacity:.5;line-height:1.6;">\n Pick an existing function already stored in this environment. Inline test preview is available when writing a new function in this panel.\n </div>\n </if>\n </div>\n </div>\n\n <div style="display:flex;flex-direction:column;gap:14px;min-width:0;">\n <div style="padding:14px;border:1px solid var(--okdb-app-border);border-radius:10px;background:var(--okdb-app-bg-deep);display:flex;flex-direction:column;gap:12px;">\n <div style="font-size:10px;text-transform:uppercase;letter-spacing:.06em;opacity:.45;">Runtime</div>\n <div style="display:grid;grid-template-columns:1fr 1fr;gap:10px;">\n <div>\n <div style="font-size:10px;opacity:.4;text-transform:uppercase;letter-spacing:.05em;">Concurrency</div>\n <input type="number" min="1" max="64" :value="concurrency" @input="concurrency = $event.target.value"\n style="margin-top:4px;background:var(--okdb-app-bg-deep);border:1px solid var(--okdb-app-border);border-radius:6px;padding:6px 8px;color:inherit;font-size:13px;width:100%;box-sizing:border-box;" />\n </div>\n <div>\n <div style="font-size:10px;opacity:.4;text-transform:uppercase;letter-spacing:.05em;">Poll interval</div>\n <input type="number" min="10" max="10000" :value="pollInterval" @input="pollInterval = $event.target.value"\n style="margin-top:4px;background:var(--okdb-app-bg-deep);border:1px solid var(--okdb-app-border);border-radius:6px;padding:6px 8px;color:inherit;font-size:13px;width:100%;box-sizing:border-box;" />\n <div style="font-size:10px;opacity:.4;margin-top:4px;">milliseconds</div>\n </div>\n </div>\n </div>\n\n <div style="padding:14px;border:1px solid var(--okdb-app-border);border-radius:10px;background:var(--okdb-app-bg-deep);display:flex;flex-direction:column;gap:12px;">\n <div style="display:flex;align-items:center;gap:8px;flex-wrap:wrap;">\n <div style="font-size:10px;text-transform:uppercase;letter-spacing:.06em;opacity:.45;">Testing</div>\n <if :="fnMode !== \'new\'"><span style="font-size:10px;color:var(--okdb-warning);opacity:.8;">inline preview works for new functions</span></if>\n </div>\n\n <div>\n <div style="font-size:10px;opacity:.4;text-transform:uppercase;letter-spacing:.05em;">Sample job payload</div>\n <div style="margin-top:6px;border:1px solid var(--okdb-app-border);border-radius:8px;overflow:hidden;background:var(--okdb-app-bg-deep);min-height:220px;display:flex;flex-direction:column;min-width:0;">\n <ok-json-input mode="textbox" :value="samplePayload" @edit="samplePayload = $event.detail" style="height:100%;display:flex;min-height:220px;" />\n </div>\n </div>\n\n <if :="fnMode === \'new\'">\n <div style="display:flex;align-items:center;gap:8px;flex-wrap:wrap;">\n <button @click="preview()" :disabled="!fnValidation.ok || previewRunning"\n style="font-size:12px;padding:5px 14px;background:color-mix(in srgb, var(--okdb-accent) 9%, transparent);border-color:color-mix(in srgb, var(--okdb-accent) 27%, transparent);color:var(--okdb-accent);">\n {{ previewRunning ? \'Running…\' : \'▷ Test with sample job\' }}\n </button>\n <span style="font-size:11px;opacity:.45;line-height:1.5;">\n Runs the draft against the sample payload above. Side-effects still write to live data.\n </span>\n </div>\n </if>\n\n <if :="previewError">\n <div style="color:var(--okdb-danger);font-size:11px;padding:8px 10px;border:1px solid color-mix(in srgb, var(--okdb-danger) 20%, transparent);border-radius:6px;">{{ previewError }}</div>\n </if>\n\n <if :="previewResult">\n <div style="display:flex;flex-direction:column;gap:8px;padding:10px;border:1px solid var(--okdb-app-border);border-radius:8px;background:#0f1418;">\n <div :style="\'font-size:12px;font-weight:600;color:\'+previewStatusColor(previewResult)">\n {{ previewOk ? \'✓ Function executed successfully\' : \'✕ Function returned an error\' }}\n </div>\n <div style="display:flex;gap:10px;flex-wrap:wrap;font-size:11px;opacity:.55;">\n <span>status: {{ previewResult.status || \'ok\' }}</span>\n <if :="previewDuration != null"><span>{{ previewDuration }}ms</span></if>\n </div>\n <pre :style="\'margin:0;max-height:220px;overflow:auto;padding:10px;border-radius:8px;background:var(--okdb-app-bg-deep);border:1px solid var(--okdb-app-border);font-size:11px;line-height:1.55;white-space:pre-wrap;word-break:break-word;color:\' + (previewOk ? \'var(--okdb-app-fg)\' : \'#fca5a5\')">{{ formatJson(previewOk ? (previewResult.result?.value ?? previewResult) : (previewResult.error ?? previewResult.result?.value ?? previewResult)) }}</pre>\n <if :="previewLogs.length > 0">\n <details>\n <summary style="font-size:10px;text-transform:uppercase;letter-spacing:.06em;opacity:.45;cursor:pointer;user-select:none;">Logs ({{ previewLogs.length }})</summary>\n <div style="margin-top:6px;display:flex;flex-direction:column;gap:4px;max-height:140px;overflow:auto;">\n <each :of="previewLogs" let:item="entry">\n <div style="font-size:11px;padding:6px 8px;border:1px solid var(--okdb-app-border);border-radius:6px;background:var(--okdb-app-bg-deep);display:flex;gap:8px;align-items:flex-start;">\n <span style="font-size:10px;text-transform:uppercase;opacity:.5;min-width:40px;">{{ entry.level || \'log\' }}</span>\n <span style="flex:1;">{{ entry.msg || entry.message || formatJson(entry) }}</span>\n </div>\n </each>\n </div>\n </details>\n </if>\n </div>\n </if>\n </div>\n </div>\n </div>\n\n <if :="createError">\n <div style="color:var(--okdb-danger);font-size:12px;padding:6px 10px;border:1px solid color-mix(in srgb, var(--okdb-danger) 20%, transparent);border-radius:6px;">{{ createError }}</div>\n </if>\n\n <div style="display:flex;justify-content:flex-end;gap:8px;">\n <button @click="cancelCreate()" style="font-size:12px;padding:5px 14px;opacity:.6;">Cancel</button>\n <button @click="create()" :disabled="!canCreate || creating"\n style="font-size:12px;padding:5px 18px;background:color-mix(in srgb, var(--okdb-accent) 13%, transparent);border-color:var(--okdb-accent);color:var(--okdb-accent);font-weight:600;">\n {{ creating ? \'Creating…\' : \'Create Worker\' }}\n </button>\n </div>\n </div>\n </if>\n\n</div>'};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
<script type="module">import s from"./parts/sync-topology.ok.js";import t from"./parts/sync-retention.ok.js";export default{tag:"sync-index",unwrap:!0,dependencies:[s,t],context:()=>({loading:!1,error:null,topology:null,availableEnvs:[],selectedNodeId:null,showConnect:!1,joinAddress:"",dataLink:!0,joinToken:"",joinUsername:"",joinPassword:"",showPasswordAuth:!1,joining:!1,joinError:null,selfNode:null,selfClock:null,selfClocks:{},selfTagsInput:"",savingSelf:!1,saveSelfError:null,async loadSelf(){try{const s=await fetch(`${__ENV__.API}/sync/info`),t=await s.json();s.ok&&(this.selfNode=t.data?.node??null,this.selfClock=t.data?.clock??null,this.selfClocks=t.data?.clocks??{},this.selfTagsInput=(this.selfNode?.tags??[]).join(", "))}catch{}},async loadTopology(){this.loading=!0,this.error=null;try{const s=await fetch(`${__ENV__.API}/sync/topology`),t=await s.json();if(!s.ok)throw new Error(t?.error?.message||"Failed to load topology");const o=t.data??t;this.topology=o.topology??o,this.availableEnvs=o.availableEnvs??[]}catch(s){this.error=s?.message||String(s)}finally{this.loading=!1}},async loadIdentity(){},openConnect(){this.joinAddress="",this.joinToken="",this.joinUsername="",this.joinPassword="",this.joinError=null,this.showPasswordAuth=!1,this.showConnect=!0},closeConnect(){this.showConnect=!1,this.joinError=null},async joinCluster(){if(this.joinAddress&&!this.joining){this.joining=!0,this.joinError=null;try{const s={address:this.joinAddress,data_link:this.dataLink};!this.showPasswordAuth&&this.joinToken.trim()?s.token=this.joinToken.trim():this.showPasswordAuth&&this.joinUsername.trim()&&(s.username=this.joinUsername.trim(),s.password=this.joinPassword);const t=await fetch(`${__ENV__.API}/sync/connect`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)}),o=await t.json();if(!t.ok)throw new Error(o?.error?.message||"Connect failed");this.closeConnect(),await this.loadTopology()}catch(s){this.joinError=s.message}finally{this.joining=!1}}},get selfClockEntries(){return Object.entries(this.selfClocks).filter(([s])=>"~system"!==s)},get selfTagList(){return this.parseTags(this.selfTagsInput)},parseTags:s=>String(s??"").split(",").map(s=>s.trim()).filter(Boolean).filter((s,t,o)=>o.indexOf(s)===t),selectNode(s){this.selectedNodeId=s||null},async saveSelfTags(){if(!this.savingSelf){this.savingSelf=!0,this.saveSelfError=null;try{const s=await fetch(`${__ENV__.API}/sync/self`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({tags:this.selfTagList})}),t=await s.json();if(!s.ok)throw new Error(t?.error?.message||"Failed to save node tags");this.selfNode=t.data?.node??t.result?.node??this.selfNode,this.selfTagsInput=(this.selfNode?.tags??[]).join(", "),await this.loadTopology()}catch(s){this.saveSelfError=s?.message||String(s)}finally{this.savingSelf=!1}}},async copyText(s){try{await navigator.clipboard.writeText(String(s??""))}catch(s){}}}),async mount(){await this.loadSelf(),await this.loadTopology()}};</script><template><component import="../../layouts/_default.ok.html"><template name="sidebar"><if :="selfNode"><div style="background:var(--okdb-app-surface);border:1px solid var(--okdb-app-border);border-radius:10px;padding:10px 12px;font-size:12px;display:flex;flex-direction:column;gap:6px"><div style="font-size:10px;text-transform:uppercase;letter-spacing:.06em;opacity:.5;margin-bottom:2px">This Node</div><div style="display:flex;align-items:center;gap:6px"><span style="width:7px;height:7px;border-radius:50%;background:var(--okdb-success);flex-shrink:0"></span> <span style="font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">{{selfNode.name || selfNode.id?.slice(0,8)}}</span></div><div style="display:grid;grid-template-columns:52px 1fr;gap:3px 8px;opacity:.8"><span style="opacity:.6">ID</span><div style="display:flex;align-items:center;gap:4px"><span style="font-family:monospace;font-size:11px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">{{selfNode.id?.slice(0, 12)}}… </span><span @click="copyText(selfNode.id)" style="cursor:pointer;opacity:.5;font-size:10px">⎘</span></div><if :="selfNode.address"><span style="opacity:.6">Addr</span> <span style="font-family:monospace;font-size:11px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap" :title="selfNode.address">{{selfNode.address}}</span></if></div><div style="border-top:1px solid var(--okdb-app-border);padding-top:8px;margin-top:4px;display:flex;flex-direction:column;gap:8px"><div style="font-size:10px;opacity:.4;text-transform:uppercase;letter-spacing:.05em">Node Tags</div><input :value="selfTagsInput" @input="selfTagsInput = $event.target.value" @keydown:enter="saveSelfTags()" placeholder="gpu, region:eu, fast-storage" style="font-family:monospace;font-size:12px"/><div style="display:flex;flex-wrap:wrap;gap:6px;min-height:20px"><if :="selfTagList.length === 0"><span style="font-size:11px;opacity:.45">No tags</span></if><for :="selfTagList" let:tag><span style="font-size:10px;padding:2px 8px;border-radius:999px;border:1px solid var(--okdb-accent-soft-border);color:var(--okdb-accent);background:var(--okdb-accent-soft-bg)">{{tag}}</span></for></div><if :="saveSelfError"><div style="font-size:11px;color:var(--okdb-danger)">{{saveSelfError}}</div></if><div style="display:flex;justify-content:flex-end"><button @click="saveSelfTags()" :disabled="savingSelf" style="font-size:11px;padding:4px 10px;background:var(--okdb-sky-soft-bg);border-color:var(--okdb-sky-soft-border);color:var(--okdb-sky)">{{ savingSelf ? 'Saving…' : 'Save Tags' }}</button></div></div><if :="selfClockEntries.length"><div style="border-top:1px solid var(--okdb-app-border);padding-top:6px;margin-top:2px"><div style="font-size:10px;opacity:.4;margin-bottom:4px;text-transform:uppercase;letter-spacing:.05em">Clocks</div><div style="display:grid;grid-template-columns:64px 1fr;gap:2px 8px;font-size:11px"><for :="selfClockEntries" let:entry><span style="opacity:.5;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">{{entry[0]}}</span> <span style="font-family:monospace;opacity:.8">{{entry[1]}}</span></for></div></div></if></div></if></template><template name="default"><div style="display:flex;flex-direction:column;gap:20px;height:100%"><div style="display:flex;justify-content:space-between;align-items:center"><div style="font-weight:600;font-size:18px">Sync Cluster</div><div style="display:flex;gap:8px"><button @click="loadTopology()" :disabled="loading">Refresh</button> <button @click="openConnect()" style="background:var(--okdb-sky-soft-bg);border-color:var(--okdb-sky-soft-border);color:var(--okdb-sky)">+ Connect Node</button></div></div><if :="error"><div style="color:var(--okdb-danger);font-size:13px">{{error}}</div></if><sync-topology :topology="topology" :available-envs="availableEnvs" :self-id="selfNode?.id" :selected-node-id="selectedNodeId" @select="selectNode($event.detail)"/><div style="border-top:1px solid var(--okdb-app-border);padding-top:20px"><sync-retention/></div></div><if :="showConnect"><div @click.self="closeConnect()" style="position:fixed;inset:0;z-index:1000;background:rgba(0,0,0,.65);display:flex;align-items:center;justify-content:center"><div style="background:var(--okdb-app-bg-deep);border:1px solid var(--okdb-app-border);border-radius:14px;padding:24px;width:440px;max-width:calc(100vw - 32px);display:flex;flex-direction:column;gap:16px;box-shadow:0 24px 64px rgba(0,0,0,.6)"><div style="display:flex;justify-content:space-between;align-items:center"><div style="font-weight:700;font-size:16px">Connect to Node</div><span @click="closeConnect()" style="cursor:pointer;opacity:.5;font-size:18px;line-height:1;padding:2px 6px">✕</span></div><div style="display:flex;flex-direction:column;gap:6px"><label style="font-size:11px;opacity:.5;text-transform:uppercase;letter-spacing:.06em">Remote address</label> <input :value="joinAddress" @input="joinAddress = $event.target.value" @keydown:enter="joinCluster()" placeholder="http://host:8484" style="font-family:monospace" autofocus/></div><div style="display:flex;flex-direction:column;gap:8px"><div style="display:flex;align-items:center;justify-content:space-between"><label style="font-size:11px;opacity:.5;text-transform:uppercase;letter-spacing:.06em">Credential</label><div style="display:flex;border:1px solid var(--okdb-app-border);border-radius:6px;overflow:hidden;font-size:11px"><button @click="showPasswordAuth = false" :style="!showPasswordAuth
|
|
2
|
-
? 'background:var(--okdb-app-surface);color:var(--okdb-app-fg-strong);border:none;padding:3px 12px;cursor:pointer;'
|
|
3
|
-
: 'background:transparent;color:var(--okdb-app-fg-subtle);border:none;padding:3px 12px;cursor:pointer;'">Token</button> <button @click="showPasswordAuth = true" :style="showPasswordAuth
|
|
4
|
-
? 'background:var(--okdb-app-surface);color:var(--okdb-app-fg-strong);border:none;padding:3px 12px;cursor:pointer;'
|
|
5
|
-
: 'background:transparent;color:var(--okdb-app-fg-subtle);border:none;padding:3px 12px;cursor:pointer;'">Login</button></div></div><if :="!showPasswordAuth"><input :value="joinToken" @input="joinToken = $event.target.value" @keydown:enter="joinCluster()" placeholder="Bearer token — leave blank if remote is open" style="font-family:monospace;font-size:12px"/></if><if :="showPasswordAuth"><div style="display:flex;gap:8px"><input :value="joinUsername" @input="joinUsername = $event.target.value" placeholder="Username" style="flex:1"/> <input type="password" :value="joinPassword" @input="joinPassword = $event.target.value" @keydown:enter="joinCluster()" placeholder="Password" style="flex:1"/></div></if></div><div style="display:flex;align-items:center;gap:8px;font-size:12px;opacity:.8"><input type="checkbox" id="modalDataLink" :checked="dataLink" @change="dataLink = $event.target.checked" style="cursor:pointer"/> <label for="modalDataLink" style="cursor:pointer">Sync data immediately <span style="opacity:.5;font-size:11px">(unchecked = topology only)</span></label></div><if :="joinError"><div style="font-size:12px;color:var(--okdb-danger);background:var(--okdb-danger-soft-bg);border:1px solid var(--okdb-danger-soft-border);border-radius:8px;padding:8px 12px">{{joinError}}</div></if><div style="display:flex;justify-content:flex-end;gap:8px;margin-top:4px"><button @click="closeConnect()" style="opacity:.7">Cancel</button> <button @click="joinCluster()" :disabled="!joinAddress || joining" style="background:var(--okdb-sky-soft-bg);border-color:var(--okdb-sky-soft-border);color:var(--okdb-sky);min-width:100px">{{ joining ? 'Connecting…' : 'Connect' }}</button></div></div></div></if></template></component></template>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default{tag:"sync-node-detail",unwrap:!0,context:e=>({get topology(){return e.$attr.topology||{}},get nodeId(){return e.$attr.nodeId},get node(){return this.topology?.[this.nodeId]||null},get tags(){return Array.isArray(this.node?.tags)?this.node.tags:[]},pretty(e){if(null==e)return"";try{return JSON.stringify(e,null,2)}catch{return String(e)}}}),template:'<if :="node"><div style="border:1px solid var(--okdb-app-border); border-radius:10px; padding:14px; background:var(--okdb-app-bg); display:flex; flex-direction:column; gap:12px;"><div style="display:flex; align-items:center; gap:8px;"><div style="font-weight:600; flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;">Node Detail: {{node.id}}</div><if :="node.error"><span style="font-size:10px; padding:2px 8px; border-radius:999px; color:var(--okdb-danger); border:1px solid color-mix(in srgb, var(--okdb-danger) 20%, transparent);">error</span></if></div><div style="display:grid; grid-template-columns:repeat(auto-fit,minmax(180px,1fr)); gap:10px 14px; font-size:12px;"><div><div style="opacity:.45; font-size:10px; text-transform:uppercase; letter-spacing:.05em;">Address</div><div style="margin-top:4px; font-family:monospace; word-break:break-all;">{{node.address || \'—\'}}</div></div><div><div style="opacity:.45; font-size:10px; text-transform:uppercase; letter-spacing:.05em;">Clock</div><div style="margin-top:4px; font-family:monospace;">{{node.clock ?? \'—\'}}</div></div><div><div style="opacity:.45; font-size:10px; text-transform:uppercase; letter-spacing:.05em;">Available envs</div><div style="margin-top:4px;">{{(node.availableEnvs || []).join(\', \') || \'—\'}}</div></div></div><div style="display:flex; flex-direction:column; gap:6px;"><div style="opacity:.45; font-size:10px; text-transform:uppercase; letter-spacing:.05em;">Tags</div><div style="display:flex; flex-wrap:wrap; gap:6px; min-height:20px;"><if :="tags.length === 0"><span style="font-size:11px; opacity:.45;">No tags</span></if><for :="tags" let:tag><span style="font-size:10px; padding:2px 8px; border-radius:999px; border:1px solid var(--okdb-accent-soft-border); color:var(--okdb-accent); background:var(--okdb-accent-soft-bg);">{{tag}}</span></for></div></div><pre style="font-size:12px; margin:0; overflow:auto; background:var(--okdb-app-bg-deep); border:1px solid var(--okdb-app-border); border-radius:8px; padding:10px;">\n{{pretty(node)}}\n </pre></div></if>'};
|