@statelyai/agent 0.1.2 → 0.1.3
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/.changeset/shaggy-buttons-itch.md +5 -0
- package/dist/index.js +7 -9
- package/dist/index.mjs +7 -9
- package/package.json +2 -1
- package/src/agent.ts +3 -3
- package/src/text.ts +4 -5
package/dist/index.js
CHANGED
|
@@ -142,12 +142,9 @@ async function simplePlanner(agent, input) {
|
|
|
142
142
|
};
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
// src/agent.ts
|
|
146
|
-
var import_crypto2 = require("crypto");
|
|
147
|
-
|
|
148
145
|
// src/text.ts
|
|
149
|
-
var import_crypto = require("crypto");
|
|
150
146
|
var import_xstate = require("xstate");
|
|
147
|
+
var import_nanoid = require("nanoid");
|
|
151
148
|
async function getMessages(agent, prompt, options) {
|
|
152
149
|
let messages = [];
|
|
153
150
|
if (options.messages === true) {
|
|
@@ -169,7 +166,7 @@ async function agentGenerateText(agent, options) {
|
|
|
169
166
|
...options
|
|
170
167
|
};
|
|
171
168
|
const template = resolvedOptions.template ?? defaultTextTemplate;
|
|
172
|
-
const id = (0,
|
|
169
|
+
const id = (0, import_nanoid.nanoid)();
|
|
173
170
|
const goal = typeof resolvedOptions.prompt === "string" ? resolvedOptions.prompt : await resolvedOptions.prompt(agent);
|
|
174
171
|
const promptWithContext = template({
|
|
175
172
|
goal,
|
|
@@ -203,7 +200,7 @@ async function agentStreamText(agent, options) {
|
|
|
203
200
|
...options
|
|
204
201
|
};
|
|
205
202
|
const template = resolvedOptions.template ?? defaultTextTemplate;
|
|
206
|
-
const id = (0,
|
|
203
|
+
const id = (0, import_nanoid.nanoid)();
|
|
207
204
|
const goal = typeof resolvedOptions.prompt === "string" ? resolvedOptions.prompt : await resolvedOptions.prompt(agent);
|
|
208
205
|
const promptWithContext = template({
|
|
209
206
|
goal,
|
|
@@ -235,7 +232,7 @@ async function agentStreamText(agent, options) {
|
|
|
235
232
|
rawResponse: res.rawResponse
|
|
236
233
|
},
|
|
237
234
|
content: res.text,
|
|
238
|
-
id: (0,
|
|
235
|
+
id: (0, import_nanoid.nanoid)(),
|
|
239
236
|
timestamp: Date.now(),
|
|
240
237
|
responseId: id
|
|
241
238
|
});
|
|
@@ -355,6 +352,7 @@ var vercelAdapter = {
|
|
|
355
352
|
};
|
|
356
353
|
|
|
357
354
|
// src/agent.ts
|
|
355
|
+
var import_nanoid2 = require("nanoid");
|
|
358
356
|
var agentLogic = (0, import_xstate3.fromTransition)(
|
|
359
357
|
(state, event, { emit }) => {
|
|
360
358
|
switch (event.type) {
|
|
@@ -439,7 +437,7 @@ function createAgent({
|
|
|
439
437
|
agent.addMessage = (messageInput) => {
|
|
440
438
|
const message = {
|
|
441
439
|
...messageInput,
|
|
442
|
-
id: messageInput.id ?? (0,
|
|
440
|
+
id: messageInput.id ?? (0, import_nanoid2.nanoid)(),
|
|
443
441
|
timestamp: messageInput.timestamp ?? Date.now(),
|
|
444
442
|
sessionId: agent.sessionId
|
|
445
443
|
};
|
|
@@ -466,7 +464,7 @@ function createAgent({
|
|
|
466
464
|
agent.addObservation = (observationInput) => {
|
|
467
465
|
const observation = {
|
|
468
466
|
...observationInput,
|
|
469
|
-
id: observationInput.id ?? (0,
|
|
467
|
+
id: observationInput.id ?? (0, import_nanoid2.nanoid)(),
|
|
470
468
|
sessionId: agent.sessionId,
|
|
471
469
|
timestamp: observationInput.timestamp ?? Date.now()
|
|
472
470
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -115,16 +115,13 @@ async function simplePlanner(agent, input) {
|
|
|
115
115
|
};
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
// src/agent.ts
|
|
119
|
-
import { randomUUID as randomUUID2 } from "crypto";
|
|
120
|
-
|
|
121
118
|
// src/text.ts
|
|
122
|
-
import { randomUUID } from "crypto";
|
|
123
119
|
import {
|
|
124
120
|
fromObservable,
|
|
125
121
|
fromPromise,
|
|
126
122
|
toObserver
|
|
127
123
|
} from "xstate";
|
|
124
|
+
import { nanoid } from "nanoid";
|
|
128
125
|
async function getMessages(agent, prompt, options) {
|
|
129
126
|
let messages = [];
|
|
130
127
|
if (options.messages === true) {
|
|
@@ -146,7 +143,7 @@ async function agentGenerateText(agent, options) {
|
|
|
146
143
|
...options
|
|
147
144
|
};
|
|
148
145
|
const template = resolvedOptions.template ?? defaultTextTemplate;
|
|
149
|
-
const id =
|
|
146
|
+
const id = nanoid();
|
|
150
147
|
const goal = typeof resolvedOptions.prompt === "string" ? resolvedOptions.prompt : await resolvedOptions.prompt(agent);
|
|
151
148
|
const promptWithContext = template({
|
|
152
149
|
goal,
|
|
@@ -180,7 +177,7 @@ async function agentStreamText(agent, options) {
|
|
|
180
177
|
...options
|
|
181
178
|
};
|
|
182
179
|
const template = resolvedOptions.template ?? defaultTextTemplate;
|
|
183
|
-
const id =
|
|
180
|
+
const id = nanoid();
|
|
184
181
|
const goal = typeof resolvedOptions.prompt === "string" ? resolvedOptions.prompt : await resolvedOptions.prompt(agent);
|
|
185
182
|
const promptWithContext = template({
|
|
186
183
|
goal,
|
|
@@ -212,7 +209,7 @@ async function agentStreamText(agent, options) {
|
|
|
212
209
|
rawResponse: res.rawResponse
|
|
213
210
|
},
|
|
214
211
|
content: res.text,
|
|
215
|
-
id:
|
|
212
|
+
id: nanoid(),
|
|
216
213
|
timestamp: Date.now(),
|
|
217
214
|
responseId: id
|
|
218
215
|
});
|
|
@@ -332,6 +329,7 @@ var vercelAdapter = {
|
|
|
332
329
|
};
|
|
333
330
|
|
|
334
331
|
// src/agent.ts
|
|
332
|
+
import { nanoid as nanoid2 } from "nanoid";
|
|
335
333
|
var agentLogic = fromTransition(
|
|
336
334
|
(state, event, { emit }) => {
|
|
337
335
|
switch (event.type) {
|
|
@@ -416,7 +414,7 @@ function createAgent({
|
|
|
416
414
|
agent.addMessage = (messageInput) => {
|
|
417
415
|
const message = {
|
|
418
416
|
...messageInput,
|
|
419
|
-
id: messageInput.id ??
|
|
417
|
+
id: messageInput.id ?? nanoid2(),
|
|
420
418
|
timestamp: messageInput.timestamp ?? Date.now(),
|
|
421
419
|
sessionId: agent.sessionId
|
|
422
420
|
};
|
|
@@ -443,7 +441,7 @@ function createAgent({
|
|
|
443
441
|
agent.addObservation = (observationInput) => {
|
|
444
442
|
const observation = {
|
|
445
443
|
...observationInput,
|
|
446
|
-
id: observationInput.id ??
|
|
444
|
+
id: observationInput.id ?? nanoid2(),
|
|
447
445
|
sessionId: agent.sessionId,
|
|
448
446
|
timestamp: observationInput.timestamp ?? Date.now()
|
|
449
447
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statelyai/agent",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"@ai-sdk/openai": "^0.0.13",
|
|
42
42
|
"@xstate/graph": "^2.0.0",
|
|
43
43
|
"ai": "^3.1.32",
|
|
44
|
+
"nanoid": "^5.0.7",
|
|
44
45
|
"xstate": "^5.13.2"
|
|
45
46
|
},
|
|
46
47
|
"packageManager": "pnpm@8.11.0"
|
package/src/agent.ts
CHANGED
|
@@ -22,10 +22,10 @@ import {
|
|
|
22
22
|
AgentMemoryContext,
|
|
23
23
|
} from './types';
|
|
24
24
|
import { simplePlanner } from './planners/simplePlanner';
|
|
25
|
-
import { randomUUID } from 'crypto';
|
|
26
25
|
import { agentGenerateText, agentStreamText } from './text';
|
|
27
26
|
import { agentDecide } from './decision';
|
|
28
27
|
import { vercelAdapter } from './adapters/vercel';
|
|
28
|
+
import { nanoid } from 'nanoid';
|
|
29
29
|
|
|
30
30
|
export const agentLogic: AgentLogic<AnyEventObject> = fromTransition(
|
|
31
31
|
(state, event, { emit }) => {
|
|
@@ -144,7 +144,7 @@ export function createAgent<
|
|
|
144
144
|
agent.addMessage = (messageInput) => {
|
|
145
145
|
const message = {
|
|
146
146
|
...messageInput,
|
|
147
|
-
id: messageInput.id ??
|
|
147
|
+
id: messageInput.id ?? nanoid(),
|
|
148
148
|
timestamp: messageInput.timestamp ?? Date.now(),
|
|
149
149
|
sessionId: agent.sessionId,
|
|
150
150
|
};
|
|
@@ -176,7 +176,7 @@ export function createAgent<
|
|
|
176
176
|
agent.addObservation = (observationInput) => {
|
|
177
177
|
const observation = {
|
|
178
178
|
...observationInput,
|
|
179
|
-
id: observationInput.id ??
|
|
179
|
+
id: observationInput.id ?? nanoid(),
|
|
180
180
|
sessionId: agent.sessionId,
|
|
181
181
|
timestamp: observationInput.timestamp ?? Date.now(),
|
|
182
182
|
};
|
package/src/text.ts
CHANGED
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
AgentGenerateTextOptions,
|
|
10
10
|
AgentStreamTextOptions,
|
|
11
11
|
} from './types';
|
|
12
|
-
import { randomUUID } from 'crypto';
|
|
13
12
|
import { defaultTextTemplate } from './templates/defaultText';
|
|
14
13
|
import {
|
|
15
14
|
AnyMachineSnapshot,
|
|
@@ -20,7 +19,7 @@ import {
|
|
|
20
19
|
fromPromise,
|
|
21
20
|
toObserver,
|
|
22
21
|
} from 'xstate';
|
|
23
|
-
import {
|
|
22
|
+
import { nanoid } from 'nanoid';
|
|
24
23
|
|
|
25
24
|
/**
|
|
26
25
|
* Gets an array of messages from the given prompt, based on the agent and options.
|
|
@@ -62,7 +61,7 @@ export async function agentGenerateText<T extends Agent<any>>(
|
|
|
62
61
|
};
|
|
63
62
|
const template = resolvedOptions.template ?? defaultTextTemplate;
|
|
64
63
|
// TODO: check if messages was provided instead
|
|
65
|
-
const id =
|
|
64
|
+
const id = nanoid();
|
|
66
65
|
const goal =
|
|
67
66
|
typeof resolvedOptions.prompt === 'string'
|
|
68
67
|
? resolvedOptions.prompt
|
|
@@ -110,7 +109,7 @@ export async function agentStreamText(
|
|
|
110
109
|
};
|
|
111
110
|
const template = resolvedOptions.template ?? defaultTextTemplate;
|
|
112
111
|
|
|
113
|
-
const id =
|
|
112
|
+
const id = nanoid();
|
|
114
113
|
const goal =
|
|
115
114
|
typeof resolvedOptions.prompt === 'string'
|
|
116
115
|
? resolvedOptions.prompt
|
|
@@ -149,7 +148,7 @@ export async function agentStreamText(
|
|
|
149
148
|
rawResponse: res.rawResponse,
|
|
150
149
|
},
|
|
151
150
|
content: res.text,
|
|
152
|
-
id:
|
|
151
|
+
id: nanoid(),
|
|
153
152
|
timestamp: Date.now(),
|
|
154
153
|
responseId: id,
|
|
155
154
|
});
|