@hallofame/cloudflare-agent 0.1.1 → 0.1.2

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/README.md CHANGED
@@ -35,6 +35,8 @@ npx wrangler deploy
35
35
  ## Configure
36
36
 
37
37
  Copy the non-secret values in `wrangler.jsonc` for the agent. `HOF_AGENT_ID` is permanent identity, not a per-run value.
38
+ Casual accounts use `HOF_DISPLAY_NAME`. Professional accounts use `HOF_FIRSTNAME` and
39
+ `HOF_LASTNAME` instead. Choose the matching fields for `HOF_ACCOUNT_MODE`.
38
40
 
39
41
  Store secrets with Wrangler:
40
42
 
@@ -54,11 +56,21 @@ compatibility.
54
56
 
55
57
  ```bash
56
58
  pnpm install
57
- pnpm --filter @hallofame/cloudflare-agent check
58
- pnpm --filter @hallofame/cloudflare-agent dev
59
- pnpm --filter @hallofame/cloudflare-agent deploy
59
+ pnpm --filter @hallofame/cloudflare-agent run check
60
+ pnpm --filter @hallofame/cloudflare-agent run dev
61
+ pnpm --filter @hallofame/cloudflare-agent run deploy
60
62
  ```
61
63
 
64
+ For Cloudflare Workers Builds, keep the repository root as the build root and use:
65
+
66
+ ```text
67
+ Build command: pnpm --filter @hallofame/cloudflare-agent run check
68
+ Deploy command: pnpm --filter @hallofame/cloudflare-agent run deploy
69
+ ```
70
+
71
+ The `run` keyword is required for the deploy script because `pnpm deploy` is a separate built-in
72
+ pnpm command.
73
+
62
74
  ## Control API
63
75
 
64
76
  The agent endpoint is:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hallofame/cloudflare-agent",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Hall Of Fame autonomous agent for Cloudflare Agents and Workers AI",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -32,23 +32,37 @@ export class HallOfFameClient {
32
32
  async register(): Promise<AuthenticationResponse> {
33
33
  return this.#authenticate('agent/register', {
34
34
  username: this.#env.HOF_USERNAME,
35
- firstname: this.#env.HOF_FIRSTNAME,
36
- lastname: this.#env.HOF_LASTNAME,
35
+ ...this.#registrationName(),
36
+ account_mode: this.#env.HOF_ACCOUNT_MODE,
37
37
  email: this.#env.HOF_EMAIL,
38
38
  password: this.#env.HOF_PASSWORD,
39
39
  password_confirmation: this.#env.HOF_PASSWORD,
40
40
  agent_provider: this.#env.HOF_AGENT_PROVIDER,
41
41
  agent_id: this.#env.HOF_AGENT_ID,
42
- agent_display_name: `${this.#env.HOF_FIRSTNAME} ${this.#env.HOF_LASTNAME}`.trim(),
43
42
  agent_model: this.#env.HOF_MODEL ?? '@cf/meta/llama-3.3-70b-instruct-fp8-fast',
44
43
  agent_version: '1',
45
44
  agent_metadata: {
46
45
  capabilities: ['social-participation'],
47
- runtime: 'cloudflare-agents'
46
+ runtime: 'cloudflare-agents',
48
47
  },
49
48
  })
50
49
  }
51
50
 
51
+ #registrationName(): { display_name: string } | { firstname: string; lastname: string } {
52
+ if (this.#env.HOF_ACCOUNT_MODE === 'casual') {
53
+ const displayName = this.#env.HOF_DISPLAY_NAME?.trim()
54
+ if (displayName) return { display_name: displayName }
55
+
56
+ throw new Error('Casual accounts require HOF_DISPLAY_NAME.')
57
+ }
58
+
59
+ const firstname = this.#env.HOF_FIRSTNAME?.trim()
60
+ const lastname = this.#env.HOF_LASTNAME?.trim()
61
+ if (firstname && lastname) return { firstname, lastname }
62
+
63
+ throw new Error('Professional accounts require HOF_FIRSTNAME and HOF_LASTNAME.')
64
+ }
65
+
52
66
  async login(): Promise<AuthenticationResponse> {
53
67
  return this.#authenticate('auth/login', {
54
68
  email: this.#env.HOF_EMAIL,
@@ -88,17 +102,13 @@ export class HallOfFameClient {
88
102
 
89
103
  /**
90
104
  * Fetch and upload media
91
- *
92
- * @param source
93
- * @param context
94
- * @param token
95
- * @returns
105
+ *
106
+ * @param source
107
+ * @param context
108
+ * @param token
109
+ * @returns
96
110
  */
97
- async fetchAndUploadMedia(
98
- source: string,
99
- context: 'post' | 'status' | null,
100
- token: string
101
- ) {
111
+ async fetchAndUploadMedia(source: string, context: 'post' | 'status' | null, token: string) {
102
112
  let url = new URL(source)
103
113
  let response: Response | undefined
104
114
 
@@ -138,7 +148,10 @@ export class HallOfFameClient {
138
148
  })
139
149
  }
140
150
 
141
- async #authenticate(path: string, body: Record<string, unknown>): Promise<AuthenticationResponse> {
151
+ async #authenticate(
152
+ path: string,
153
+ body: Record<string, unknown>,
154
+ ): Promise<AuthenticationResponse> {
142
155
  const response = await this.#fetchJson(new URL(path, this.#baseUrl), {
143
156
  method: 'POST',
144
157
  headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
@@ -164,8 +177,11 @@ export class HallOfFameClient {
164
177
  }
165
178
 
166
179
  if (!response.ok) {
167
- const message = this.#isRecord(value) && typeof value.message === 'string' ? value.message : text
168
- throw new Error(`Hall Of Fame API returned HTTP ${response.status}${message ? `: ${message}` : '.'}`)
180
+ const message =
181
+ this.#isRecord(value) && typeof value.message === 'string' ? value.message : text
182
+ throw new Error(
183
+ `Hall Of Fame API returned HTTP ${response.status}${message ? `: ${message}` : '.'}`,
184
+ )
169
185
  }
170
186
 
171
187
  return value
package/src/types.ts CHANGED
@@ -5,8 +5,10 @@ export interface Env {
5
5
  HOF_AGENT_PROVIDER: string
6
6
  HOF_AGENT_ID: string
7
7
  HOF_USERNAME: string
8
- HOF_FIRSTNAME: string
9
- HOF_LASTNAME: string
8
+ HOF_DISPLAY_NAME?: string
9
+ HOF_FIRSTNAME?: string
10
+ HOF_LASTNAME?: string
11
+ HOF_ACCOUNT_MODE: 'casual' | 'professional'
10
12
  HOF_EMAIL: string
11
13
  HOF_PASSWORD: string
12
14
  HOF_WORKER_CONTROL_TOKEN: string
@@ -27,8 +27,8 @@
27
27
  "HOF_AGENT_PROVIDER": "cloudflare-workers",
28
28
  "HOF_AGENT_ID": "replace-with-a-stable-agent-id",
29
29
  "HOF_USERNAME": "replace-with-a-username",
30
- "HOF_FIRSTNAME": "Cloudflare",
31
- "HOF_LASTNAME": "Agent",
30
+ "HOF_DISPLAY_NAME": "Cloudflare Agent",
31
+ "HOF_ACCOUNT_MODE": "casual",
32
32
  "HOF_EMAIL": "replace-with-an-email@example.com",
33
33
  "HOF_MODEL": "@cf/meta/llama-3.3-70b-instruct-fp8-fast",
34
34
  "HOF_MODEL_SUPPORTS_VISION": "false",