@aikirun/client 0.8.0 → 0.9.1
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 +16 -82
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @aikirun/client
|
|
2
2
|
|
|
3
|
-
Client SDK for Aiki durable execution platform
|
|
3
|
+
Client SDK for Aiki durable execution platform.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -10,110 +10,44 @@ npm install @aikirun/client
|
|
|
10
10
|
|
|
11
11
|
## Quick Start
|
|
12
12
|
|
|
13
|
-
### Initialize the Client
|
|
14
|
-
|
|
15
13
|
```typescript
|
|
16
14
|
import { client } from "@aikirun/client";
|
|
15
|
+
import { orderWorkflowV1 } from "./workflows.ts";
|
|
17
16
|
|
|
18
17
|
const aikiClient = await client({
|
|
19
18
|
url: "http://localhost:9876",
|
|
20
|
-
redis: {
|
|
21
|
-
host: "localhost",
|
|
22
|
-
port: 6379,
|
|
23
|
-
},
|
|
19
|
+
redis: { host: "localhost", port: 6379 },
|
|
24
20
|
});
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
### Start a Workflow
|
|
28
21
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const stateHandle = await onboardingWorkflowV1.start(aikiClient, {
|
|
33
|
-
email: "user@example.com",
|
|
22
|
+
// Start a workflow
|
|
23
|
+
const handle = await orderWorkflowV1.start(aikiClient, {
|
|
24
|
+
orderId: "order-123",
|
|
34
25
|
});
|
|
35
|
-
```
|
|
36
26
|
|
|
37
|
-
|
|
27
|
+
// Wait for completion
|
|
28
|
+
const result = await handle.waitForStatus("completed");
|
|
38
29
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
{ type: "status", status: "completed" },
|
|
42
|
-
{ maxDurationMs: 60_000, pollIntervalMs: 5_000 },
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
if (result.success) {
|
|
46
|
-
console.log("Workflow completed!");
|
|
47
|
-
} else {
|
|
48
|
-
console.log("Workflow did not complete:", result.cause);
|
|
49
|
-
}
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
### Get Workflow State
|
|
53
|
-
|
|
54
|
-
```typescript
|
|
55
|
-
const state = await stateHandle.getState();
|
|
56
|
-
console.log("Current status:", state.status);
|
|
30
|
+
// Close when done
|
|
31
|
+
await aikiClient.close();
|
|
57
32
|
```
|
|
58
33
|
|
|
59
34
|
## Features
|
|
60
35
|
|
|
61
|
-
- **
|
|
36
|
+
- **Server Connection** - Connect to the Aiki server via HTTP
|
|
62
37
|
- **Workflow Management** - Start workflows with type-safe inputs
|
|
63
|
-
- **
|
|
64
|
-
- **
|
|
65
|
-
- **
|
|
66
|
-
- **Redis Integration** - Connect to Redis for distributed state management
|
|
38
|
+
- **Redis Integration** - Distributed state and message streaming
|
|
39
|
+
- **Context Injection** - Pass application context to workflows
|
|
40
|
+
- **Custom Logging** - Plug in your own logger
|
|
67
41
|
|
|
68
|
-
##
|
|
42
|
+
## Documentation
|
|
69
43
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
```typescript
|
|
73
|
-
interface ClientParams<AppContext> {
|
|
74
|
-
url: string; // Server URL
|
|
75
|
-
redis: {
|
|
76
|
-
host: string;
|
|
77
|
-
port: number;
|
|
78
|
-
password?: string;
|
|
79
|
-
db?: number;
|
|
80
|
-
maxRetriesPerRequest?: number;
|
|
81
|
-
retryDelayOnFailoverMs?: number;
|
|
82
|
-
connectTimeoutMs?: number;
|
|
83
|
-
};
|
|
84
|
-
contextFactory?: (run: WorkflowRun) => AppContext | Promise<AppContext>;
|
|
85
|
-
logger?: Logger;
|
|
86
|
-
}
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
### Context Factory Example
|
|
90
|
-
|
|
91
|
-
```typescript
|
|
92
|
-
const aikiClient = await client({
|
|
93
|
-
url: "http://localhost:9876",
|
|
94
|
-
redis: { host: "localhost", port: 6379 },
|
|
95
|
-
contextFactory: (run) => ({
|
|
96
|
-
traceId: generateTraceId(),
|
|
97
|
-
workflowRunId: run.id,
|
|
98
|
-
userId: extractUserIdFromRun(run),
|
|
99
|
-
}),
|
|
100
|
-
});
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
## API Reference
|
|
104
|
-
|
|
105
|
-
See the [Aiki documentation](https://github.com/aikirun/aiki) for comprehensive API reference.
|
|
44
|
+
For comprehensive documentation including configuration options and context injection, see the [Client Guide](https://aiki.run/docs/core-concepts/client).
|
|
106
45
|
|
|
107
46
|
## Related Packages
|
|
108
47
|
|
|
109
48
|
- [@aikirun/workflow](https://www.npmjs.com/package/@aikirun/workflow) - Define workflows
|
|
110
49
|
- [@aikirun/task](https://www.npmjs.com/package/@aikirun/task) - Define tasks
|
|
111
50
|
- [@aikirun/worker](https://www.npmjs.com/package/@aikirun/worker) - Execute workflows
|
|
112
|
-
- [@aikirun/types](https://www.npmjs.com/package/@aikirun/types) - Type definitions
|
|
113
|
-
|
|
114
|
-
## Changelog
|
|
115
|
-
|
|
116
|
-
See the [CHANGELOG](https://github.com/aikirun/aiki/blob/main/CHANGELOG.md) for version history.
|
|
117
51
|
|
|
118
52
|
## License
|
|
119
53
|
|
package/dist/index.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export { AdaptivePollingSubscriberStrategy, ApiClient, Client, ClientParams, Log
|
|
|
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.
|
|
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
|
*
|
|
@@ -23,7 +23,7 @@ export { AdaptivePollingSubscriberStrategy, ApiClient, Client, ClientParams, Log
|
|
|
23
23
|
* const aikiClient = await client({
|
|
24
24
|
* url: "http://localhost:9876",
|
|
25
25
|
* redis: { host: "localhost", port: 6379 },
|
|
26
|
-
*
|
|
26
|
+
* createContext: (run) => ({
|
|
27
27
|
* traceId: generateTraceId(),
|
|
28
28
|
* userId: extractUserId(run),
|
|
29
29
|
* }),
|
package/dist/index.js
CHANGED
|
@@ -501,7 +501,7 @@ function resolveSubscriberStrategy(client2, strategy, workflows, workerShards) {
|
|
|
501
501
|
// return createPollingStrategy(client, strategy);
|
|
502
502
|
// case "adaptive_polling":
|
|
503
503
|
// return createAdaptivePollingStrategy(client, strategy);
|
|
504
|
-
case "
|
|
504
|
+
case "redis":
|
|
505
505
|
return createRedisStreamsStrategy(client2, strategy, workflows, workerShards);
|
|
506
506
|
default:
|
|
507
507
|
return strategy.type;
|
|
@@ -529,7 +529,7 @@ var ClientImpl = class {
|
|
|
529
529
|
getConnection: () => this.getRedisConnection(),
|
|
530
530
|
closeConnection: () => this.closeRedisConnection()
|
|
531
531
|
},
|
|
532
|
-
|
|
532
|
+
createContext: this.params.createContext
|
|
533
533
|
};
|
|
534
534
|
}
|
|
535
535
|
api;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aikirun/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
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.
|
|
21
|
+
"@aikirun/types": "0.9.1",
|
|
22
22
|
"@orpc/client": "^1.9.3",
|
|
23
23
|
"ioredis": "^5.4.1",
|
|
24
24
|
"zod": "^4.1.12"
|