@agentick/angular 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Agentick Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # @agentick/angular
2
+
3
+ Angular integration for Agentick. Provides a signal-first service wrapper around `@agentick/client`.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @agentick/angular
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```ts
14
+ import { Component, inject } from "@angular/core";
15
+ import { AgentickService, provideAgentick } from "@agentick/angular";
16
+
17
+ @Component({
18
+ selector: "app-chat",
19
+ providers: [provideAgentick({ baseUrl: "/api/agent" })],
20
+ template: `
21
+ <div>{{ agentick.text() }}</div>
22
+ <button (click)="send('Hello')">Send</button>
23
+ `,
24
+ })
25
+ export class ChatComponent {
26
+ agentick = inject(AgentickService);
27
+
28
+ constructor() {
29
+ this.agentick.subscribe("conv-123");
30
+ }
31
+
32
+ async send(message: string) {
33
+ const handle = this.agentick.send(message);
34
+ await handle.result;
35
+ }
36
+ }
37
+ ```
38
+
39
+ ## Service API
40
+
41
+ ```ts
42
+ service.session(sessionId) // cold accessor
43
+ service.subscribe(sessionId) // hot accessor
44
+ service.unsubscribe() // drop current subscription
45
+
46
+ service.send(input) // returns ClientExecutionHandle
47
+ service.abort(reason?)
48
+ service.close()
49
+
50
+ service.channel(name) // session-scoped channel
51
+ ```
52
+
53
+ Signals:
54
+
55
+ ```ts
56
+ service.connectionState()
57
+ service.sessionId()
58
+ service.streamingText()
59
+ service.text()
60
+ service.isStreaming()
61
+ ```
@@ -0,0 +1,210 @@
1
+ /**
2
+ * AgentickService - Modern Angular service for Agentick.
3
+ *
4
+ * Uses Angular signals for reactive state management with RxJS interop.
5
+ *
6
+ * @module @agentick/angular/service
7
+ */
8
+ import { InjectionToken, type OnDestroy } from "@angular/core";
9
+ import { Observable } from "rxjs";
10
+ import { type AgentickClient, type ConnectionState, type StreamEvent, type StreamingTextState, type SessionStreamEvent, type SessionAccessor, type ClientExecutionHandle } from "@agentick/client";
11
+ import type { AgentickConfig } from "./types";
12
+ /**
13
+ * Injection token for Agentick configuration.
14
+ */
15
+ export declare const TENTICKLE_CONFIG: InjectionToken<AgentickConfig>;
16
+ /**
17
+ * Provides AgentickService with configuration at component level.
18
+ *
19
+ * Use this to create isolated service instances for different components,
20
+ * each with their own connection and state.
21
+ *
22
+ * @example Multiple agents in one app
23
+ * ```typescript
24
+ * // Each component gets its own AgentickService instance
25
+ *
26
+ * @Component({
27
+ * selector: 'app-support-chat',
28
+ * providers: [provideAgentick({ baseUrl: '/api/support-agent' })],
29
+ * template: `<div>{{ agentick.text() }}</div>`,
30
+ * })
31
+ * export class SupportChatComponent {
32
+ * agentick = inject(AgentickService);
33
+ * }
34
+ *
35
+ * @Component({
36
+ * selector: 'app-sales-chat',
37
+ * providers: [provideAgentick({ baseUrl: '/api/sales-agent' })],
38
+ * template: `<div>{{ agentick.text() }}</div>`,
39
+ * })
40
+ * export class SalesChatComponent {
41
+ * agentick = inject(AgentickService);
42
+ * }
43
+ * ```
44
+ *
45
+ * @param config - Configuration for this service instance
46
+ * @returns Provider array to spread into component's providers
47
+ */
48
+ export declare function provideAgentick(config: AgentickConfig): (typeof AgentickService | {
49
+ provide: InjectionToken<AgentickConfig>;
50
+ useValue: AgentickConfig;
51
+ })[];
52
+ /**
53
+ * Modern Angular service for Agentick.
54
+ *
55
+ * Uses signals for state, with RxJS observables available for compatibility.
56
+ *
57
+ * @example Standalone setup
58
+ * ```typescript
59
+ * import { AgentickService, TENTICKLE_CONFIG } from '@agentick/angular';
60
+ *
61
+ * bootstrapApplication(AppComponent, {
62
+ * providers: [
63
+ * { provide: TENTICKLE_CONFIG, useValue: { baseUrl: 'https://api.example.com' } },
64
+ * ],
65
+ * });
66
+ * ```
67
+ *
68
+ * @example Component with signals
69
+ * ```typescript
70
+ * @Component({
71
+ * template: `
72
+ * @if (agentick.isConnected()) {
73
+ * <div class="response">
74
+ * {{ agentick.text() }}
75
+ * @if (agentick.isStreaming()) {
76
+ * <span class="cursor">|</span>
77
+ * }
78
+ * </div>
79
+ * <input #input />
80
+ * <button (click)="send(input.value)">Send</button>
81
+ * } @else {
82
+ * <p>Connecting...</p>
83
+ * }
84
+ * `,
85
+ * })
86
+ * export class ChatComponent {
87
+ * agentick = inject(AgentickService);
88
+ *
89
+ * constructor() {
90
+ * this.agentick.subscribe("conv-123");
91
+ * }
92
+ *
93
+ * async send(message: string) {
94
+ * const handle = this.agentick.send(message);
95
+ * await handle.result;
96
+ * }
97
+ * }
98
+ * ```
99
+ *
100
+ * @example With RxJS (for compatibility)
101
+ * ```typescript
102
+ * @Component({
103
+ * template: `{{ text$ | async }}`,
104
+ * })
105
+ * export class LegacyComponent {
106
+ * agentick = inject(AgentickService);
107
+ * text$ = this.agentick.text$;
108
+ * }
109
+ * ```
110
+ */
111
+ export declare class AgentickService implements OnDestroy {
112
+ private readonly client;
113
+ private readonly destroy$;
114
+ private currentSession?;
115
+ /** Current connection state */
116
+ readonly connectionState: import("@angular/core").WritableSignal<ConnectionState>;
117
+ /** Current session ID */
118
+ readonly sessionId: import("@angular/core").WritableSignal<string | undefined>;
119
+ /** Connection error, if any */
120
+ readonly error: import("@angular/core").WritableSignal<Error | undefined>;
121
+ /** Streaming text state from the client */
122
+ readonly streamingText: import("@angular/core").WritableSignal<StreamingTextState>;
123
+ /** Whether currently connected */
124
+ readonly isConnected: import("@angular/core").Signal<boolean>;
125
+ /** Whether currently connecting */
126
+ readonly isConnecting: import("@angular/core").Signal<boolean>;
127
+ /** Current streaming text */
128
+ readonly text: import("@angular/core").Signal<string>;
129
+ /** Whether currently streaming */
130
+ readonly isStreaming: import("@angular/core").Signal<boolean>;
131
+ /** Observable of connection state (for RxJS users) */
132
+ readonly connectionState$: Observable<ConnectionState>;
133
+ /** Observable of whether connected (for RxJS users) */
134
+ readonly isConnected$: Observable<boolean>;
135
+ /** Observable of streaming text state (for RxJS users) */
136
+ readonly streamingText$: Observable<StreamingTextState>;
137
+ /** Observable of just the text (for RxJS users) */
138
+ readonly text$: Observable<string>;
139
+ /** Observable of whether streaming (for RxJS users) */
140
+ readonly isStreaming$: Observable<boolean>;
141
+ /** Subject for raw stream events */
142
+ private readonly eventsSubject;
143
+ /** Observable of all stream events */
144
+ readonly events$: Observable<StreamEvent | SessionStreamEvent>;
145
+ /** Subject for execution results */
146
+ private readonly resultSubject;
147
+ /** Observable of execution results */
148
+ readonly result$: Observable<{
149
+ response: string;
150
+ outputs: Record<string, unknown>;
151
+ usage: {
152
+ inputTokens: number;
153
+ outputTokens: number;
154
+ totalTokens: number;
155
+ };
156
+ stopReason?: string;
157
+ }>;
158
+ /**
159
+ * Creates a new AgentickService.
160
+ *
161
+ * @param configOrInjected - Config passed directly (for testing) or undefined to use DI
162
+ */
163
+ constructor(configOrInjected?: AgentickConfig);
164
+ private setupSubscriptions;
165
+ /**
166
+ * Get a cold session accessor.
167
+ */
168
+ session(sessionId: string): SessionAccessor;
169
+ /**
170
+ * Subscribe to a session and make it the active session.
171
+ */
172
+ subscribe(sessionId: string): SessionAccessor;
173
+ /**
174
+ * Unsubscribe from the active session.
175
+ */
176
+ unsubscribe(): void;
177
+ /**
178
+ * Send a message to the session.
179
+ */
180
+ send(input: Parameters<AgentickClient["send"]>[0]): ClientExecutionHandle;
181
+ /**
182
+ * Abort the current execution.
183
+ */
184
+ abort(reason?: string): Promise<void>;
185
+ /**
186
+ * Close the active session on the server.
187
+ */
188
+ close(): Promise<void>;
189
+ /**
190
+ * Clear the accumulated streaming text.
191
+ */
192
+ clearStreamingText(): void;
193
+ /**
194
+ * Get a channel accessor for custom pub/sub.
195
+ */
196
+ channel(name: string): import("@agentick/client").ChannelAccessor;
197
+ /**
198
+ * Create an Observable from a channel.
199
+ */
200
+ channel$(name: string): Observable<{
201
+ type: string;
202
+ payload: unknown;
203
+ }>;
204
+ /**
205
+ * Filter events by type.
206
+ */
207
+ eventsOfType(...types: StreamEvent["type"][]): Observable<StreamEvent>;
208
+ ngOnDestroy(): void;
209
+ }
210
+ //# sourceMappingURL=agentick.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agentick.service.d.ts","sourceRoot":"","sources":["../src/agentick.service.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAEL,cAAc,EACd,KAAK,SAAS,EAIf,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,UAAU,EAA8B,MAAM,MAAM,CAAC;AAC9D,OAAO,EAEL,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC3B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KA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W,IAAI,IAAI;CAKpB"}
@@ -0,0 +1,354 @@
1
+ /**
2
+ * AgentickService - Modern Angular service for Agentick.
3
+ *
4
+ * Uses Angular signals for reactive state management with RxJS interop.
5
+ *
6
+ * @module @agentick/angular/service
7
+ */
8
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
9
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
10
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
11
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
12
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
13
+ };
14
+ var __metadata = (this && this.__metadata) || function (k, v) {
15
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
16
+ };
17
+ import { Injectable, InjectionToken, computed, signal, inject, } from "@angular/core";
18
+ import { toObservable } from "@angular/core/rxjs-interop";
19
+ import { Observable, Subject, filter, takeUntil } from "rxjs";
20
+ import { createClient, } from "@agentick/client";
21
+ /**
22
+ * Injection token for Agentick configuration.
23
+ */
24
+ export const TENTICKLE_CONFIG = new InjectionToken("TENTICKLE_CONFIG");
25
+ /**
26
+ * Provides AgentickService with configuration at component level.
27
+ *
28
+ * Use this to create isolated service instances for different components,
29
+ * each with their own connection and state.
30
+ *
31
+ * @example Multiple agents in one app
32
+ * ```typescript
33
+ * // Each component gets its own AgentickService instance
34
+ *
35
+ * @Component({
36
+ * selector: 'app-support-chat',
37
+ * providers: [provideAgentick({ baseUrl: '/api/support-agent' })],
38
+ * template: `<div>{{ agentick.text() }}</div>`,
39
+ * })
40
+ * export class SupportChatComponent {
41
+ * agentick = inject(AgentickService);
42
+ * }
43
+ *
44
+ * @Component({
45
+ * selector: 'app-sales-chat',
46
+ * providers: [provideAgentick({ baseUrl: '/api/sales-agent' })],
47
+ * template: `<div>{{ agentick.text() }}</div>`,
48
+ * })
49
+ * export class SalesChatComponent {
50
+ * agentick = inject(AgentickService);
51
+ * }
52
+ * ```
53
+ *
54
+ * @param config - Configuration for this service instance
55
+ * @returns Provider array to spread into component's providers
56
+ */
57
+ export function provideAgentick(config) {
58
+ return [{ provide: TENTICKLE_CONFIG, useValue: config }, AgentickService];
59
+ }
60
+ /**
61
+ * Modern Angular service for Agentick.
62
+ *
63
+ * Uses signals for state, with RxJS observables available for compatibility.
64
+ *
65
+ * @example Standalone setup
66
+ * ```typescript
67
+ * import { AgentickService, TENTICKLE_CONFIG } from '@agentick/angular';
68
+ *
69
+ * bootstrapApplication(AppComponent, {
70
+ * providers: [
71
+ * { provide: TENTICKLE_CONFIG, useValue: { baseUrl: 'https://api.example.com' } },
72
+ * ],
73
+ * });
74
+ * ```
75
+ *
76
+ * @example Component with signals
77
+ * ```typescript
78
+ * @Component({
79
+ * template: `
80
+ * @if (agentick.isConnected()) {
81
+ * <div class="response">
82
+ * {{ agentick.text() }}
83
+ * @if (agentick.isStreaming()) {
84
+ * <span class="cursor">|</span>
85
+ * }
86
+ * </div>
87
+ * <input #input />
88
+ * <button (click)="send(input.value)">Send</button>
89
+ * } @else {
90
+ * <p>Connecting...</p>
91
+ * }
92
+ * `,
93
+ * })
94
+ * export class ChatComponent {
95
+ * agentick = inject(AgentickService);
96
+ *
97
+ * constructor() {
98
+ * this.agentick.subscribe("conv-123");
99
+ * }
100
+ *
101
+ * async send(message: string) {
102
+ * const handle = this.agentick.send(message);
103
+ * await handle.result;
104
+ * }
105
+ * }
106
+ * ```
107
+ *
108
+ * @example With RxJS (for compatibility)
109
+ * ```typescript
110
+ * @Component({
111
+ * template: `{{ text$ | async }}`,
112
+ * })
113
+ * export class LegacyComponent {
114
+ * agentick = inject(AgentickService);
115
+ * text$ = this.agentick.text$;
116
+ * }
117
+ * ```
118
+ */
119
+ let AgentickService = class AgentickService {
120
+ // ══════════════════════════════════════════════════════════════════════════
121
+ // Constructor
122
+ // ══════════════════════════════════════════════════════════════════════════
123
+ /**
124
+ * Creates a new AgentickService.
125
+ *
126
+ * @param configOrInjected - Config passed directly (for testing) or undefined to use DI
127
+ */
128
+ constructor(configOrInjected) {
129
+ this.destroy$ = new Subject();
130
+ // ══════════════════════════════════════════════════════════════════════════
131
+ // Signals - Primary State
132
+ // ══════════════════════════════════════════════════════════════════════════
133
+ /** Current connection state */
134
+ this.connectionState = signal("disconnected");
135
+ /** Current session ID */
136
+ this.sessionId = signal(undefined);
137
+ /** Connection error, if any */
138
+ this.error = signal(undefined);
139
+ /** Streaming text state from the client */
140
+ this.streamingText = signal({ text: "", isStreaming: false });
141
+ // ══════════════════════════════════════════════════════════════════════════
142
+ // Computed Signals - Derived State
143
+ // ══════════════════════════════════════════════════════════════════════════
144
+ /** Whether currently connected */
145
+ this.isConnected = computed(() => this.connectionState() === "connected");
146
+ /** Whether currently connecting */
147
+ this.isConnecting = computed(() => this.connectionState() === "connecting");
148
+ /** Current streaming text */
149
+ this.text = computed(() => this.streamingText().text);
150
+ /** Whether currently streaming */
151
+ this.isStreaming = computed(() => this.streamingText().isStreaming);
152
+ /** Subject for raw stream events */
153
+ this.eventsSubject = new Subject();
154
+ /** Observable of all stream events */
155
+ this.events$ = this.eventsSubject.asObservable();
156
+ /** Subject for execution results */
157
+ this.resultSubject = new Subject();
158
+ /** Observable of execution results */
159
+ this.result$ = this.resultSubject.asObservable();
160
+ // Support both direct config (for testing) and DI injection
161
+ let config = configOrInjected;
162
+ if (!config) {
163
+ try {
164
+ config = inject(TENTICKLE_CONFIG, { optional: true }) ?? undefined;
165
+ }
166
+ catch {
167
+ // Not in injection context - config must be passed directly
168
+ }
169
+ }
170
+ if (!config) {
171
+ throw new Error("AgentickService requires TENTICKLE_CONFIG to be provided");
172
+ }
173
+ this.client = createClient(config);
174
+ // Initialize observables from signals
175
+ // Note: toObservable requires injection context, so we create them conditionally
176
+ try {
177
+ this.connectionState$ = toObservable(this.connectionState);
178
+ this.isConnected$ = toObservable(this.isConnected);
179
+ this.streamingText$ = toObservable(this.streamingText);
180
+ this.text$ = toObservable(this.text);
181
+ this.isStreaming$ = toObservable(this.isStreaming);
182
+ }
183
+ catch {
184
+ // Not in injection context - create manual observables for testing
185
+ this.connectionState$ = new Observable((subscriber) => {
186
+ subscriber.next(this.connectionState());
187
+ const interval = setInterval(() => {
188
+ subscriber.next(this.connectionState());
189
+ }, 10);
190
+ return () => clearInterval(interval);
191
+ });
192
+ this.isConnected$ = new Observable((subscriber) => {
193
+ subscriber.next(this.isConnected());
194
+ const interval = setInterval(() => {
195
+ subscriber.next(this.isConnected());
196
+ }, 10);
197
+ return () => clearInterval(interval);
198
+ });
199
+ this.streamingText$ = new Observable((subscriber) => {
200
+ subscriber.next(this.streamingText());
201
+ const interval = setInterval(() => {
202
+ subscriber.next(this.streamingText());
203
+ }, 10);
204
+ return () => clearInterval(interval);
205
+ });
206
+ this.text$ = new Observable((subscriber) => {
207
+ subscriber.next(this.text());
208
+ const interval = setInterval(() => {
209
+ subscriber.next(this.text());
210
+ }, 10);
211
+ return () => clearInterval(interval);
212
+ });
213
+ this.isStreaming$ = new Observable((subscriber) => {
214
+ subscriber.next(this.isStreaming());
215
+ const interval = setInterval(() => {
216
+ subscriber.next(this.isStreaming());
217
+ }, 10);
218
+ return () => clearInterval(interval);
219
+ });
220
+ }
221
+ this.setupSubscriptions();
222
+ }
223
+ setupSubscriptions() {
224
+ // Connection state → signal
225
+ this.client.onConnectionChange((state) => {
226
+ this.connectionState.set(state);
227
+ });
228
+ // Streaming text → signal
229
+ this.client.onStreamingText((state) => {
230
+ this.streamingText.set(state);
231
+ });
232
+ // Events → subject (for filtering)
233
+ this.client.onEvent((event) => {
234
+ this.eventsSubject.next(event);
235
+ });
236
+ // Results → subject
237
+ this.client.onEvent((event) => {
238
+ if (event.type === "result") {
239
+ this.resultSubject.next(event.result);
240
+ }
241
+ });
242
+ }
243
+ // ══════════════════════════════════════════════════════════════════════════
244
+ // Session Access
245
+ // ══════════════════════════════════════════════════════════════════════════
246
+ /**
247
+ * Get a cold session accessor.
248
+ */
249
+ session(sessionId) {
250
+ return this.client.session(sessionId);
251
+ }
252
+ /**
253
+ * Subscribe to a session and make it the active session.
254
+ */
255
+ subscribe(sessionId) {
256
+ const accessor = this.client.subscribe(sessionId);
257
+ this.currentSession = accessor;
258
+ this.sessionId.set(sessionId);
259
+ return accessor;
260
+ }
261
+ /**
262
+ * Unsubscribe from the active session.
263
+ */
264
+ unsubscribe() {
265
+ this.currentSession?.unsubscribe();
266
+ this.currentSession = undefined;
267
+ this.sessionId.set(undefined);
268
+ }
269
+ // ══════════════════════════════════════════════════════════════════════════
270
+ // Messaging
271
+ // ══════════════════════════════════════════════════════════════════════════
272
+ /**
273
+ * Send a message to the session.
274
+ */
275
+ send(input) {
276
+ if (this.currentSession) {
277
+ return this.currentSession.send(input);
278
+ }
279
+ return this.client.send(input);
280
+ }
281
+ /**
282
+ * Abort the current execution.
283
+ */
284
+ async abort(reason) {
285
+ if (this.currentSession) {
286
+ await this.currentSession.abort(reason);
287
+ return;
288
+ }
289
+ const id = this.sessionId();
290
+ if (id) {
291
+ await this.client.abort(id, reason);
292
+ }
293
+ }
294
+ /**
295
+ * Close the active session on the server.
296
+ */
297
+ async close() {
298
+ if (this.currentSession) {
299
+ await this.currentSession.close();
300
+ this.currentSession = undefined;
301
+ this.sessionId.set(undefined);
302
+ }
303
+ }
304
+ /**
305
+ * Clear the accumulated streaming text.
306
+ */
307
+ clearStreamingText() {
308
+ this.client.clearStreamingText();
309
+ }
310
+ // ══════════════════════════════════════════════════════════════════════════
311
+ // Channels
312
+ // ══════════════════════════════════════════════════════════════════════════
313
+ /**
314
+ * Get a channel accessor for custom pub/sub.
315
+ */
316
+ channel(name) {
317
+ if (!this.currentSession) {
318
+ throw new Error("No active session. Call subscribe(sessionId) first.");
319
+ }
320
+ return this.currentSession.channel(name);
321
+ }
322
+ /**
323
+ * Create an Observable from a channel.
324
+ */
325
+ channel$(name) {
326
+ return new Observable((subscriber) => {
327
+ const channel = this.channel(name);
328
+ const unsubscribe = channel.subscribe((payload, event) => {
329
+ subscriber.next({ type: event.type, payload });
330
+ });
331
+ return () => unsubscribe();
332
+ }).pipe(takeUntil(this.destroy$));
333
+ }
334
+ /**
335
+ * Filter events by type.
336
+ */
337
+ eventsOfType(...types) {
338
+ return this.events$.pipe(filter((event) => types.includes(event.type)));
339
+ }
340
+ // ══════════════════════════════════════════════════════════════════════════
341
+ // Cleanup
342
+ // ══════════════════════════════════════════════════════════════════════════
343
+ ngOnDestroy() {
344
+ this.destroy$.next();
345
+ this.destroy$.complete();
346
+ this.client.destroy();
347
+ }
348
+ };
349
+ AgentickService = __decorate([
350
+ Injectable({ providedIn: "root" }),
351
+ __metadata("design:paramtypes", [Object])
352
+ ], AgentickService);
353
+ export { AgentickService };
354
+ //# sourceMappingURL=agentick.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agentick.service.js","sourceRoot":"","sources":["../src/agentick.service.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;;;;;;;;;;AAEH,OAAO,EACL,UAAU,EACV,cAAc,EAEd,QAAQ,EACR,MAAM,EACN,MAAM,GACP,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAC9D,OAAO,EACL,YAAY,GAQb,MAAM,kBAAkB,CAAC;AAG1B;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,cAAc,CAAiB,kBAAkB,CAAC,CAAC;AAEvF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,eAAe,CAAC,MAAsB;IACpD,OAAO,CAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,eAAe,CAAC,CAAC;AAC5E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