@agentshouse/mdruntime-adapter 0.1.0-alpha.9 → 0.1.0-c023d3564cb7c

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 (69) hide show
  1. package/AGENTS.md +312 -74
  2. package/README.md +32 -0
  3. package/dist/actions.d.ts +57 -13
  4. package/dist/actions.d.ts.map +1 -1
  5. package/dist/actions.js +274 -397
  6. package/dist/adapter.d.ts +1 -0
  7. package/dist/adapter.d.ts.map +1 -1
  8. package/dist/adapter.js +525 -216
  9. package/dist/digest.js +1 -5
  10. package/dist/discovery.d.ts +27 -36
  11. package/dist/discovery.d.ts.map +1 -1
  12. package/dist/discovery.js +173 -228
  13. package/dist/gather.d.ts +4 -0
  14. package/dist/gather.d.ts.map +1 -0
  15. package/dist/gather.js +35 -0
  16. package/dist/index.d.ts +4 -2
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +3 -3
  19. package/dist/map.d.ts +2 -2
  20. package/dist/map.d.ts.map +1 -1
  21. package/dist/map.js +6 -7
  22. package/dist/model.d.ts +7 -18
  23. package/dist/model.d.ts.map +1 -1
  24. package/dist/model.js +60 -57
  25. package/dist/part.d.ts +15 -0
  26. package/dist/part.d.ts.map +1 -0
  27. package/dist/part.js +85 -0
  28. package/dist/read.d.ts +93 -35
  29. package/dist/read.d.ts.map +1 -1
  30. package/dist/read.js +415 -245
  31. package/dist/refusal.d.ts +5 -7
  32. package/dist/refusal.d.ts.map +1 -1
  33. package/dist/refusal.js +47 -68
  34. package/dist/room-types.d.ts +6 -0
  35. package/dist/room-types.d.ts.map +1 -0
  36. package/dist/room-types.js +66 -0
  37. package/dist/site.d.ts +1 -1
  38. package/dist/site.d.ts.map +1 -1
  39. package/dist/site.js +219 -161
  40. package/dist/stream.d.ts +18 -6
  41. package/dist/stream.d.ts.map +1 -1
  42. package/dist/stream.js +556 -214
  43. package/dist/transport.d.ts +131 -38
  44. package/dist/transport.d.ts.map +1 -1
  45. package/dist/transport.js +4 -3
  46. package/dist/upload.d.ts +12 -0
  47. package/dist/upload.d.ts.map +1 -0
  48. package/dist/upload.js +52 -0
  49. package/dist/version.d.ts +3 -0
  50. package/dist/version.d.ts.map +1 -1
  51. package/dist/version.js +32 -18
  52. package/dist/write.d.ts +18 -8
  53. package/dist/write.d.ts.map +1 -1
  54. package/dist/write.js +259 -228
  55. package/package.json +4 -13
  56. package/dist/actions.js.map +0 -1
  57. package/dist/adapter.js.map +0 -1
  58. package/dist/digest.js.map +0 -1
  59. package/dist/discovery.js.map +0 -1
  60. package/dist/index.js.map +0 -1
  61. package/dist/map.js.map +0 -1
  62. package/dist/model.js.map +0 -1
  63. package/dist/read.js.map +0 -1
  64. package/dist/refusal.js.map +0 -1
  65. package/dist/site.js.map +0 -1
  66. package/dist/stream.js.map +0 -1
  67. package/dist/transport.js.map +0 -1
  68. package/dist/version.js.map +0 -1
  69. package/dist/write.js.map +0 -1
package/dist/refusal.d.ts CHANGED
@@ -1,11 +1,9 @@
1
1
  import type { AdapterFailure, DiscoverResult, ProviderRefusal, ScopedRefusal } from '@agentshouse/mdruntime';
