@acontext/acontext 0.0.9 → 0.0.10

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.
@@ -27,7 +27,6 @@ export declare const AcontextMessageSchema: z.ZodObject<{
27
27
  role: z.ZodEnum<{
28
28
  user: "user";
29
29
  assistant: "assistant";
30
- system: "system";
31
30
  }>;
32
31
  parts: z.ZodArray<z.ZodObject<{
33
32
  type: z.ZodString;
@@ -39,14 +38,14 @@ export declare const AcontextMessageSchema: z.ZodObject<{
39
38
  }, z.core.$strip>;
40
39
  export type AcontextMessageInput = z.infer<typeof AcontextMessageSchema>;
41
40
  export declare class AcontextMessage {
42
- role: 'user' | 'assistant' | 'system';
41
+ role: 'user' | 'assistant';
43
42
  parts: MessagePart[];
44
43
  meta?: Record<string, unknown> | null;
45
44
  constructor(data: AcontextMessageInput);
46
45
  toJSON(): AcontextMessageInput;
47
46
  }
48
47
  export declare function buildAcontextMessage(options: {
49
- role: 'user' | 'assistant' | 'system';
48
+ role: 'user' | 'assistant';
50
49
  parts: (MessagePart | string | MessagePartInput)[];
51
50
  meta?: Record<string, unknown> | null;
52
51
  }): AcontextMessage;
package/dist/messages.js CHANGED
@@ -44,7 +44,7 @@ class MessagePart {
44
44
  }
45
45
  exports.MessagePart = MessagePart;
46
46
  exports.AcontextMessageSchema = zod_1.z.object({
47
- role: zod_1.z.enum(['user', 'assistant', 'system']),
47
+ role: zod_1.z.enum(['user', 'assistant']),
48
48
  parts: zod_1.z.array(exports.MessagePartSchema),
49
49
  meta: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).nullable().optional(),
50
50
  });
@@ -64,8 +64,8 @@ class AcontextMessage {
64
64
  }
65
65
  exports.AcontextMessage = AcontextMessage;
66
66
  function buildAcontextMessage(options) {
67
- if (!['user', 'assistant', 'system'].includes(options.role)) {
68
- throw new Error("role must be one of {'user', 'assistant', 'system'}");
67
+ if (!['user', 'assistant'].includes(options.role)) {
68
+ throw new Error("role must be one of {'user', 'assistant'}");
69
69
  }
70
70
  const normalizedParts = options.parts.map((part) => {
71
71
  if (part instanceof MessagePart) {
@@ -4,7 +4,7 @@
4
4
  import { RequesterProtocol } from '../client-types';
5
5
  import { AcontextMessage } from '../messages';
6
6
  import { FileUpload } from '../uploads';
7
- import { GetMessagesOutput, GetTasksOutput, LearningStatus, ListSessionsOutput, Message, Session, TokenCounts } from '../types';
7
+ import { EditStrategy, GetMessagesOutput, GetTasksOutput, LearningStatus, ListSessionsOutput, Message, Session, TokenCounts } from '../types';
8
8
  export type MessageBlob = AcontextMessage | Record<string, unknown>;
9
9
  export declare class SessionsAPI {
10
10
  private requester;
@@ -18,6 +18,7 @@ export declare class SessionsAPI {
18
18
  }): Promise<ListSessionsOutput>;
19
19
  create(options?: {
20
20
  spaceId?: string | null;
21
+ disableTaskTracking?: boolean | null;
21
22
  configs?: Record<string, unknown>;
22
23
  }): Promise<Session>;
23
24
  delete(sessionId: string): Promise<void>;
@@ -38,12 +39,29 @@ export declare class SessionsAPI {
38
39
  fileField?: string | null;
39
40
  file?: FileUpload | null;
40
41
  }): Promise<Message>;
42
+ /**
43
+ * Get messages for a session.
44
+ *
45
+ * @param sessionId - The UUID of the session.
46
+ * @param options - Options for retrieving messages.
47
+ * @param options.limit - Maximum number of messages to return.
48
+ * @param options.cursor - Cursor for pagination.
49
+ * @param options.withAssetPublicUrl - Whether to include presigned URLs for assets.
50
+ * @param options.format - The format of the messages ('acontext', 'openai', or 'anthropic').
51
+ * @param options.timeDesc - Order by created_at descending if true, ascending if false.
52
+ * @param options.editStrategies - Optional list of edit strategies to apply before format conversion.
53
+ * Examples:
54
+ * - Remove tool results: [{ type: 'remove_tool_result', params: { keep_recent_n_tool_results: 3 } }]
55
+ * - Token limit: [{ type: 'token_limit', params: { limit_tokens: 20000 } }]
56
+ * @returns GetMessagesOutput containing the list of messages and pagination information.
57
+ */
41
58
  getMessages(sessionId: string, options?: {
42
59
  limit?: number | null;
43
60
  cursor?: string | null;
44
61
  withAssetPublicUrl?: boolean | null;
45
62
  format?: 'acontext' | 'openai' | 'anthropic';
46
63
  timeDesc?: boolean | null;
64
+ editStrategies?: Array<EditStrategy> | null;
47
65
  }): Promise<GetMessagesOutput>;
48
66
  flush(sessionId: string): Promise<{
49
67
  status: number;
@@ -32,6 +32,9 @@ class SessionsAPI {
32
32
  if (options?.spaceId) {
33
33
  payload.space_id = options.spaceId;
34
34
  }
35
+ if (options?.disableTaskTracking !== undefined && options?.disableTaskTracking !== null) {
36
+ payload.disable_task_tracking = options.disableTaskTracking;
37
+ }
35
38
  if (options?.configs !== undefined) {
36
39
  payload.configs = options.configs;
37
40
  }
@@ -115,6 +118,22 @@ class SessionsAPI {
115
118
  return types_1.MessageSchema.parse(data);
116
119
  }
117
120
  }
121
+ /**
122
+ * Get messages for a session.
123
+ *
124
+ * @param sessionId - The UUID of the session.
125
+ * @param options - Options for retrieving messages.
126
+ * @param options.limit - Maximum number of messages to return.
127
+ * @param options.cursor - Cursor for pagination.
128
+ * @param options.withAssetPublicUrl - Whether to include presigned URLs for assets.
129
+ * @param options.format - The format of the messages ('acontext', 'openai', or 'anthropic').
130
+ * @param options.timeDesc - Order by created_at descending if true, ascending if false.
131
+ * @param options.editStrategies - Optional list of edit strategies to apply before format conversion.
132
+ * Examples:
133
+ * - Remove tool results: [{ type: 'remove_tool_result', params: { keep_recent_n_tool_results: 3 } }]
134
+ * - Token limit: [{ type: 'token_limit', params: { limit_tokens: 20000 } }]
135
+ * @returns GetMessagesOutput containing the list of messages and pagination information.
136
+ */
118
137
  async getMessages(sessionId, options) {
119
138
  const params = {};
120
139
  if (options?.format !== undefined) {
@@ -126,6 +145,9 @@ class SessionsAPI {
126
145
  with_asset_public_url: options?.withAssetPublicUrl ?? null,
127
146
  time_desc: options?.timeDesc ?? true, // Default to true
128
147
  }));
148
+ if (options?.editStrategies !== undefined && options?.editStrategies !== null) {
149
+ params.edit_strategies = JSON.stringify(options.editStrategies);
150
+ }
129
151
  const data = await this.requester.request('GET', `/session/${sessionId}/messages`, {
130
152
  params: Object.keys(params).length > 0 ? params : undefined,
131
153
  });
@@ -95,7 +95,7 @@ class SpacesAPI {
95
95
  */
96
96
  async confirmExperience(spaceId, experienceId, options) {
97
97
  const payload = { save: options.save };
98
- const data = await this.requester.request('PATCH', `/space/${spaceId}/experience_confirmations/${experienceId}`, { jsonData: payload });
98
+ const data = await this.requester.request('PUT', `/space/${spaceId}/experience_confirmations/${experienceId}`, { jsonData: payload });
99
99
  if (data === null || data === undefined) {
100
100
  return null;
101
101
  }
@@ -55,6 +55,7 @@ export type Message = z.infer<typeof MessageSchema>;
55
55
  export declare const SessionSchema: z.ZodObject<{
56
56
  id: z.ZodString;
57
57
  project_id: z.ZodString;
58
+ disable_task_tracking: z.ZodBoolean;
58
59
  space_id: z.ZodNullable<z.ZodString>;
59
60
  configs: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
60
61
  created_at: z.ZodString;
@@ -78,6 +79,7 @@ export declare const ListSessionsOutputSchema: z.ZodObject<{
78
79
  items: z.ZodArray<z.ZodObject<{
79
80
  id: z.ZodString;
80
81
  project_id: z.ZodString;
82
+ disable_task_tracking: z.ZodBoolean;
81
83
  space_id: z.ZodNullable<z.ZodString>;
82
84
  configs: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
83
85
  created_at: z.ZodString;
@@ -128,3 +130,64 @@ export declare const TokenCountsSchema: z.ZodObject<{
128
130
  total_tokens: z.ZodNumber;
129
131
  }, z.core.$strip>;
130
132
  export type TokenCounts = z.infer<typeof TokenCountsSchema>;
133
+ /**
134
+ * Parameters for the remove_tool_result edit strategy.
135
+ */
136
+ export declare const RemoveToolResultParamsSchema: z.ZodObject<{
137
+ keep_recent_n_tool_results: z.ZodOptional<z.ZodNumber>;
138
+ tool_result_placeholder: z.ZodOptional<z.ZodString>;
139
+ }, z.core.$strip>;
140
+ export type RemoveToolResultParams = z.infer<typeof RemoveToolResultParamsSchema>;
141
+ /**
142
+ * Edit strategy to replace old tool results with placeholder text.
143
+ *
144
+ * Example: { type: 'remove_tool_result', params: { keep_recent_n_tool_results: 5, tool_result_placeholder: 'Cleared' } }
145
+ */
146
+ export declare const RemoveToolResultStrategySchema: z.ZodObject<{
147
+ type: z.ZodLiteral<"remove_tool_result">;
148
+ params: z.ZodObject<{
149
+ keep_recent_n_tool_results: z.ZodOptional<z.ZodNumber>;
150
+ tool_result_placeholder: z.ZodOptional<z.ZodString>;
151
+ }, z.core.$strip>;
152
+ }, z.core.$strip>;
153
+ export type RemoveToolResultStrategy = z.infer<typeof RemoveToolResultStrategySchema>;
154
+ /**
155
+ * Parameters for the token_limit edit strategy.
156
+ */
157
+ export declare const TokenLimitParamsSchema: z.ZodObject<{
158
+ limit_tokens: z.ZodNumber;
159
+ }, z.core.$strip>;
160
+ export type TokenLimitParams = z.infer<typeof TokenLimitParamsSchema>;
161
+ /**
162
+ * Edit strategy to truncate messages based on token count.
163
+ *
164
+ * Removes oldest messages until the total token count is within the specified limit.
165
+ * Maintains tool-call/tool-result pairing - when removing a message with tool-calls,
166
+ * the corresponding tool-result messages are also removed.
167
+ *
168
+ * Example: { type: 'token_limit', params: { limit_tokens: 20000 } }
169
+ */
170
+ export declare const TokenLimitStrategySchema: z.ZodObject<{
171
+ type: z.ZodLiteral<"token_limit">;
172
+ params: z.ZodObject<{
173
+ limit_tokens: z.ZodNumber;
174
+ }, z.core.$strip>;
175
+ }, z.core.$strip>;
176
+ export type TokenLimitStrategy = z.infer<typeof TokenLimitStrategySchema>;
177
+ /**
178
+ * Union schema for all edit strategies.
179
+ * When adding new strategies, extend this union: z.union([RemoveToolResultStrategySchema, OtherStrategySchema, ...])
180
+ */
181
+ export declare const EditStrategySchema: z.ZodUnion<readonly [z.ZodObject<{
182
+ type: z.ZodLiteral<"remove_tool_result">;
183
+ params: z.ZodObject<{
184
+ keep_recent_n_tool_results: z.ZodOptional<z.ZodNumber>;
185
+ tool_result_placeholder: z.ZodOptional<z.ZodString>;
186
+ }, z.core.$strip>;
187
+ }, z.core.$strip>, z.ZodObject<{
188
+ type: z.ZodLiteral<"token_limit">;
189
+ params: z.ZodObject<{
190
+ limit_tokens: z.ZodNumber;
191
+ }, z.core.$strip>;
192
+ }, z.core.$strip>]>;
193
+ export type EditStrategy = z.infer<typeof EditStrategySchema>;
@@ -3,7 +3,7 @@
3
3
  * Type definitions for session, message, and task resources.
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.TokenCountsSchema = exports.LearningStatusSchema = exports.GetTasksOutputSchema = exports.GetMessagesOutputSchema = exports.PublicURLSchema = exports.ListSessionsOutputSchema = exports.TaskSchema = exports.SessionSchema = exports.MessageSchema = exports.PartSchema = exports.AssetSchema = void 0;
6
+ exports.EditStrategySchema = exports.TokenLimitStrategySchema = exports.TokenLimitParamsSchema = exports.RemoveToolResultStrategySchema = exports.RemoveToolResultParamsSchema = exports.TokenCountsSchema = exports.LearningStatusSchema = exports.GetTasksOutputSchema = exports.GetMessagesOutputSchema = exports.PublicURLSchema = exports.ListSessionsOutputSchema = exports.TaskSchema = exports.SessionSchema = exports.MessageSchema = exports.PartSchema = exports.AssetSchema = void 0;
7
7
  const zod_1 = require("zod");
8
8
  exports.AssetSchema = zod_1.z.object({
9
9
  bucket: zod_1.z.string(),
@@ -35,6 +35,7 @@ exports.MessageSchema = zod_1.z.object({
35
35
  exports.SessionSchema = zod_1.z.object({
36
36
  id: zod_1.z.string(),
37
37
  project_id: zod_1.z.string(),
38
+ disable_task_tracking: zod_1.z.boolean(),
38
39
  space_id: zod_1.z.string().nullable(),
39
40
  configs: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).nullable(),
40
41
  created_at: zod_1.z.string(),
@@ -79,3 +80,59 @@ exports.LearningStatusSchema = zod_1.z.object({
79
80
  exports.TokenCountsSchema = zod_1.z.object({
80
81
  total_tokens: zod_1.z.number(),
81
82
  });
83
+ /**
84
+ * Parameters for the remove_tool_result edit strategy.
85
+ */
86
+ exports.RemoveToolResultParamsSchema = zod_1.z.object({
87
+ /**
88
+ * Number of most recent tool results to keep with original content.
89
+ * @default 3
90
+ */
91
+ keep_recent_n_tool_results: zod_1.z.number().optional(),
92
+ /**
93
+ * Custom text to replace old tool results with.
94
+ * @default "Done"
95
+ */
96
+ tool_result_placeholder: zod_1.z.string().optional(),
97
+ });
98
+ /**
99
+ * Edit strategy to replace old tool results with placeholder text.
100
+ *
101
+ * Example: { type: 'remove_tool_result', params: { keep_recent_n_tool_results: 5, tool_result_placeholder: 'Cleared' } }
102
+ */
103
+ exports.RemoveToolResultStrategySchema = zod_1.z.object({
104
+ type: zod_1.z.literal('remove_tool_result'),
105
+ params: exports.RemoveToolResultParamsSchema,
106
+ });
107
+ /**
108
+ * Parameters for the token_limit edit strategy.
109
+ */
110
+ exports.TokenLimitParamsSchema = zod_1.z.object({
111
+ /**
112
+ * Maximum number of tokens to keep. Required parameter.
113
+ * Messages will be removed from oldest to newest until total tokens <= limit_tokens.
114
+ * Tool-call and tool-result pairs are always removed together.
115
+ */
116
+ limit_tokens: zod_1.z.number(),
117
+ });
118
+ /**
119
+ * Edit strategy to truncate messages based on token count.
120
+ *
121
+ * Removes oldest messages until the total token count is within the specified limit.
122
+ * Maintains tool-call/tool-result pairing - when removing a message with tool-calls,
123
+ * the corresponding tool-result messages are also removed.
124
+ *
125
+ * Example: { type: 'token_limit', params: { limit_tokens: 20000 } }
126
+ */
127
+ exports.TokenLimitStrategySchema = zod_1.z.object({
128
+ type: zod_1.z.literal('token_limit'),
129
+ params: exports.TokenLimitParamsSchema,
130
+ });
131
+ /**
132
+ * Union schema for all edit strategies.
133
+ * When adding new strategies, extend this union: z.union([RemoveToolResultStrategySchema, OtherStrategySchema, ...])
134
+ */
135
+ exports.EditStrategySchema = zod_1.z.union([
136
+ exports.RemoveToolResultStrategySchema,
137
+ exports.TokenLimitStrategySchema,
138
+ ]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acontext/acontext",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "description": "TypeScript SDK for the Acontext API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",