@zodic/shared 0.0.183 → 0.0.185
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { DurableObjectState } from '@cloudflare/workers-types';
|
|
2
|
-
import { ConceptProgress } from '../../types';
|
|
3
2
|
|
|
4
3
|
export class ConceptNameDO {
|
|
5
4
|
state: DurableObjectState;
|
|
@@ -7,7 +6,7 @@ export class ConceptNameDO {
|
|
|
7
6
|
names: { 'en-us': string[]; 'pt-br': string[] };
|
|
8
7
|
count: number;
|
|
9
8
|
timestamps: number[];
|
|
10
|
-
lastIndex: number; // ✅
|
|
9
|
+
lastIndex: number; // ✅ Tracks last processed index
|
|
11
10
|
|
|
12
11
|
static TOTAL_NAMES = 1728; // Maximum total names to be generated
|
|
13
12
|
|
|
@@ -24,6 +23,8 @@ export class ConceptNameDO {
|
|
|
24
23
|
const url = new URL(request.url);
|
|
25
24
|
const method = request.method;
|
|
26
25
|
|
|
26
|
+
console.log(`📥 DO Received Request: ${method} ${url.pathname}`);
|
|
27
|
+
|
|
27
28
|
if (method === 'GET' && url.pathname === '/names') {
|
|
28
29
|
return new Response(JSON.stringify(await this.getNames()), {
|
|
29
30
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -43,16 +44,17 @@ export class ConceptNameDO {
|
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
if (method === 'POST' && url.pathname === '/add-name') {
|
|
46
|
-
const { language, name } = (await request.json()) as {
|
|
47
|
+
const { language, name, index } = (await request.json()) as {
|
|
47
48
|
language: 'en-us' | 'pt-br';
|
|
48
49
|
name: string;
|
|
50
|
+
index: number;
|
|
49
51
|
};
|
|
50
52
|
|
|
51
53
|
if (!['en-us', 'pt-br'].includes(language)) {
|
|
52
54
|
return new Response('Invalid language', { status: 400 });
|
|
53
55
|
}
|
|
54
56
|
|
|
55
|
-
await this.addName(language, name);
|
|
57
|
+
await this.addName(language, name, index);
|
|
56
58
|
return new Response('OK', { status: 200 });
|
|
57
59
|
}
|
|
58
60
|
|
|
@@ -75,9 +77,17 @@ export class ConceptNameDO {
|
|
|
75
77
|
return this.names;
|
|
76
78
|
}
|
|
77
79
|
|
|
78
|
-
async getProgress(): Promise<
|
|
80
|
+
async getProgress(): Promise<{
|
|
81
|
+
count: number;
|
|
82
|
+
total: number;
|
|
83
|
+
lastIndex: number;
|
|
84
|
+
progress: string;
|
|
85
|
+
ratePerMinute: number;
|
|
86
|
+
estimatedTimeMinutes: number | 'N/A';
|
|
87
|
+
}> {
|
|
79
88
|
await this.loadCount();
|
|
80
89
|
await this.loadTimestamps();
|
|
90
|
+
await this.loadLastIndex(); // ✅ Ensure latest lastIndex is fetched
|
|
81
91
|
|
|
82
92
|
const now = Date.now();
|
|
83
93
|
const oneMinuteAgo = now - 60 * 1000;
|
|
@@ -92,7 +102,7 @@ export class ConceptNameDO {
|
|
|
92
102
|
return {
|
|
93
103
|
count: this.count,
|
|
94
104
|
total: ConceptNameDO.TOTAL_NAMES,
|
|
95
|
-
lastIndex: this.lastIndex,
|
|
105
|
+
lastIndex: this.lastIndex, // ✅ Include lastIndex in response
|
|
96
106
|
progress:
|
|
97
107
|
((this.count / ConceptNameDO.TOTAL_NAMES) * 100).toFixed(2) + '%',
|
|
98
108
|
ratePerMinute,
|
|
@@ -101,29 +111,40 @@ export class ConceptNameDO {
|
|
|
101
111
|
}
|
|
102
112
|
|
|
103
113
|
async getLastIndex(): Promise<number> {
|
|
104
|
-
|
|
105
|
-
this.lastIndex = (await this.state.storage.get<number>('lastIndex')) || 0;
|
|
106
|
-
}
|
|
114
|
+
await this.loadLastIndex(); // ✅ Fetch lastIndex from storage
|
|
107
115
|
return this.lastIndex;
|
|
108
116
|
}
|
|
109
117
|
|
|
110
|
-
async addName(
|
|
118
|
+
async addName(
|
|
119
|
+
language: 'en-us' | 'pt-br',
|
|
120
|
+
name: string,
|
|
121
|
+
index: number
|
|
122
|
+
): Promise<void> {
|
|
111
123
|
await this.getNames();
|
|
112
124
|
await this.loadCount();
|
|
125
|
+
await this.loadLastIndex(); // ✅ Ensure lastIndex is loaded before modifying
|
|
113
126
|
|
|
114
127
|
if (!this.names[language].includes(name)) {
|
|
115
128
|
this.names[language].push(name);
|
|
116
129
|
this.count += 1;
|
|
130
|
+
|
|
117
131
|
this.recordTimestamp();
|
|
118
132
|
|
|
133
|
+
// 🔥 **Ensure lastIndex is updated**
|
|
134
|
+
if (index > this.lastIndex) {
|
|
135
|
+
this.lastIndex = index;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// 🔥 **Store all updated values in a single put() call**
|
|
119
139
|
await this.state.storage.put({
|
|
120
140
|
names: this.names,
|
|
121
141
|
count: this.count,
|
|
122
142
|
timestamps: this.timestamps,
|
|
143
|
+
lastIndex: this.lastIndex, // ✅ Store the last processed index
|
|
123
144
|
});
|
|
124
145
|
|
|
125
146
|
console.log(
|
|
126
|
-
`✅ Added name "${name}" to ${language}, count
|
|
147
|
+
`✅ Added name "${name}" to ${language}, count: ${this.count}, lastIndex: ${this.lastIndex}`
|
|
127
148
|
);
|
|
128
149
|
}
|
|
129
150
|
}
|
|
@@ -131,12 +152,22 @@ export class ConceptNameDO {
|
|
|
131
152
|
async setLastIndex(lastIndex: number): Promise<void> {
|
|
132
153
|
this.lastIndex = lastIndex;
|
|
133
154
|
await this.state.storage.put('lastIndex', this.lastIndex);
|
|
155
|
+
console.log(`📌 Updated lastIndex to ${this.lastIndex}`);
|
|
134
156
|
}
|
|
135
157
|
|
|
136
158
|
async loadCount(): Promise<void> {
|
|
137
159
|
this.count = (await this.state.storage.get<number>('count')) || 0;
|
|
138
160
|
}
|
|
139
161
|
|
|
162
|
+
async loadLastIndex(): Promise<void> {
|
|
163
|
+
const storedIndex = await this.state.storage.get<number>('lastIndex');
|
|
164
|
+
if (typeof storedIndex === 'number') {
|
|
165
|
+
this.lastIndex = storedIndex;
|
|
166
|
+
} else {
|
|
167
|
+
this.lastIndex = 0; // ✅ Ensure it starts from 0
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
140
171
|
async loadTimestamps(): Promise<void> {
|
|
141
172
|
this.timestamps =
|
|
142
173
|
(await this.state.storage.get<number[]>('timestamps')) || [];
|
|
@@ -76,7 +76,7 @@ export class ConceptWorkflow {
|
|
|
76
76
|
`🚀 Processing batch for concept: ${conceptSlug}, Phase: ${phase}, Total Combinations: ${combinations.length}`
|
|
77
77
|
);
|
|
78
78
|
|
|
79
|
-
const concurrency =
|
|
79
|
+
const concurrency = 5;
|
|
80
80
|
const failedCombinations: string[] = [];
|
|
81
81
|
|
|
82
82
|
// ✅ Get Durable Object stub for progress tracking
|
package/package.json
CHANGED
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
import { DrizzleD1Database } from 'drizzle-orm/d1';
|
|
10
10
|
import { Context, Env } from 'hono';
|
|
11
11
|
import type { Container } from 'inversify';
|
|
12
|
-
import { ConceptNameDO } from '../../app';
|
|
13
12
|
|
|
14
13
|
export type CentralBindings = {
|
|
15
14
|
TEST_IMAGES_BUCKET: R2Bucket;
|
|
@@ -27,6 +26,7 @@ export type CentralBindings = {
|
|
|
27
26
|
KV_CONCEPT_NAMES: KVNamespace;
|
|
28
27
|
CONCEPT_GENERATION_QUEUE: Queue;
|
|
29
28
|
CONCEPT_NAMES_DO: DurableObjectNamespace;
|
|
29
|
+
CROWN_QUEUE: Queue;
|
|
30
30
|
|
|
31
31
|
PROMPT_IMAGE_DESCRIBER: string;
|
|
32
32
|
PROMPT_GENERATE_ARCHETYPE_BASIC_INFO: string;
|
|
@@ -117,6 +117,7 @@ export type BackendBindings = Env &
|
|
|
117
117
|
| 'TOGETHER_API_KEY'
|
|
118
118
|
| 'CONCEPT_NAMES_DO'
|
|
119
119
|
| 'API_BASE_URL'
|
|
120
|
+
| 'CROWN_QUEUE'
|
|
120
121
|
>;
|
|
121
122
|
|
|
122
123
|
export type BackendCtx = Context<
|