@agentuity/core 1.0.37 → 1.0.38

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.
Files changed (49) hide show
  1. package/dist/services/keyvalue/service.d.ts +2 -0
  2. package/dist/services/keyvalue/service.d.ts.map +1 -1
  3. package/dist/services/keyvalue/service.js +4 -0
  4. package/dist/services/keyvalue/service.js.map +1 -1
  5. package/dist/services/sandbox/client.d.ts +56 -5
  6. package/dist/services/sandbox/client.d.ts.map +1 -1
  7. package/dist/services/sandbox/client.js +120 -51
  8. package/dist/services/sandbox/client.js.map +1 -1
  9. package/dist/services/sandbox/pause.js +1 -1
  10. package/dist/services/sandbox/pause.js.map +1 -1
  11. package/dist/services/sandbox/types.d.ts +30 -0
  12. package/dist/services/sandbox/types.d.ts.map +1 -1
  13. package/dist/services/sandbox/types.js +28 -0
  14. package/dist/services/sandbox/types.js.map +1 -1
  15. package/dist/services/stream/delete.d.ts +27 -0
  16. package/dist/services/stream/delete.d.ts.map +1 -0
  17. package/dist/services/stream/delete.js +58 -0
  18. package/dist/services/stream/delete.js.map +1 -0
  19. package/dist/services/stream/index.d.ts +3 -0
  20. package/dist/services/stream/index.d.ts.map +1 -1
  21. package/dist/services/stream/index.js +3 -0
  22. package/dist/services/stream/index.js.map +1 -1
  23. package/dist/services/stream/namespaces.d.ts +75 -0
  24. package/dist/services/stream/namespaces.d.ts.map +1 -0
  25. package/dist/services/stream/namespaces.js +99 -0
  26. package/dist/services/stream/namespaces.js.map +1 -0
  27. package/dist/services/stream/search.d.ts +34 -0
  28. package/dist/services/stream/search.d.ts.map +1 -0
  29. package/dist/services/stream/search.js +49 -0
  30. package/dist/services/stream/search.js.map +1 -0
  31. package/dist/services/task/service.d.ts +152 -18
  32. package/dist/services/task/service.d.ts.map +1 -1
  33. package/dist/services/task/service.js +251 -10
  34. package/dist/services/task/service.js.map +1 -1
  35. package/dist/services/vector/service.d.ts +3 -0
  36. package/dist/services/vector/service.d.ts.map +1 -1
  37. package/dist/services/vector/service.js +7 -0
  38. package/dist/services/vector/service.js.map +1 -1
  39. package/package.json +2 -2
  40. package/src/services/keyvalue/service.ts +4 -0
  41. package/src/services/sandbox/client.ts +215 -84
  42. package/src/services/sandbox/pause.ts +1 -1
  43. package/src/services/sandbox/types.ts +52 -0
  44. package/src/services/stream/delete.ts +87 -0
  45. package/src/services/stream/index.ts +3 -0
  46. package/src/services/stream/namespaces.ts +160 -0
  47. package/src/services/stream/search.ts +80 -0
  48. package/src/services/task/service.ts +371 -13
  49. package/src/services/vector/service.ts +8 -0
