@statelyai/agent 0.0.7 → 0.0.8
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/CHANGELOG.md +29 -0
- package/dist/index.d.ts +13 -44
- package/dist/index.js +4761 -25
- package/examples/joke.ts +55 -62
- package/examples/numberGuesser.ts +10 -37
- package/examples/ticTacToe.ts +37 -72
- package/examples/weather.ts +48 -27
- package/examples/wordGuesser.ts +14 -26
- package/package.json +5 -3
- package/src/adapters/openai.ts +8 -3
- package/src/agent.ts +1 -1
- package/src/index.ts +1 -1
- package/src/schemas.ts +18 -32
- package/src/utils.ts +23 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# @statelyai/agent
|
|
2
2
|
|
|
3
|
+
## 0.0.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#22](https://github.com/statelyai/agent/pull/22) [`8a2c34b`](https://github.com/statelyai/agent/commit/8a2c34b8a99161bf47c72df8eed3f5d3b6a19f5f) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The `createSchemas(…)` function has been removed. The `defineEvents(…)` function should be used instead, as it is a simpler way of defining events and event schemas using Zod:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { defineEvents } from "@statelyai/agent";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
import { setup } from "xstate";
|
|
13
|
+
|
|
14
|
+
const events = defineEvents({
|
|
15
|
+
inc: z.object({
|
|
16
|
+
by: z.number().describe("Increment amount"),
|
|
17
|
+
}),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const machine = setup({
|
|
21
|
+
types: {
|
|
22
|
+
events: events.types,
|
|
23
|
+
},
|
|
24
|
+
schema: {
|
|
25
|
+
events: events.schemas,
|
|
26
|
+
},
|
|
27
|
+
}).createMachine({
|
|
28
|
+
// ...
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
3
32
|
## 0.0.7
|
|
4
33
|
|
|
5
34
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,52 +1,21 @@
|
|
|
1
1
|
import * as xstate from 'xstate';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { FromSchema } from 'json-schema-to-ts';
|
|
2
|
+
import { Values, AnyStateMachine, createActor, PromiseActorLogic, AnyEventObject, ObservableActorLogic } from 'xstate';
|
|
3
|
+
import { TypeOf, SomeZodObject } from 'zod';
|
|
5
4
|
import OpenAI from 'openai';
|
|
6
5
|
import { ChatCompletionCreateParamsBase } from 'openai/resources/chat/completions';
|
|
7
6
|
import { ChatCompletionCreateParamsNonStreaming, ChatCompletionCreateParamsStreaming } from 'openai/resources';
|
|
8
7
|
|
|
9
|
-
type
|
|
10
|
-
[
|
|
11
|
-
description?: string;
|
|
12
|
-
properties?: {
|
|
13
|
-
[key: string]: JSONSchema7;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
type ContextSchema = JSONSchema7 & {
|
|
18
|
-
type: 'object';
|
|
8
|
+
type ZodEventTypes = {
|
|
9
|
+
[eventType: string]: SomeZodObject;
|
|
19
10
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
type:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
required: Array<(keyof Prop<T[K], 'properties'> & string) | 'type'>;
|
|
29
|
-
additionalProperties: false;
|
|
30
|
-
};
|
|
31
|
-
} & {};
|
|
32
|
-
|
|
33
|
-
declare function createSchemas<const TContextSchema extends ContextSchema, const TEventSchemas extends EventSchemas>({ context, events, }: {
|
|
34
|
-
/**
|
|
35
|
-
* The JSON schema for the context object.
|
|
36
|
-
*
|
|
37
|
-
* Must be of `{ type: 'object' }`.
|
|
38
|
-
*/
|
|
39
|
-
context?: TContextSchema;
|
|
40
|
-
/**
|
|
41
|
-
* An object mapping event types to each event object's JSON Schema.
|
|
42
|
-
*/
|
|
43
|
-
events: TEventSchemas;
|
|
44
|
-
}): {
|
|
45
|
-
context: TContextSchema | undefined;
|
|
46
|
-
events: ConvertToJSONSchemas<TEventSchemas>;
|
|
47
|
-
types: {
|
|
48
|
-
context: FromSchema<TContextSchema>;
|
|
49
|
-
events: FromSchema<Values<ConvertToJSONSchemas<TEventSchemas>>>;
|
|
11
|
+
declare function defineEvents<const TEventSchemas extends ZodEventTypes>(events: TEventSchemas): {
|
|
12
|
+
types: Values<{
|
|
13
|
+
[K in keyof TEventSchemas]: {
|
|
14
|
+
type: K;
|
|
15
|
+
} & TypeOf<TEventSchemas[K]>;
|
|
16
|
+
}>;
|
|
17
|
+
schemas: {
|
|
18
|
+
[K in keyof TEventSchemas]: unknown;
|
|
50
19
|
};
|
|
51
20
|
};
|
|
52
21
|
|
|
@@ -90,4 +59,4 @@ declare function createOpenAIAdapter<T extends {
|
|
|
90
59
|
model: ChatCompletionCreateParamsBase['model'];
|
|
91
60
|
}>(openai: OpenAI, settings: T): StatelyAgentAdapter;
|
|
92
61
|
|
|
93
|
-
export { createAgent, createOpenAIAdapter,
|
|
62
|
+
export { createAgent, createOpenAIAdapter, defineEvents };
|