@agentworkforce/sage 1.2.3 → 1.2.4

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 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,EAAE,aAAa,EAAE,CAAC;AACzB,YAAY,EAAE,YAAY,EAAE,CAAC;;mBAGZ,OAAO,OAAO,YAAY,OAAO,gBAAgB;;AADlE,wBAIE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAElE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,EAAE,aAAa,EAAE,CAAC;AACzB,YAAY,EAAE,YAAY,EAAE,CAAC;;mBAKZ,OAAO,OAAO,YAAY,OAAO,gBAAgB;;AADlE,wBAoBE"}
package/dist/index.js CHANGED
@@ -2,9 +2,25 @@
2
2
  * NPM package entry consumed by the cloud worker runtime.
3
3
  */
4
4
  import { createSageApp } from "./app.js";
5
+ import { registerProactiveSchedules } from "./proactive/scheduler.js";
5
6
  export { createSageApp };
7
+ let schedulesRegistered = false;
6
8
  export default {
7
9
  fetch(request, env, ctx) {
10
+ if (!schedulesRegistered) {
11
+ schedulesRegistered = true;
12
+ ctx.waitUntil(registerProactiveSchedules(env)
13
+ .then((success) => {
14
+ if (!success) {
15
+ schedulesRegistered = false;
16
+ console.error("[sage] Proactive schedule registration failed; will retry on next request");
17
+ }
18
+ })
19
+ .catch((error) => {
20
+ schedulesRegistered = false;
21
+ console.error("[sage] Failed to register proactive schedules:", error);
22
+ }));
23
+ }
8
24
  return createSageApp().fetch(request, env, ctx);
9
25
  },
10
26
  };
@@ -1,2 +1,8 @@
1
- export declare function registerProactiveSchedules(): Promise<void>;
1
+ interface SchedulerBindings {
2
+ AGENTCRON_API_KEY?: string;
3
+ AGENTCRON_URL?: string;
4
+ SAGE_PUBLIC_URL?: string;
5
+ }
6
+ export declare function registerProactiveSchedules(bindings?: SchedulerBindings): Promise<boolean>;
7
+ export {};
2
8
  //# sourceMappingURL=scheduler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../../src/proactive/scheduler.ts"],"names":[],"mappings":"AAyQA,wBAAsB,0BAA0B,IAAI,OAAO,CAAC,IAAI,CAAC,CA4EhE"}
1
+ {"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../../src/proactive/scheduler.ts"],"names":[],"mappings":"AAyOA,UAAU,iBAAiB;IACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAiDD,wBAAsB,0BAA0B,CAC9C,QAAQ,CAAC,EAAE,iBAAiB,GAC3B,OAAO,CAAC,OAAO,CAAC,CAiFlB"}
@@ -27,7 +27,7 @@ class AgentCron {
27
27
  baseUrl;
28
28
  constructor(options) {
29
29
  this.apiKey = options.apiKey;
30
- this.baseUrl = (options.baseUrl ?? "https://api.agentcron.dev").replace(/\/$/, "");
30
+ this.baseUrl = (options.baseUrl ?? "https://api.relaycron.dev").replace(/\/$/, "");
31
31
  }
32
32
  async createSchedule(params) {
33
33
  return this.request("POST", "/v1/schedules", params);
@@ -96,7 +96,7 @@ class AgentCron {
96
96
  }
97
97
  }
98
98
  const SCHEDULE_NAME_PREFIX = "sage-";
99
- const DEFAULT_AGENTCRON_URL = "https://api.agentcron.dev";
99
+ const DEFAULT_AGENTCRON_URL = "https://api.relaycron.dev";
100
100
  const DEFAULT_TIMEZONE = "UTC";
101
101
  const AGENTCRON_REQUEST_TIMEOUT_MS = 15_000;
102
102
  const WEBHOOK_TIMEOUT_MS = 10_000;
@@ -127,14 +127,22 @@ function requireTrimmedEnv(name) {
127
127
  }
128
128
  return value;
129
129
  }