2
- export type DoorRefusal = ProviderRefusal;
3
- export declare function doorRefusal(body: unknown): DoorRefusal | null;
4
- export declare function scopedRefusal(locator: string, scope: ScopedRefusal['scope'], refusal: DoorRefusal): ScopedRefusal;
5
- export declare function classifyDoor(status: number, body: unknown, locator: string): AdapterFailure | {
2
+ export declare function doorRefusal(body: unknown): ProviderRefusal | null;
3
+ export declare function scopedRefusal(locator: string, scope: ScopedRefusal['scope'], refusal: ProviderRefusal): ScopedRefusal;
4
+ export declare function classifyDoor(status: number, body: unknown, locator: string): AdapterFailure | null;
5
+ export declare function classifyRead(status: number, body: unknown, locator: string): AdapterFailure | {
6
6
  kind: 'beyond-horizon';
7
7
  } | null;
8
- export declare function discoveryFailure(classified: AdapterFailure | {
9
- kind: 'beyond-horizon';
10
- }): DiscoverResult;
8
+ export declare function discoveryFailure(status: number, body: unknown): DiscoverResult | null;
11
9
  //# sourceMappingURL=refusal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"refusal.d.ts","sourceRoot":"","sources":["../src/refusal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,eAAe,EACf,aAAa,EACd,MAAM,wBAAwB,CAAC;AAgBhC,MAAM,MAAM,WAAW,GAAG,eAAe,CAAC;AAE1C,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,WAAW,GAAG,IAAI,CAO7D;AAED,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,EAC7B,OAAO,EAAE,WAAW,GACnB,aAAa,CAEf;AAED,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,MAAM,GACd,cAAc,GAAG;IAAE,IAAI,EAAE,gBAAgB,CAAA;CAAE,GAAG,IAAI,CAepD;AAED,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,cAAc,GAAG;IAAE,IAAI,EAAE,gBAAgB,CAAA;CAAE,GACtD,cAAc,CAMhB"}
1
+ {"version":3,"file":"refusal.d.ts","sourceRoot":"","sources":["../src/refusal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,eAAe,EACf,aAAa,EACd,MAAM,wBAAwB,CAAC;AAEhC,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAOjE;AAED,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,EAC7B,OAAO,EAAE,eAAe,GACvB,aAAa,CAEf;AAqBD,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,MAAM,GACd,cAAc,GAAG,IAAI,CAMvB;AAED,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,MAAM,GACd,cAAc,GAAG;IAAE,IAAI,EAAE,gBAAgB,CAAA;CAAE,GAAG,IAAI,CAGpD;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,cAAc,GAAG,IAAI,CAQrF"}
package/dist/refusal.js CHANGED
@@ -1,78 +1,57 @@
1
- const RETRYABLE_CODES = new Set([
2
- 'auth_unavailable',
3
- 'replica_behind',
4
- 'read_replica_unavailable',
5
- 'read_replica_lagging',
6
- 'read_pool_acquisition_timed_out',
7
- 'sync_unavailable',
8
- 'sync_failed',
9
- 'rate_limited',
10
- 'operation_contended',
11
- 'service_mode_write_halted',
12
- 'transaction_budget_exceeded'
13
- ]);
14
1
  export function doorRefusal(body) {
15
- if (typeof body !== 'object' || body === null) return null;
16
- if (!('error' in body) || typeof body.error !== 'object' || body.error === null) return null;
2
+ if (typeof body !== 'object' || body === null)
3
+ return null;
4
+ if (!('error' in body) || typeof body.error !== 'object' || body.error === null)
5
+ return null;
17
6
  const error = body.error;
18
- if (typeof error.code !== 'string') return null;
19
- const { code, ...fields } = error;
20
- return {
21
- code,
22
- fields
23
- };
7
+ if (typeof error.code !== 'string')
8
+ return null;
9
+ const { code, retryable, ...fields } = error;
10
+ return { code, fields, retryable: retryable === true };
24
11
  }
25
12
  export function scopedRefusal(locator, scope, refusal) {
26
- return {
27
- kind: 'scoped-refusal',
28
- locator,
29
- scope,
30
- code: refusal.code,
31
- fields: refusal.fields
32
- };
13
+ return { kind: 'scoped-refusal', locator, scope, ...refusal };
33
14
  }
34
- export function classifyDoor(status, body, locator) {
35
- if (status === 0) return {
36
- kind: 'transport-uncertainty'
37
- };
15
+ function doorFailure(status, body) {
16
+ if (status === 0)
17
+ return { kind: 'transport-uncertainty' };
38
18
  const refusal = doorRefusal(body);
39
- if (status === 401) return {
40
- kind: 'revoked-authorization'
41
- };
42
- if (refusal !== null && RETRYABLE_CODES.has(refusal.code)) return {
43
- kind: 'transport-uncertainty'
44
- };
45
- if (refusal !== null && refusal.code === 'position_expired') return {
46
- kind: 'beyond-horizon'
47
- };
48
- if (status === 404 || refusal?.code === 'room_not_found') {
49
- return {
50
- kind: 'room-not-readable',
51
- locator
52
- };
19
+ if (status === 401)
20
+ return { kind: 'revoked-authorization' };
21
+ if (refusal?.retryable === true || refusal?.code === 'update_required') {
22
+ return { kind: 'transport-uncertainty' };
53
23
  }
54
- if (status >= 500) return {
55
- kind: 'transport-uncertainty'
56
- };
57
- if (status < 400) return null;
58
- if (refusal === null) return {
59
- kind: 'transport-uncertainty'
60
- };
61
- if (status === 403) return scopedRefusal(locator, 'operation', refusal);
62
- return scopedRefusal(locator, 'undisclosed', refusal);
24
+ if (status === 404 || refusal?.code === 'room_not_found')
25
+ return { kind: 'room-not-readable' };
26
+ if (status < 400)
27
+ return null;
28
+ if (refusal === null)
29
+ return { kind: 'transport-uncertainty' };
30
+ return { kind: 'refused', scope: status === 403 ? 'operation' : 'undisclosed', refusal };
31
+ }
32
+ export function classifyDoor(status, body, locator) {
33
+ const failure = doorFailure(status, body);
34
+ if (failure === null)
35
+ return null;
36
+ if (failure.kind === 'room-not-readable')
37
+ return { kind: 'room-not-readable', locator };
38
+ if (failure.kind === 'refused')
39
+ return scopedRefusal(locator, failure.scope, failure.refusal);
40
+ return failure;
41
+ }
42
+ export function classifyRead(status, body, locator) {
43
+ if (doorRefusal(body)?.code === 'expired')
44
+ return { kind: 'beyond-horizon' };
45
+ return classifyDoor(status, body, locator);
63
46
  }
64
- export function discoveryFailure(classified) {
65
- if (classified.kind === 'revoked-authorization') return classified;
66
- if (classified.kind === 'scoped-refusal') {
67
- return {
68
- kind: 'contract-unavailable',
69
- code: classified.code,
70
- fields: classified.fields
71
- };
47
+ export function discoveryFailure(status, body) {
48
+ const failure = doorFailure(status, body);
49
+ if (failure === null)
50
+ return null;
51
+ if (failure.kind === 'revoked-authorization')
52
+ return failure;
53
+ if (failure.kind === 'refused') {
54
+ return { kind: 'contract-unavailable', ...failure.refusal };
72
55
  }
73
- return {
74
- kind: 'transport-uncertainty'
75
- };
56
+ return { kind: 'transport-uncertainty' };
76
57
  }
77
-
78
- //# sourceMappingURL=refusal.js.map
@@ -0,0 +1,6 @@
1
+ export declare const INBOX_CHANNEL_KINDS: readonly ['telegram-bot'];
2
+ export type InboxChannelKind = (typeof INBOX_CHANNEL_KINDS)[number];
3
+ export declare const INBOX_CHAT_TYPE = "inbox-chat";
4
+ export declare const INBOX_MESSAGE_TYPE = "inbox-message";
5
+ export declare const HOUSE_ROOM_TYPES: string;
6
+ //# sourceMappingURL=room-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"room-types.d.ts","sourceRoot":"","sources":["../src/room-types.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,YAAI,cAAc,CAAU,CAAC;AAE7D,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEpE,eAAO,MAAM,eAAe,eAAe,CAAC;AAE5C,eAAO,MAAM,kBAAkB,kBAAkB,CAAC;AAalD,eAAO,MAAM,gBAAgB,QAsDjB,CAAC"}
@@ -0,0 +1,66 @@
1
+ export const INBOX_CHANNEL_KINDS = ['telegram-bot'];
2
+ export const INBOX_CHAT_TYPE = 'inbox-chat';
3
+ export const INBOX_MESSAGE_TYPE = 'inbox-message';
4
+ const IDENTITY = "{ type: string, pattern: '^\\S+$' }";
5
+ const AGENT = [' agent: { type: string, format: uuid }', ' name: { type: string }'];
6
+ const ASSIGNEE = [
7
+ ' type: object',
8
+ ' properties:',
9
+ ' user: { type: string, format: uuid }',
10
+ ...AGENT,
11
+ ];
12
+ export const HOUSE_ROOM_TYPES = [
13
+ `${INBOX_CHAT_TYPE}:`,
14
+ ' properties:',
15
+ ' inbox: { type: string, format: uuid }',
16
+ ` channel: { enum: [${INBOX_CHANNEL_KINDS.join(', ')}] }`,
17
+ ` chat: ${IDENTITY}`,
18
+ ' customer:',
19
+ ' type: object',
20
+ ' properties:',
21
+ ' name: { type: string }',
22
+ ` username: ${IDENTITY}`,
23
+ ` phone: ${IDENTITY}`,
24
+ ' assignee:',
25
+ ...ASSIGNEE,
26
+ ' return_to:',
27
+ ' type: object',
28
+ ' properties:',
29
+ ...AGENT,
30
+ ' conversation: { type: string, format: uuid }',
31
+ ' required: [inbox, channel, chat, customer]',
32
+ `${INBOX_MESSAGE_TYPE}:`,
33
+ ' properties:',
34
+ ' direction: { enum: [in, out] }',
35
+ ' sender:',
36
+ ' type: object',
37
+ ' properties:',
38
+ ' name: { type: string }',
39
+ ` username: ${IDENTITY}`,
40
+ ' sent_at: { type: string, format: date-time }',
41
+ ` channel_message: ${IDENTITY}`,
42
+ ' state: { enum: [sending, sent, failed] }',
43
+ ' reason: { type: string }',
44
+ ' reactions:',
45
+ ' type: array',
46
+ ' items:',
47
+ ' type: object',
48
+ ' properties:',
49
+ ' reaction: { type: string, minLength: 1 }',
50
+ ' sender:',
51
+ ' type: object',
52
+ ' properties:',
53
+ ` id: ${IDENTITY}`,
54
+ ' name: { type: string }',
55
+ ` username: ${IDENTITY}`,
56
+ ' count: { type: integer, minimum: 1 }',
57
+ ' required: [reaction]',
58
+ ` post: ${IDENTITY}`,
59
+ ' assignee:',
60
+ ...ASSIGNEE,
61
+ ' sent_outside: { const: true }',
62
+ ' required: [direction]',
63
+ ' if: { properties: { direction: { const: in } } }',
64
+ ' then: { required: [sent_at] }',
65
+ '',
66
+ ].join('\n');
package/dist/site.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import type { Adapter } from '@agentshouse/mdruntime';
2
2
  import { type HouseSiteTransport } from './transport.js';
3
- export declare function createSiteAdapter(transport: HouseSiteTransport): Adapter;
3
+ export declare function createSiteAdapter(transport: HouseSiteTransport, snapshot?: boolean): Adapter;
4
4
  //# sourceMappingURL=site.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../src/site.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAOR,MAAM,wBAAwB,CAAC;AA8BhC,OAAO,EAKL,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AAgCxB,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,kBAAkB,GAAG,OAAO,CAuIxE"}
1
+ {"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../src/site.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAWR,MAAM,wBAAwB,CAAC;AA+BhC,OAAO,EAML,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AAoCxB,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,kBAAkB,EAAE,QAAQ,UAAQ,GAAG,OAAO,CAoP1F"}