@harnessio/ai-chat-core 0.0.16 → 0.0.18

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.
@@ -1,3 +1,4 @@
1
+ import { SystemEvent } from '../../types/adapters';
1
2
  import { AppendMessage, Message } from '../../types/message';
2
3
  import { RuntimeCapabilities, ThreadState } from '../../types/thread';
3
4
  import { BaseSubscribable, Unsubscribe } from '../../utils/Subscribable';
@@ -10,12 +11,18 @@ export declare class ThreadRuntime extends BaseSubscribable {
10
11
  get messages(): readonly Message[];
11
12
  get isRunning(): boolean;
12
13
  get isDisabled(): boolean;
14
+ get isWaitingForUser(): boolean;
15
+ get pendingCapability(): {
16
+ capabilityId: string;
17
+ capabilityName: string;
18
+ } | null;
13
19
  get capabilities(): RuntimeCapabilities;
14
20
  get conversationId(): string | undefined;
15
21
  get title(): string | undefined;
16
22
  getState(): ThreadState;
17
23
  append(message: AppendMessage): void;
18
24
  send(text: string): Promise<void>;
25
+ sendSystemEvent(systemEvent: SystemEvent): Promise<void>;
19
26
  cancelRun(): void;
20
27
  clear(): void;
21
28
  reset(messages?: Message[]): void;
@@ -1,5 +1,5 @@
1
1
  import { CapabilityExecutionManager } from '../../core';
2
- import { StreamAdapter } from '../../types/adapters';
2
+ import { StreamAdapter, SystemEvent } from '../../types/adapters';
3
3
  import { AppendMessage, Message } from '../../types/message';
4
4
  import { RuntimeCapabilities } from '../../types/thread';
5
5
  import { BaseSubscribable } from '../../utils/Subscribable';
@@ -14,6 +14,8 @@ export declare class ThreadRuntimeCore extends BaseSubscribable {
14
14
  private _messages;
15
15
  private _isRunning;
16
16
  private _isDisabled;
17
+ private _isWaitingForUser;
18
+ private _pendingCapability;
17
19
  private _abortController;
18
20
  private _conversationId?;
19
21
  private _title?;
@@ -22,11 +24,17 @@ export declare class ThreadRuntimeCore extends BaseSubscribable {
22
24
  get messages(): readonly Message[];
23
25
  get isRunning(): boolean;
24
26
  get isDisabled(): boolean;
27
+ get isWaitingForUser(): boolean;
28
+ get pendingCapability(): {
29
+ capabilityId: string;
30
+ capabilityName: string;
31
+ } | null;
25
32
  get conversationId(): string | undefined;
26
33
  get title(): string | undefined;
27
34
  get capabilities(): RuntimeCapabilities;
28
35
  private updateMessages;
29
36
  append(message: AppendMessage): void;
37
+ startSystemEventRun(systemEvent: SystemEvent): Promise<void>;
30
38
  startRun(userMessage: AppendMessage): Promise<void>;
31
39
  private handleStreamEvent;
32
40
  private handlePartStart;
@@ -30,6 +30,7 @@ export type StreamEvent = {
30
30
  readonly capabilityName: string;
31
31
  readonly capabilityId: string;
32
32
  readonly args: any;
33
+ readonly status?: 'executing' | 'waiting_for_user' | 'waiting_for_confirmation' | 'completed';
33
34
  readonly strategy?: 'queue' | 'parallel' | 'replace';
34
35
  } | {
35
36
  readonly type: string;
@@ -37,11 +38,22 @@ export type StreamEvent = {
37
38
  readonly parentId?: string;
38
39
  [key: string]: any;
39
40
  };
41
+ export type SystemEventType = 'action_completed' | 'action_cancelled';
42
+ export interface SystemEvent {
43
+ event_type: SystemEventType;
44
+ capability_id: string;
45
+ result?: {
46
+ success: boolean;
47
+ [key: string]: unknown;
48
+ };
49
+ target_page_id?: string;
50
+ }
40
51
  export interface StreamRequest {
41
52
  messages: Message[];
42
53
  conversationId?: string;
43
54
  signal?: AbortSignal;
44
55
  config?: Record<string, unknown>;
56
+ systemEvent?: SystemEvent;
45
57
  }
46
58
  export interface StreamChunk {
47
59
  event: StreamEvent;
@@ -1,7 +1,7 @@
1
1
  export type { Message, MessageContent, MessageRole, MessageStatus, AppendMessage, TextContent, ErrorContent, MetadataContent, AssistantThoughtContent, CustomContent, ArtifactContent } from './message';
2
2
  export type { ThreadListItemState, ThreadState, RuntimeCapabilities } from './thread';
3
- export type { ChatPlugin, MessageRenderer, MessageRendererProps, GroupRenderer, GroupRendererProps, PluginConfig } from './plugin';
4
- export type { StreamAdapter, ThreadListAdapter, StreamEvent, StreamRequest, StreamChunk, ThreadListLoadOptions } from './adapters';
3
+ export type { ChatPlugin, MessageRenderer, MessageRendererProps, GroupRenderer, GroupRendererProps, PluginConfig, AuxiliaryRendererProps } from './plugin';
4
+ export type { StreamAdapter, ThreadListAdapter, StreamEvent, StreamRequest, StreamChunk, ThreadListLoadOptions, SystemEvent, SystemEventType } from './adapters';
5
5
  export type { SSEEvent } from '../utils/BaseSSEStreamAdapter';
6
6
  export type { CapabilityStatus, CapabilityExecutionContext, CapabilityExecution, CapabilityHandler, CapabilityRendererProps, CapabilityRenderer, CapabilityConfig, CapabilityContent } from './capability';
7
7
  export type { ChatContextItem, ChatContextMap, ChatContextData, ChatContextValue } from './context';
@@ -15,6 +15,7 @@ export interface ThreadState {
15
15
  threadId: string;
16
16
  isDisabled: boolean;
17
17
  isRunning: boolean;
18
+ isWaitingForUser: boolean;
18
19
  capabilities: RuntimeCapabilities;
19
20
  conversationId?: string;
20
21
  title?: string;
@@ -1,11 +1,11 @@
1
- import { StreamAdapter, StreamChunk } from '../types/adapters';
1
+ import { StreamAdapter, StreamChunk, StreamRequest } from '../types/adapters';
2
2
  import { Message } from '../types/message';
3
3
  export interface SSEEvent {
4
4
  event: string;
5
5
  data: any;
6
6
  }
7
7
  export declare abstract class BaseSSEStreamAdapter<TAllowedEvents extends readonly string[] = readonly string[]> implements StreamAdapter {
8
- protected abstract prepareRequest(params: {
8
+ protected abstract prepareRequest(params: StreamRequest & {
9
9
  messages: Message[];
10
10
  conversationId?: string;
11
11
  signal?: AbortSignal;
@@ -18,10 +18,6 @@ export declare abstract class BaseSSEStreamAdapter<TAllowedEvents extends readon
18
18
  }): StreamChunk | null;
19
19
  protected getAllowedEvents(): TAllowedEvents | null;
20
20
  protected shouldProcessEvent(eventType: string): boolean;
21
- stream(params: {
22
- messages: Message[];
23
- conversationId?: string;
24
- signal?: AbortSignal;
25
- }): AsyncGenerator<StreamChunk, void, unknown>;
21
+ stream(params: StreamRequest): AsyncGenerator<StreamChunk, void, unknown>;
26
22
  private parseSSEStream;
27
23
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@harnessio/ai-chat-core",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "private": false,