130
- function createClient() {
130
+ function bindingValue(bindings, name) {
131
+ return bindings?.[name]?.trim() || undefined;
132
+ }
133
+ function createClient(bindings) {
131
134
  return new AgentCron({
132
- apiKey: requireTrimmedEnv("AGENTCRON_API_KEY"),
133
- baseUrl: env.AGENTCRON_URL?.trim() || DEFAULT_AGENTCRON_URL,
135
+ apiKey: bindingValue(bindings, "AGENTCRON_API_KEY") ||
136
+ requireTrimmedEnv("AGENTCRON_API_KEY"),
137
+ baseUrl: bindingValue(bindings, "AGENTCRON_URL") ||
138
+ env.AGENTCRON_URL?.trim() ||
139
+ DEFAULT_AGENTCRON_URL,
134
140
  });
135
141
  }
136
- function getPublicUrl() {
137
- return requireTrimmedEnv("SAGE_PUBLIC_URL").replace(/\/$/, "");
142
+ function getPublicUrl(bindings) {
143
+ const value = bindingValue(bindings, "SAGE_PUBLIC_URL") ||
144
+ requireTrimmedEnv("SAGE_PUBLIC_URL");
145
+ return value.replace(/\/$/, "");
138
146
  }
139
147
  function buildWebhookUrl(publicUrl, path) {
140
148
  return `${publicUrl}${path.startsWith("/") ? path : `/${path}`}`;
@@ -153,16 +161,17 @@ async function listExistingScheduleIds(client) {
153
161
  } while (cursor);
154
162
  return schedules;
155
163
  }
156
- export async function registerProactiveSchedules() {
164
+ export async function registerProactiveSchedules(bindings) {
157
165
  let client;
158
166
  let publicUrl;
159
167
  try {
160
- client = createClient();
161
- publicUrl = getPublicUrl();
168
+ client = createClient(bindings);
169
+ publicUrl = getPublicUrl(bindings);
162
170
  }
163
171
  catch (error) {
164
172
  console.warn("[proactive/scheduler] Skipping schedule registration:", error instanceof Error ? error.message : String(error));
165
- return;
173
+ // Missing config is permanent — no point retrying.
174
+ return true;
166
175
  }
167
176
  let existingScheduleIds;
168
177
  try {
@@ -170,8 +179,10 @@ export async function registerProactiveSchedules() {
170
179
  }
171
180
  catch (error) {
172
181
  console.warn("[proactive/scheduler] Failed to load existing schedules; skipping registration to avoid duplicates:", error instanceof Error ? error.message : String(error));
173
- return;
182
+ // Transient API failure — caller should retry.
183
+ return false;
174
184
  }
185
+ let failed = false;
175
186
  for (const definition of PROACTIVE_SCHEDULES) {
176
187
  const transport = {
177
188
  type: "webhook",
@@ -218,6 +229,8 @@ export async function registerProactiveSchedules() {
218
229
  }
219
230
  catch (error) {
220
231
  console.error(`[proactive/scheduler] Failed to register ${definition.name}:`, error instanceof Error ? error.message : String(error));
232
+ failed = true;
221
233
  }
222
234
  }
235
+ return !failed;
223
236
  }
package/dist/types.d.ts CHANGED
@@ -18,6 +18,9 @@ export interface SageBindings {
18
18
  SLACK_BOT_USER_ID?: string;
19
19
  SLACK_SIGNING_SECRET?: string;
20
20
  SAGE_NOTIFY_CHANNEL?: string;
21
+ AGENTCRON_API_KEY?: string;
22
+ AGENTCRON_URL?: string;
23
+ SAGE_PUBLIC_URL?: string;
21
24
  DEDUP: KVNamespace;
22
25
  THREADS: KVNamespace;
23
26
  RATE_LIMIT?: {
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoB,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAI/E;;GAEG;AACH,MAAM,WAAW,YAAY;IAE3B,gBAAgB,EAAE,MAAM,CAAC;IACzB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,mBAAmB,EAAE,MAAM,CAAC;IAE5B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,aAAa,C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,CAAC,EAAE,MAAM,CAAC;IAC9B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAE7B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB,KAAK,EAAE,WAAW,CAAC;IACnB,OAAO,EAAE,WAAW,CAAC;IACrB,UAAU,CAAC,EAAE;QAAE,KAAK,EAAE,CAAC,IAAI,EAAE;YAAE,GAAG,EAAE,MAAM,CAAA;SAAE,KAAK,OAAO,CAAC;YAAE,OAAO,EAAE,OAAO,CAAA;SAAE,CAAC,CAAA;KAAE,CAAC;CAClF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentworkforce/sage",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/AgentWorkforce/sage.git"