@zodic/shared 0.0.163 → 0.0.164

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.
@@ -0,0 +1,59 @@
1
+ import { DurableObjectState } from '@cloudflare/workers-types';
2
+
3
+ export class ConceptNameDO {
4
+ state: DurableObjectState;
5
+ env: any;
6
+ names: { 'en-us': string[]; 'pt-br': string[] };
7
+
8
+ constructor(state: DurableObjectState, env: any) {
9
+ this.state = state;
10
+ this.env = env;
11
+ this.names = { 'en-us': [], 'pt-br': [] };
12
+ }
13
+
14
+ async fetch(request: Request): Promise<Response> {
15
+ const url = new URL(request.url);
16
+ const method = request.method;
17
+
18
+ if (method === 'GET' && url.pathname === '/names') {
19
+ await this.loadNames();
20
+ return new Response(JSON.stringify(this.names), {
21
+ headers: { 'Content-Type': 'application/json' },
22
+ });
23
+ }
24
+
25
+ if (method === 'POST' && url.pathname === '/add-name') {
26
+ const { language, name } = (await request.json()) as {
27
+ language: 'en-us' | 'pt-br';
28
+ name: string;
29
+ };
30
+
31
+ // ✅ Normalize language codes to match `generateBasicInfo`
32
+ if (!['en-us', 'pt-br'].includes(language)) {
33
+ return new Response('Invalid language', { status: 400 });
34
+ }
35
+
36
+ await this.addName(language, name);
37
+ return new Response('OK', { status: 200 });
38
+ }
39
+
40
+ return new Response('Not Found', { status: 404 });
41
+ }
42
+
43
+ async loadNames(): Promise<void> {
44
+ const stored = await this.state.storage.get<{
45
+ 'en-us': string[];
46
+ 'pt-br': string[];
47
+ }>('names');
48
+ if (stored) {
49
+ this.names = stored;
50
+ }
51
+ }
52
+
53
+ async addName(language: 'en-us' | 'pt-br', name: string): Promise<void> {
54
+ if (!this.names[language].includes(name)) {
55
+ this.names[language].push(name);
56
+ await this.state.storage.put('names', this.names);
57
+ }
58
+ }
59
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zodic/shared",
3
- "version": "0.0.163",
3
+ "version": "0.0.164",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  Ai,
3
3
  D1Database,
4
+ DurableObject,
4
5
  KVNamespace,
5
6
  Queue,
6
7
  R2Bucket,
@@ -24,6 +25,7 @@ export type CentralBindings = {
24
25
  KV_CONCEPT_FAILURES: KVNamespace;
25
26
  KV_CONCEPT_NAMES: KVNamespace;
26
27
  CONCEPT_GENERATION_QUEUE: Queue;
28
+ CONCEPT_NAMES_DO: DurableObject;
27
29
 
28
30
  PROMPT_IMAGE_DESCRIBER: string;
29
31
  PROMPT_GENERATE_ARCHETYPE_BASIC_INFO: string;
@@ -112,6 +114,7 @@ export type BackendBindings = Env &
112
114
  | 'DEEPSEEK_API_KEY'
113
115
  | 'PROMPT_GENERATE_ARCHETYPE_BASIC_INFO'
114
116
  | 'TOGETHER_API_KEY'
117
+ | 'CONCEPT_NAMES_DO'
115
118
  >;
116
119
 
117
120
  export type BackendCtx = Context<