@@ -0,0 +1,80 @@
1
+ import { z } from 'zod';
2
+ import { type APIClient } from '../api.ts';
3
+ import { StreamNamespaceEntrySchema, type StreamNamespaceEntry } from './namespaces.ts';
4
+ import { StreamResponseError } from './util.ts';
5
+
6
+ // --- Response schema matching Pulse format ---
7
+
8
+ const SearchStreamsResponseSchema = z.discriminatedUnion('success', [
9
+ z.object({
10
+ success: z.literal<false>(false),
11
+ message: z.string().optional(),
12
+ }),
13
+ z.object({
14
+ success: z.literal<true>(true),
15
+ entries: z.array(StreamNamespaceEntrySchema),
16
+ total: z.number(),
17
+ }),
18
+ ]);
19
+
20
+ type SearchStreamsResponse = z.infer<typeof SearchStreamsResponseSchema>;
21
+
22
+ // --- Options ---
23
+
24
+ export interface StreamSearchOptions {
25
+ keyword: string;
26
+ namespace?: string;
27
+ limit?: number;
28
+ offset?: number;
29
+ }
30
+
31
+ // --- Return types ---
32
+
33
+ export interface StreamSearchResult {
34
+ entries: StreamNamespaceEntry[];
35
+ total: number;
36
+ }
37
+
38
+ // --- Function ---
39
+
40
+ /**
41
+ * Search streams by keyword across name, metadata, and headers.
42
+ * Optionally filter by a specific namespace.
43
+ *
44
+ * @param client - The API client configured for Pulse
45
+ * @param options - Search keyword, optional namespace filter, and pagination
46
+ * @returns Matching stream entries with total count
47
+ *
48
+ * @example
49
+ * const result = await streamSearch(client, { keyword: 'agent-logs' });
50
+ * console.log(`Found ${result.total} matching streams`);
51
+ *
52
+ * @example
53
+ * // Search within a specific namespace
54
+ * const result = await streamSearch(client, {
55
+ * keyword: 'error',
56
+ * namespace: 'agent-logs',
57
+ * limit: 50,
58
+ * });
59
+ */
60
+ export async function streamSearch(
61
+ client: APIClient,
62
+ options: StreamSearchOptions
63
+ ): Promise<StreamSearchResult> {
64
+ const resp = await client.post<SearchStreamsResponse>(
65
+ '/search',
66
+ {
67
+ keyword: options.keyword,
68
+ namespace: options.namespace,
69
+ limit: options.limit,
70
+ offset: options.offset,
71
+ },
72
+ SearchStreamsResponseSchema
73
+ );
74
+
75
+ if (resp.success) {
76
+ return { entries: resp.entries, total: resp.total };
77
+ }
78
+
79
+ throw new StreamResponseError({ message: resp.message });
80
+ }
@@ -30,10 +30,9 @@ export type TaskType = z.infer<typeof TaskTypeSchema>;
30
30
  * - `'open'` — Created, not yet started.
31
31
  * - `'in_progress'` — Actively being worked on.
32
32
  * - `'done'` — Work completed.
33
- * - `'closed'` — Resolved and closed.
34
33
  * - `'cancelled'` — Abandoned.
35
34
  */
36
- export const TaskStatusSchema = z.enum(['open', 'in_progress', 'closed', 'done', 'cancelled']);
35
+ export const TaskStatusSchema = z.enum(['open', 'in_progress', 'done', 'cancelled']);
37
36
 
38
37
  export type TaskStatus = z.infer<typeof TaskStatusSchema>;
39
38
 
