@olane/o-login 0.8.3 → 0.8.5

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 (2) hide show
  1. package/README.md +65 -22
  2. package/package.json +7 -7
package/README.md CHANGED
@@ -13,7 +13,7 @@
13
13
  ### Installation
14
14
 
15
15
  ```bash
16
- npm install @olane/o-login
16
+ pnpm install @olane/o-login
17
17
  ```
18
18
 
19
19
  ### Minimal Example: Human Agent Login
@@ -139,8 +139,8 @@ new oHumanLoginTool(config: oLoginConfig)
139
139
  - **Signature**: `(data: any) => Promise<any>`
140
140
  - **Returns**: Processing result (optional)
141
141
  - `address` (oNodeAddress, optional): Custom address (default: `o://human`)
142
- - `leader` (oAddress, optional): Leader node address for network registration
143
- - `parent` (oAddress, optional): Parent node address
142
+ - `leader` (oNodeAddress, optional): Leader node address for network registration
143
+ - `parent` (oNodeAddress, optional): Parent node address
144
144
 
145
145
  **Example**:
146
146
  ```typescript
@@ -265,7 +265,7 @@ Handles intent-based requests.
265
265
  **Parameters**:
266
266
  - `intent` (string, required): The intent to resolve
267
267
 
268
- **Returns**:
268
+ **Returns** (raw data from the tool method):
269
269
  ```typescript
270
270
  {
271
271
  success: boolean;
@@ -273,18 +273,22 @@ Handles intent-based requests.
273
273
  }
274
274
  ```
275
275
 
276
+ > **Note**: When calling via `node.use()`, the raw return value is wrapped by the base class. Access it via `response.result.data`.
277
+
276
278
  **Example Usage** (from another node):
277
279
  ```typescript
278
280
  // Another node sends an intent to the human agent
