@aikirun/client 0.7.0 → 0.9.0

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
@@ -16,7 +16,7 @@ npm install @aikirun/client
16
16
  import { client } from "@aikirun/client";
17
17
 
18
18
  const aikiClient = await client({
19
- url: "http://localhost:9090",
19
+ url: "http://localhost:9876",
20
20
  redis: {
21
21
  host: "localhost",
22
22
  port: 6379,
@@ -62,7 +62,7 @@ console.log("Current status:", state.status);
62
62
  - **Workflow Management** - Start workflows with type-safe inputs
63
63
  - **State Polling** - Wait for workflow completion with configurable polling
64
64
  - **Logger** - Built-in logging for debugging
65
- - **Context Factory** - Pass application context through workflow execution
65
+ - **Create Context** - Pass application context through workflow execution
66
66
  - **Redis Integration** - Connect to Redis for distributed state management
67
67
 
68
68
  ## Configuration
@@ -81,18 +81,18 @@ interface ClientParams<AppContext> {
81
81
  retryDelayOnFailoverMs?: number;
82
82
  connectTimeoutMs?: number;
83
83
  };
84
- contextFactory?: (run: WorkflowRun) => AppContext | Promise<AppContext>;
84
+ createContext?: (run: WorkflowRun) => AppContext | Promise<AppContext>;
85
85
  logger?: Logger;
86
86
  }
87
87
  ```
88
88
 
89
- ### Context Factory Example
89
+ ### Create Context Example
90
90
 
91
91
  ```typescript
92
92
  const aikiClient = await client({
93
- url: "http://localhost:9090",
93
+ url: "http://localhost:9876",
94
94
  redis: { host: "localhost", port: 6379 },
95
- contextFactory: (run) => ({
95
+ createContext: (run) => ({
96
96
  traceId: generateTraceId(),
97
97
  workflowRunId: run.id,
98
98
  userId: extractUserIdFromRun(run),
package/dist/index.d.ts CHANGED
@@ -9,21 +9,21 @@ export { AdaptivePollingSubscriberStrategy, ApiClient, Client, ClientParams, Log
9
9
  *
10
10
  * @template AppContext - Type of application context passed to workflows (default: null)
11
11
  * @param params - Client configuration parameters
12
- * @param params.url - HTTP URL of the Aiki server (e.g., "http://localhost:9090")
12
+ * @param params.url - HTTP URL of the Aiki server (e.g., "http://localhost:9876")
13
13
  * @param params.redis - Redis connection configuration
14
14
  * @param params.redis.host - Redis server hostname
15
15
  * @param params.redis.port - Redis server port
16
16
  * @param params.redis.password - Optional Redis password
17
- * @param params.contextFactory - Optional function to create context for each workflow run
17
+ * @param params.createContext - Optional function to create context for each workflow run
18
18
  * @param params.logger - Optional custom logger (defaults to ConsoleLogger)
19
19
  * @returns Promise resolving to a configured Client instance
20
20
  *
21
21
  * @example
22
22
  * ```typescript
23
23
  * const aikiClient = await client({
24
- * url: "http://localhost:9090",
24
+ * url: "http://localhost:9876",
25
25
  * redis: { host: "localhost", port: 6379 },
26
- * contextFactory: (run) => ({
26
+ * createContext: (run) => ({
27
27
  * traceId: generateTraceId(),
28
28
  * userId: extractUserId(run),
29
29
  * }),
package/dist/index.js CHANGED
@@ -69,6 +69,14 @@ function distributeRoundRobin(totalSize, itemCount) {
69
69
  return distribution;
70
70
  }
71
71
 
72
+ // ../../lib/path/index.ts
73
+ function getWorkflowStreamName(name, versionId, shard) {
74
+ return shard ? `workflow/${name}/${versionId}/${shard}` : `workflow/${name}/${versionId}`;
75
+ }
76
+ function getWorkerConsumerGroupName(workflowName, workflowVersionId, shard) {
77
+ return shard ? `worker/${workflowName}/${workflowVersionId}/${shard}` : `worker/${workflowName}/${workflowVersionId}`;
78
+ }
79
+
72
80
  // ../../lib/retry/strategy.ts
73
81
  function getRetryParams(attempts, strategy) {
74
82
  const strategyType = strategy.type;
@@ -208,10 +216,6 @@ function createRedisStreamsStrategy(client2, strategy, workflows, workerShards)
208
216
  "aiki.messageId": meta.messageId
209
217
  });
210
218
  } else {
211
- logger.debug("Message acknowledged", {
212
- "aiki.workflowRunId": workflowRunId,
213
- "aiki.messageId": meta.messageId
214
- });
215
219
  }
216
220
  } catch (error) {
217
221
  logger.error("Failed to acknowledge message", {
@@ -252,20 +256,20 @@ function createRedisStreamsStrategy(client2, strategy, workflows, workerShards)
252
256
  }
253
257
  };
254
258
  }
255
- function getRedisStreamConsumerGroupMap(workflows, shardKeys) {
256
- if (!shardKeys || !isNonEmptyArray(shardKeys)) {
259
+ function getRedisStreamConsumerGroupMap(workflows, shards) {
260
+ if (!shards || !isNonEmptyArray(shards)) {
257
261
  return new Map(
258
262
  workflows.map((workflow) => [
259
- `workflow/${workflow.id}/${workflow.versionId}`,
260
- `worker/${workflow.id}/${workflow.versionId}`
263
+ getWorkflowStreamName(workflow.name, workflow.versionId),
264
+ getWorkerConsumerGroupName(workflow.name, workflow.versionId)
261
265
  ])
262
266
  );
263
267
  }
264
268
  return new Map(
265
269
  workflows.flatMap(
266
- (workflow) => shardKeys.map((shardKey) => [
267
- `workflow/${workflow.id}/${workflow.versionId}/${shardKey}`,
268
- `worker/${workflow.id}/${workflow.versionId}/${shardKey}`
270
+ (workflow) => shards.map((shard) => [
271
+ getWorkflowStreamName(workflow.name, workflow.versionId, shard),
272
+ getWorkerConsumerGroupName(workflow.name, workflow.versionId, shard)
269
273
  ])
270
274
  )
271
275
  );
@@ -332,7 +336,6 @@ async function fetchRedisStreamMessages(redis, logger, streams, streamConsumerGr
332
336
  async function processRedisStreamMessages(redis, logger, streamConsumerGroupMap, streamsEntries) {
333
337
  const workflowRuns = [];
334
338
  for (const streamEntriesRaw of streamsEntries) {
335
- logger.debug("Raw stream entries", { entries: streamEntriesRaw });
336
339
  const streamEntriesResult = RedisStreamEntriesSchema.safeParse(streamEntriesRaw);
337
340
  if (!streamEntriesResult.success) {
338
341
  logger.error("Invalid stream entries format", {
@@ -498,7 +501,7 @@ function resolveSubscriberStrategy(client2, strategy, workflows, workerShards) {
498
501
  // return createPollingStrategy(client, strategy);
499
502
  // case "adaptive_polling":
500
503
  // return createAdaptivePollingStrategy(client, strategy);
501
- case "redis_streams":
504
+ case "redis":
502
505
  return createRedisStreamsStrategy(client2, strategy, workflows, workerShards);
503
506
  default:
504
507
  return strategy.type;
@@ -526,7 +529,7 @@ var ClientImpl = class {
526
529
  getConnection: () => this.getRedisConnection(),
527
530
  closeConnection: () => this.closeRedisConnection()
528
531
  },
529
- contextFactory: this.params.contextFactory
532
+ createContext: this.params.createContext
530
533
  };
531
534
  }
532
535
  api;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aikirun/client",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "description": "Client SDK for Aiki - connect to the server, start workflows, and manage execution",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -18,7 +18,7 @@
18
18
  "build": "tsup"
19
19
  },
20
20
  "dependencies": {
21
- "@aikirun/types": "0.7.0",
21
+ "@aikirun/types": "0.9.0",
22
22
  "@orpc/client": "^1.9.3",
23
23
  "ioredis": "^5.4.1",
24
24
  "zod": "^4.1.12"