astrocode-workflow 0.1.52 → 0.1.53

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/dist/ui/inject.js CHANGED
@@ -1,16 +1,17 @@
1
1
  let isInjecting = false;
2
- let queuedInjection = null;
3
- export async function injectChatPrompt(opts) {
4
- const { ctx, sessionId, text, agent = "Astro" } = opts;
5
- // Prefix to clearly indicate source as Astro agent
6
- const prefixedText = `[${agent}]\n\n${text}`;
7
- if (isInjecting) {
8
- // Replace any existing queued injection (keep only latest)
9
- queuedInjection = opts;
2
+ const injectionQueue = [];
3
+ async function processQueue() {
4
+ if (isInjecting || injectionQueue.length === 0)
10
5
  return;
11
- }
12
6
  isInjecting = true;
7
+ const opts = injectionQueue.shift();
8
+ if (!opts) {
9
+ isInjecting = false;
10
+ return;
11
+ }
13
12
  try {
13
+ const { ctx, sessionId, text, agent = "Astro" } = opts;
14
+ const prefixedText = `[${agent}]\n\n${text}`;
14
15
  // Basic validation
15
16
  if (!sessionId) {
16
17
  console.warn("[Astrocode] Skipping injection: No sessionId provided");
@@ -34,12 +35,13 @@ export async function injectChatPrompt(opts) {
34
35
  }
35
36
  finally {
36
37
  isInjecting = false;
37
- // Process queued injection if any
38
- if (queuedInjection) {
39
- const next = queuedInjection;
40
- queuedInjection = null;
41
- // Schedule next injection asynchronously to prevent recursion
42
- setImmediate(() => injectChatPrompt(next));
38
+ // Process next item immediately
39
+ if (injectionQueue.length > 0) {
40
+ setImmediate(processQueue);
43
41
  }
44
42
  }
45
43
  }
44
+ export async function injectChatPrompt(opts) {
45
+ injectionQueue.push(opts);
46
+ processQueue();
47
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astrocode-workflow",
3
- "version": "0.1.52",
3
+ "version": "0.1.53",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -18,7 +18,7 @@
18
18
  "dependencies": {
19
19
  "@opencode-ai/plugin": "^1.1.19",
20
20
  "@opencode-ai/sdk": "^1.1.19",
21
- "astrocode-workflow": "^0.1.18",
21
+ "astrocode-workflow": "^0.1.51",
22
22
  "jsonc-parser": "^3.2.0",
23
23
  "zod": "4.1.8"
24
24
  },
package/src/ui/inject.ts CHANGED
@@ -1,26 +1,26 @@
1
1
  let isInjecting = false;
2
- let queuedInjection: { ctx: any; sessionId: string; text: string; agent?: string } | null = null;
3
-
4
- export async function injectChatPrompt(opts: {
2
+ const injectionQueue: Array<{
5
3
  ctx: any;
6
4
  sessionId: string;
7
5
  text: string;
8
6
  agent?: string;
9
- }) {
10
- const { ctx, sessionId, text, agent = "Astro" } = opts;
7
+ }> = [];
11
8
 
12
- // Prefix to clearly indicate source as Astro agent
13
- const prefixedText = `[${agent}]\n\n${text}`;
9
+ async function processQueue() {
10
+ if (isInjecting || injectionQueue.length === 0) return;
11
+
12
+ isInjecting = true;
13
+ const opts = injectionQueue.shift();
14
14
 
15
- if (isInjecting) {
16
- // Replace any existing queued injection (keep only latest)
17
- queuedInjection = opts;
15
+ if (!opts) {
16
+ isInjecting = false;
18
17
  return;
19
18
  }
20
19
 
21
- isInjecting = true;
22
-
23
20
  try {
21
+ const { ctx, sessionId, text, agent = "Astro" } = opts;
22
+ const prefixedText = `[${agent}]\n\n${text}`;
23
+
24
24
  // Basic validation
25
25
  if (!sessionId) {
26
26
  console.warn("[Astrocode] Skipping injection: No sessionId provided");
@@ -44,12 +44,19 @@ export async function injectChatPrompt(opts: {
44
44
  console.warn(`[Astrocode] Injection failed: ${error}`);
45
45
  } finally {
46
46
  isInjecting = false;
47
- // Process queued injection if any
48
- if (queuedInjection) {
49
- const next = queuedInjection;
50
- queuedInjection = null;
51
- // Schedule next injection asynchronously to prevent recursion
52
- setImmediate(() => injectChatPrompt(next));
47
+ // Process next item immediately
48
+ if (injectionQueue.length > 0) {
49
+ setImmediate(processQueue);
53
50
  }
54
51
  }
55
52
  }
53
+
54
+ export async function injectChatPrompt(opts: {
55
+ ctx: any;
56
+ sessionId: string;
57
+ text: string;
58
+ agent?: string;
59
+ }) {
60
+ injectionQueue.push(opts);
61
+ processQueue();
62
+ }