279
- const result = await humanAgent.use({
281
+ const response = await humanAgent.use(humanAgent.address, {
280
282
  method: 'intent',
281
283
  params: {
282
284
  intent: 'Please approve the budget request for Q4'
283
285
  }
284
286
  });
285
287
 
286
- console.log(result.resolution);
287
- // "Request approved" (based on your respond callback)
288
+ if (response.result.success) {
289
+ console.log(response.result.data.resolution);
290
+ // "Request approved" (based on your respond callback)
291
+ }
288
292
  ```
289
293
 
290
294
  ---
@@ -296,7 +300,7 @@ Handles question-answer requests.
296
300
  **Parameters**:
297
301
  - `question` (string, required): The question to answer
298
302
 
299
- **Returns**:
303
+ **Returns** (raw data from the tool method):
300
304
  ```typescript
301
305
  {
302
306
  success: boolean;
@@ -304,18 +308,22 @@ Handles question-answer requests.
304
308
  }
305
309
  ```
306
310
 
311
+ > **Note**: When calling via `node.use()`, the raw return value is wrapped by the base class. Access it via `response.result.data`.
312
+
307
313
  **Example Usage** (from another node):
308
314
  ```typescript
309
315
  // Another node asks a question
310
- const result = await aiAgent.use({
316
+ const response = await aiAgent.use(aiAgent.address, {
311
317
  method: 'question',
312
318
  params: {
313
319
  question: 'What is the capital of France?'
314
320
  }
315
321
  });
316
322
 
317
- console.log(result.answer);
318
- // "Paris" (based on your answer callback)
323
+ if (response.result.success) {
324
+ console.log(response.result.data.answer);
325
+ // "Paris" (based on your answer callback)
326
+ }
319
327
  ```
320
328
 
321
329
  ---
@@ -327,26 +335,57 @@ Handles streamed data.
327
335
  **Parameters**:
328
336
  - `data` (any, required): The data to process
329
337
 
330
- **Returns**:
338
+ **Returns** (raw data from the tool method):
331
339
  ```typescript
332
340
  {
333
341
  success: boolean;
334
342
  }
335
343
  ```
336
344
 
345
+ > **Note**: When calling via `node.use()`, the raw return value is wrapped by the base class. Access it via `response.result.data`.
346
+
337
347
  **Example Usage** (from another node):
338
348
  ```typescript
339
349
  // Another node streams data
340
- await humanAgent.use({
350
+ const response = await humanAgent.use(humanAgent.address, {
341
351
  method: 'receive_stream',
342
352
  params: {
343
353
  data: { type: 'notification', message: 'System update available' }
344
354
  }
345
355
  });
356
+
357
+ if (response.result.success) {
358
+ console.log('Stream data delivered successfully');
359
+ }
346
360
  ```
347
361
 
348
362
  ---
349
363
 
364
+ ## Response Structure {#response-structure}
365
+
366
+ When calling login tools via `node.use()`, responses follow the standard Olane response structure:
367
+
368
+ ```typescript
369
+ const response = await node.use(
370
+ new oNodeAddress('o://human'),
371
+ { method: 'intent', params: { intent: 'Approve the request' } }
372
+ );
373
+
374
+ // response.result.success - boolean indicating success or failure
375
+ // response.result.data - the return value on success
376
+ // response.result.error - error message on failure
377
+
378
+ if (response.result.success) {
379
+ console.log('Resolution:', response.result.data.resolution);
380
+ } else {
381
+ console.error('Error:', response.result.error);
382
+ }
383
+ ```
384
+
385
+ > **Important**: Never access `response.success` or `response.data` directly. Always use `response.result.success` and `response.result.data`.
386
+
387
+ ---
388
+
350
389
  ## Common Use Cases {#common-use-cases}
351
390
 
352
391
  ### Use Case 1: Human-in-the-Loop Approval System
@@ -478,11 +517,11 @@ const aiSupport = new oAILoginTool({
478
517
  // Check if AI can handle this
479
518
  if (intent.includes('complex') || intent.includes('escalate')) {
480
519
  // Forward to human
481
- const humanResult = await humanSupport.use({
520
+ const humanResponse = await humanSupport.use(humanSupport.address, {
482
521
  method: 'intent',
483
522
  params: { intent }
484
523
  });
485
- return `Escalated to human: ${humanResult.resolution}`;
524
+ return `Escalated to human: ${humanResponse.result.data.resolution}`;
486
525
  }
487
526
 
488
527
  // AI handles routine intents
@@ -568,14 +607,16 @@ await taskProcessor.start();
568
607
  await humanWorker.start();
569
608
 
570
609
  // Task processor sends work to human
571
- const result = await humanWorker.use({
610
+ const response = await humanWorker.use(humanWorker.address, {
572
611
  method: 'intent',
573
612
  params: {
574
613
  intent: 'Review and approve the financial report'
575
614
  }
576
615
  });
577
616
 
578
- console.log('Result:', result.resolution);
617
+ if (response.result.success) {
618
+ console.log('Result:', response.result.data.resolution);
619
+ }
579
620
  ```
580
621
 
581
622
  ---
@@ -600,10 +641,10 @@ const agent = new oHumanLoginTool({
600
641
  Connect to a leader node for service discovery:
601
642
 
602
643
  ```typescript
603
- import { oAddress } from '@olane/o-core';
644
+ import { oNodeAddress } from '@olane/o-node';
604
645
 
605
646
  const agent = new oHumanLoginTool({
606
- leader: new oAddress('o://network/leader'),
647
+ leader: new oNodeAddress('o://network/leader'),
607
648
  respond: async (intent) => 'resolved',
608
649
  answer: async (question) => 'answered',
609
650
  receiveStream: async (data) => {}
@@ -636,11 +677,11 @@ const childAgent = new oAILoginTool({
636
677
  respond: async (intent) => {
637
678
  // Escalate to parent if needed
638
679
  if (intent.includes('urgent')) {
639
- const result = await parentAgent.use({
680
+ const parentResponse = await parentAgent.use(parentAgent.address, {
640
681
  method: 'intent',
641
682
  params: { intent }
642
683
  });
643
- return result.resolution;
684
+ return parentResponse.result.data.resolution;
644
685
  }
645
686
  return 'Assistant handled';
646
687
  },
@@ -679,6 +720,8 @@ console.log('Agent offline');
679
720
 
680
721
  ### Error Handling
681
722
 
723
+ > **Note**: The callback functions (`respond`, `answer`, `receiveStream`) are user-provided and follow a different pattern from `_tool_` methods. In `_tool_` methods, you should throw errors for failures and the base class handles wrapping. In callbacks, you may catch and handle errors as shown below, since the base class will wrap the callback's return value into the standard response structure (`response.result.success`, `response.result.data`, `response.result.error`).
724
+
682
725
  ```typescript
683
726
  const agent = new oHumanLoginTool({
684
727
  respond: async (intent: string) => {
@@ -763,7 +806,7 @@ const agent = new oHumanLoginTool({
763
806
 
764
807
  **Solution**: Install all peer dependencies:
765
808
  ```bash
766
- npm install @olane/o-core @olane/o-config @olane/o-protocol @olane/o-tool @olane/o-lane @olane/o-node
809
+ pnpm install @olane/o-core @olane/o-config @olane/o-protocol @olane/o-tool @olane/o-lane @olane/o-node
767
810
  ```
768
811
 
769
812
  ---
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@olane/o-login",
3
- "version": "0.8.3",
3
+ "version": "0.8.5",
4
4
  "type": "module",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
@@ -54,13 +54,13 @@
54
54
  "typescript": "5.4.5"
55
55
  },
56
56
  "dependencies": {
57
- "@olane/o-config": "0.8.3",
58
- "@olane/o-core": "0.8.3",
59
- "@olane/o-lane": "0.8.3",
60
- "@olane/o-protocol": "0.8.3",
61
- "@olane/o-tool": "0.8.3",
57
+ "@olane/o-config": "0.8.5",
58
+ "@olane/o-core": "0.8.5",
59
+ "@olane/o-lane": "0.8.5",
60
+ "@olane/o-protocol": "0.8.5",
61
+ "@olane/o-tool": "0.8.5",
62
62
  "debug": "^4.4.1",
63
63
  "dotenv": "^16.5.0"
64
64
  },
65
- "gitHead": "189c0cf7b6dd9d5d961f5424af21d37978092d9e"
65
+ "gitHead": "e88f1e55dcc92d9a410d28200e4220697116f82f"
66
66
  }