@@ -451,6 +450,24 @@ export const BatchDeleteTasksParamsSchema = z.object({
451
450
 
452
451
  export type BatchDeleteTasksParams = z.infer<typeof BatchDeleteTasksParamsSchema>;
453
452
 
453
+ /**
454
+ * Parameters for creating a new user entity.
455
+ */
456
+ export interface CreateUserParams {
457
+ /** The user's display name. */
458
+ name: string;
459
+ /** The user type — defaults to 'human'. */
460
+ type?: 'human' | 'agent';
461
+ }
462
+
463
+ /**
464
+ * Parameters for creating a new project entity.
465
+ */
466
+ export interface CreateProjectParams {
467
+ /** The project name. */
468
+ name: string;
469
+ }
470
+
454
471
  /**
455
472
  * A single task that was deleted in a batch operation.
456
473
  */
@@ -639,9 +656,6 @@ export const TaskActivityDataPointSchema = z.object({
639
656
  /** Number of tasks in `'done'` status on this date. */
640
657
  done: z.number().describe("Number of tasks in `'done'` status on this date."),
641
658
 
642
- /** Number of tasks in `'closed'` status on this date. */
643
- closed: z.number().describe("Number of tasks in `'closed'` status on this date."),
644
-
645
659
  /** Number of tasks in `'cancelled'` status on this date. */
646
660
  cancelled: z.number().describe("Number of tasks in `'cancelled'` status on this date."),
647
661
  });
@@ -700,10 +714,10 @@ export interface TaskStorage {
700
714
  update(id: string, params: UpdateTaskParams): Promise<Task>;
701
715
 
702
716
  /**
703
- * Close a task by setting its status to closed.
717
+ * Close a task by setting its status to done.
704
718
  *
705
719
  * @param id - The unique task identifier
706
- * @returns The closed task
720
+ * @returns The task with updated closed_date and status set to done
707
721
  */
708
722
  close(id: string): Promise<Task>;
709
723
 
@@ -907,6 +921,52 @@ export interface TaskStorage {
907
921
  */
908
922
  listProjects(): Promise<ListProjectsResult>;
909
923
 
924
+ /**
925
+ * Create a new user entity.
926
+ *
927
+ * @param params - The user creation parameters
928
+ * @returns The created user entity reference
929
+ */
930
+ createUser(params: CreateUserParams): Promise<UserEntityRef>;
931
+
932
+ /**
933
+ * Get a user entity by ID.
934
+ *
935
+ * @param userId - The unique user identifier
936
+ * @returns The user entity reference
937
+ */
938
+ getUser(userId: string): Promise<UserEntityRef>;
939
+
940
+ /**
941
+ * Delete a user entity.
942
+ *
943
+ * @param userId - The unique user identifier
944
+ */
945
+ deleteUser(userId: string): Promise<void>;
946
+
947
+ /**
948
+ * Create a new project entity.
949
+ *
950
+ * @param params - The project creation parameters
951
+ * @returns The created project entity reference
952
+ */
953
+ createProject(params: CreateProjectParams): Promise<EntityRef>;
954
+
955
+ /**
956
+ * Get a project entity by ID.
957
+ *
958
+ * @param projectId - The unique project identifier
959
+ * @returns The project entity reference
960
+ */
961
+ getProject(projectId: string): Promise<EntityRef>;
962
+
963
+ /**
964
+ * Delete a project entity.
965
+ *
966
+ * @param projectId - The unique project identifier
967
+ */
968
+ deleteProject(projectId: string): Promise<void>;
969
+
910
970
  /**
911
971
  * Get task activity time-series data showing daily status counts.
912
972
  *
@@ -973,6 +1033,24 @@ const UserIdRequiredError = StructuredError(
973
1033
  'User ID is required and must be a non-empty string'
974
1034
  );
975
1035
 
1036
+ /** Thrown when a user name parameter is empty or not a string. */
1037
+ const UserNameRequiredError = StructuredError(
1038
+ 'UserNameRequiredError',
1039
+ 'A non-empty user name is required.'
1040
+ );
1041
+
1042
+ /** Thrown when a project name parameter is empty or not a string. */
1043
+ const ProjectNameRequiredError = StructuredError(
1044
+ 'ProjectNameRequiredError',
1045
+ 'A non-empty project name is required.'
1046
+ );
1047
+
1048
+ /** Thrown when a project ID parameter is empty or not a string. */
1049
+ const ProjectIdRequiredError = StructuredError(
1050
+ 'ProjectIdRequiredError',
1051
+ 'A non-empty project ID is required.'
1052
+ );
1053
+
976
1054
  /**
977
1055
  * Thrown when the API returns a success HTTP status but the response body indicates failure.
978
1056
  */
@@ -1009,7 +1087,7 @@ type TaskResponse<T> = TaskSuccessResponse<T> | TaskErrorResponse;
1009
1087
  * presigned S3 URLs, changelog tracking, and activity analytics.
1010
1088
  *
1011
1089
  * Tasks support lifecycle management through status transitions (`open` → `in_progress`
1012
- * → `done`/`closed`/`cancelled`) with automatic date tracking for each transition.
1090
+ * → `done`/`cancelled`) with automatic date tracking for each transition.
1013
1091
  *
1014
1092
  * All methods validate inputs client-side and throw structured errors for invalid
1015
1093
  * parameters. API errors throw {@link ServiceException}.
@@ -1286,17 +1364,17 @@ export class TaskStorageService implements TaskStorage {
1286
1364
  }
1287
1365
 
1288
1366
  /**
1289
- * Close a task by setting its status to closed.
1367
+ * Close a task by setting its status to done.
1290
1368
  *
1291
1369
  * @param id - The unique task identifier
1292
- * @returns The closed task with updated `closed_date`
1370
+ * @returns The task with status set to done and updated closed_date
1293
1371
  * @throws {@link TaskIdRequiredError} if the ID is empty or not a string
1294
1372
  * @throws {@link ServiceException} if the API request fails
1295
1373
  *
1296
1374
  * @example
1297
1375
  * ```typescript
1298
- * const closed = await tasks.close('task_abc123');
1299
- * console.log('Closed at:', closed.closed_date);
1376
+ * const task = await tasks.close('task_abc123');
1377
+ * console.log('Done at:', task.closed_date);
1300
1378
  * ```
1301
1379
  */
1302
1380
  async close(id: string): Promise<Task> {
@@ -1449,7 +1527,7 @@ export class TaskStorageService implements TaskStorage {
1449
1527
  *
1450
1528
  * @example
1451
1529
  * ```typescript
1452
- * const result = await tasks.batchDelete({ status: 'closed', older_than: '7d', limit: 50 });
1530
+ * const result = await tasks.batchDelete({ status: 'done', older_than: '7d', limit: 50 });
1453
1531
  * console.log(`Deleted ${result.count} tasks`);
1454
1532
  * ```
1455
1533
  */
@@ -2524,6 +2602,286 @@ export class TaskStorageService implements TaskStorage {
2524
2602
  throw await toServiceException('GET', url, res.response);
2525
2603
  }
2526
2604
 
2605
+ /**
2606
+ * Create a new user entity.
2607
+ *
2608
+ * @param params - The user creation parameters including name and optional type
2609
+ * @returns The created user entity reference
2610
+ * @throws {@link UserNameRequiredError} if the name is empty or not a string
2611
+ * @throws {@link ServiceException} if the API request fails
2612
+ *
2613
+ * @example
2614
+ * ```typescript
2615
+ * const user = await tasks.createUser({ name: 'Jane Doe', type: 'human' });
2616
+ * console.log('Created user:', user.id, user.name);
2617
+ * ```
2618
+ */
2619
+ async createUser(params: CreateUserParams): Promise<UserEntityRef> {
2620
+ if (!params?.name || typeof params.name !== 'string' || params.name.trim().length === 0) {
2621
+ throw new UserNameRequiredError();
2622
+ }
2623
+
2624
+ const normalizedName = params.name.trim();
2625
+ const url = buildUrl(this.#baseUrl, `/task/users/create/${TASK_API_VERSION}`);
2626
+ const signal = AbortSignal.timeout(30_000);
2627
+
2628
+ const res = await this.#adapter.invoke<TaskResponse<UserEntityRef>>(url, {
2629
+ method: 'POST',
2630
+ body: safeStringify({ ...params, name: normalizedName }),
2631
+ contentType: 'application/json',
2632
+ signal,
2633
+ telemetry: {
2634
+ name: 'agentuity.task.createUser',
2635
+ attributes: { userName: normalizedName },
2636
+ },
2637
+ });
2638
+
2639
+ if (res.ok) {
2640
+ if (res.data.success) {
2641
+ return res.data.data;
2642
+ }
2643
+ throw new TaskStorageResponseError({
2644
+ status: res.response.status,
2645
+ message: res.data.message,
2646
+ });
2647
+ }
2648
+
2649
+ throw await toServiceException('POST', url, res.response);
2650
+ }
2651
+
2652
+ /**
2653
+ * Get a user entity by ID.
2654
+ *
2655
+ * @param userId - The unique user identifier
2656
+ * @returns The user entity reference
2657
+ * @throws {@link UserIdRequiredError} if the user ID is empty or not a string
2658
+ * @throws {@link ServiceException} if the API request fails
2659
+ *
2660
+ * @example
2661
+ * ```typescript
2662
+ * const user = await tasks.getUser('usr_abc123');
2663
+ * console.log(`${user.name} (${user.type})`);
2664
+ * ```
2665
+ */
2666
+ async getUser(userId: string): Promise<UserEntityRef> {
2667
+ if (!userId || typeof userId !== 'string' || userId.trim().length === 0) {
2668
+ throw new UserIdRequiredError();
2669
+ }
2670
+
2671
+ const url = buildUrl(
2672
+ this.#baseUrl,
2673
+ `/task/users/get/${TASK_API_VERSION}/${encodeURIComponent(userId)}`
2674
+ );
2675
+ const signal = AbortSignal.timeout(30_000);
2676
+
2677
+ const res = await this.#adapter.invoke<TaskResponse<UserEntityRef>>(url, {
2678
+ method: 'GET',
2679
+ signal,
2680
+ telemetry: {
2681
+ name: 'agentuity.task.getUser',
2682
+ attributes: { userId },
2683
+ },
2684
+ });
2685
+
2686
+ if (res.ok) {
2687
+ if (res.data.success) {
2688
+ return res.data.data;
2689
+ }
2690
+ throw new TaskStorageResponseError({
2691
+ status: res.response.status,
2692
+ message: res.data.message,
2693
+ });
2694
+ }
2695
+
2696
+ throw await toServiceException('GET', url, res.response);
2697
+ }
2698
+
2699
+ /**
2700
+ * Delete a user entity.
2701
+ *
2702
+ * @param userId - The unique user identifier
2703
+ * @throws {@link UserIdRequiredError} if the user ID is empty or not a string
2704
+ * @throws {@link ServiceException} if the API request fails
2705
+ *
2706
+ * @example
2707
+ * ```typescript
2708
+ * await tasks.deleteUser('usr_abc123');
2709
+ * console.log('User deleted');
2710
+ * ```
2711
+ */
2712
+ async deleteUser(userId: string): Promise<void> {
2713
+ if (!userId || typeof userId !== 'string' || userId.trim().length === 0) {
2714
+ throw new UserIdRequiredError();
2715
+ }
2716
+
2717
+ const url = buildUrl(
2718
+ this.#baseUrl,
2719
+ `/task/users/delete/${TASK_API_VERSION}/${encodeURIComponent(userId)}`
2720
+ );
2721
+ const signal = AbortSignal.timeout(30_000);
2722
+
2723
+ const res = await this.#adapter.invoke<TaskResponse<void>>(url, {
2724
+ method: 'DELETE',
2725
+ signal,
2726
+ telemetry: {
2727
+ name: 'agentuity.task.deleteUser',
2728
+ attributes: { userId },
2729
+ },
2730
+ });
2731
+
2732
+ if (res.ok) {
2733
+ if (res.data?.success === false) {
2734
+ throw new TaskStorageResponseError({
2735
+ status: res.response.status,
2736
+ message: res.data.message ?? 'Operation failed',
2737
+ });
2738
+ }
2739
+ return;
2740
+ }
2741
+
2742
+ throw await toServiceException('DELETE', url, res.response);
2743
+ }
2744
+
2745
+ /**
2746
+ * Create a new project entity.
2747
+ *
2748
+ * @param params - The project creation parameters including name
2749
+ * @returns The created project entity reference
2750
+ * @throws {@link ProjectNameRequiredError} if the name is empty or not a string
2751
+ * @throws {@link ServiceException} if the API request fails
2752
+ *
2753
+ * @example
2754
+ * ```typescript
2755
+ * const project = await tasks.createProject({ name: 'My Project' });
2756
+ * console.log('Created project:', project.id, project.name);
2757
+ * ```
2758
+ */
2759
+ async createProject(params: CreateProjectParams): Promise<EntityRef> {
2760
+ if (!params?.name || typeof params.name !== 'string' || params.name.trim().length === 0) {
2761
+ throw new ProjectNameRequiredError();
2762
+ }
2763
+
2764
+ const normalizedName = params.name.trim();
2765
+ const url = buildUrl(this.#baseUrl, `/task/projects/create/${TASK_API_VERSION}`);
2766
+ const signal = AbortSignal.timeout(30_000);
2767
+
2768
+ const res = await this.#adapter.invoke<TaskResponse<EntityRef>>(url, {
2769
+ method: 'POST',
2770
+ body: safeStringify({ ...params, name: normalizedName }),
2771
+ contentType: 'application/json',
2772
+ signal,
2773
+ telemetry: {
2774
+ name: 'agentuity.task.createProject',
2775
+ attributes: { projectName: normalizedName },
2776
+ },
2777
+ });
2778
+
2779
+ if (res.ok) {
2780
+ if (res.data.success) {
2781
+ return res.data.data;
2782
+ }
2783
+ throw new TaskStorageResponseError({
2784
+ status: res.response.status,
2785
+ message: res.data.message,
2786
+ });
2787
+ }
2788
+
2789
+ throw await toServiceException('POST', url, res.response);
2790
+ }
2791
+
2792
+ /**
2793
+ * Get a project entity by ID.
2794
+ *
2795
+ * @param projectId - The unique project identifier
2796
+ * @returns The project entity reference
2797
+ * @throws {@link ProjectIdRequiredError} if the project ID is empty or not a string
2798
+ * @throws {@link ServiceException} if the API request fails
2799
+ *
2800
+ * @example
2801
+ * ```typescript
2802
+ * const project = await tasks.getProject('prj_abc123');
2803
+ * console.log(`${project.name} (${project.id})`);
2804
+ * ```
2805
+ */
2806
+ async getProject(projectId: string): Promise<EntityRef> {
2807
+ if (!projectId || typeof projectId !== 'string' || projectId.trim().length === 0) {
2808
+ throw new ProjectIdRequiredError();
2809
+ }
2810
+
2811
+ const url = buildUrl(
2812
+ this.#baseUrl,
2813
+ `/task/projects/get/${TASK_API_VERSION}/${encodeURIComponent(projectId)}`
2814
+ );
2815
+ const signal = AbortSignal.timeout(30_000);
2816
+
2817
+ const res = await this.#adapter.invoke<TaskResponse<EntityRef>>(url, {
2818
+ method: 'GET',
2819
+ signal,
2820
+ telemetry: {
2821
+ name: 'agentuity.task.getProject',
2822
+ attributes: { projectId },
2823
+ },
2824
+ });
2825
+
2826
+ if (res.ok) {
2827
+ if (res.data.success) {
2828
+ return res.data.data;
2829
+ }
2830
+ throw new TaskStorageResponseError({
2831
+ status: res.response.status,
2832
+ message: res.data.message,
2833
+ });
2834
+ }
2835
+
2836
+ throw await toServiceException('GET', url, res.response);
2837
+ }
2838
+
2839
+ /**
2840
+ * Delete a project entity.
2841
+ *
2842
+ * @param projectId - The unique project identifier
2843
+ * @throws {@link ProjectIdRequiredError} if the project ID is empty or not a string
2844
+ * @throws {@link ServiceException} if the API request fails
2845
+ *
2846
+ * @example
2847
+ * ```typescript
2848
+ * await tasks.deleteProject('prj_abc123');
2849
+ * console.log('Project deleted');
2850
+ * ```
2851
+ */
2852
+ async deleteProject(projectId: string): Promise<void> {
2853
+ if (!projectId || typeof projectId !== 'string' || projectId.trim().length === 0) {
2854
+ throw new ProjectIdRequiredError();
2855
+ }
2856
+
2857
+ const url = buildUrl(
2858
+ this.#baseUrl,
2859
+ `/task/projects/delete/${TASK_API_VERSION}/${encodeURIComponent(projectId)}`
2860
+ );
2861
+ const signal = AbortSignal.timeout(30_000);
2862
+
2863
+ const res = await this.#adapter.invoke<TaskResponse<void>>(url, {
2864
+ method: 'DELETE',
2865
+ signal,
2866
+ telemetry: {
2867
+ name: 'agentuity.task.deleteProject',
2868
+ attributes: { projectId },
2869
+ },
2870
+ });
2871
+
2872
+ if (res.ok) {
2873
+ if (res.data?.success === false) {
2874
+ throw new TaskStorageResponseError({
2875
+ status: res.response.status,
2876
+ message: res.data.message ?? 'Operation failed',
2877
+ });
2878
+ }
2879
+ return;
2880
+ }
2881
+
2882
+ throw await toServiceException('DELETE', url, res.response);
2883
+ }
2884
+
2527
2885
  /**
2528
2886
  * Get task activity time-series data showing daily task counts by status.
2529
2887
  *
@@ -341,6 +341,14 @@ export const VectorNamespaceStatsSchema = z.object({
341
341
  .number()
342
342
  .optional()
343
343
  .describe('Unix timestamp (milliseconds) when the namespace was last used'),
344
+
345
+ /**
346
+ * Whether this namespace is system-managed (internal)
347
+ */
348
+ internal: z
349
+ .boolean()
350
+ .optional()
351
+ .describe('Whether this namespace is system-managed (internal).'),
344
352
  });
345
353
 
346
354
  export type VectorNamespaceStats = z.infer<typeof VectorNamespaceStatsSchema>;