@haaaiawd/second-nature 0.1.43 → 0.1.51

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,137 +1,137 @@
1
- const PLATFORM_ARRAY_KEYS = [
2
- "posts",
3
- "nodes",
4
- "agents",
5
- "edges",
6
- "results",
7
- "entries",
8
- ];
9
- function tryExtractId(item) {
10
- if (item && typeof item === "object" && "id" in item) {
11
- const id = item.id;
12
- if (id !== undefined && id !== null)
13
- return String(id);
14
- }
15
- return undefined;
16
- }
17
- function tryExtractUri(item, platformId, fallbackId) {
18
- if (item && typeof item === "object") {
19
- const record = item;
20
- for (const key of ["url", "uri", "link"]) {
21
- const value = record[key];
22
- if (typeof value === "string" && value.trim().length > 0) {
23
- return value;
24
- }
25
- }
26
- }
27
- return `platform://${platformId}/item/${encodeURIComponent(fallbackId)}`;
28
- }
29
- function extractFromPlatformArray(platformId, record, observedAt) {
30
- for (const key of PLATFORM_ARRAY_KEYS) {
31
- const arr = record[key];
32
- if (Array.isArray(arr) && arr.length > 0) {
33
- const out = [];
34
- for (let index = 0; index < arr.length; index += 1) {
35
- const item = arr[index];
36
- const id = tryExtractId(item) ?? `${platformId}-${key}-${index}`;
37
- const uri = tryExtractUri(item, platformId, id);
38
- out.push({
39
- id,
40
- kind: "platform_item",
41
- uri,
42
- observedAt,
43
- });
44
- }
45
- if (out.length > 0)
46
- return out;
47
- }
48
- }
49
- return undefined;
50
- }
51
- function extractSourceRefs(platformId, data, observedAt) {
52
- if (data && typeof data === "object") {
53
- const record = data;
54
- if (record.data && typeof record.data === "object") {
55
- const nested = extractSourceRefs(platformId, record.data, observedAt);
56
- if (nested.length > 0)
57
- return nested;
58
- }
59
- if (Array.isArray(record.sourceRefs)) {
60
- const out = [];
61
- for (const item of record.sourceRefs) {
62
- if (item && typeof item === "object" && "uri" in item && "id" in item) {
63
- const ref = item;
64
- out.push({
65
- id: String(ref.id),
66
- kind: ref.kind ?? "platform_item",
67
- uri: String(ref.uri),
68
- excerptHash: ref.excerptHash !== undefined ? String(ref.excerptHash) : undefined,
69
- observedAt: ref.observedAt !== undefined ? String(ref.observedAt) : observedAt,
70
- });
71
- }
72
- }
73
- if (out.length > 0)
74
- return out;
75
- }
76
- if (Array.isArray(record.items)) {
77
- return record.items.map((item, index) => {
78
- const id = item && typeof item === "object" && "id" in item
79
- ? String(item.id)
80
- : `${platformId}-item-${index}`;
81
- return {
82
- id,
83
- kind: "platform_item",
84
- uri: `platform://${platformId}/item/${encodeURIComponent(id)}`,
85
- observedAt,
86
- };
87
- });
88
- }
89
- const platformRefs = extractFromPlatformArray(platformId, record, observedAt);
90
- if (platformRefs)
91
- return platformRefs;
92
- }
93
- return [];
94
- }
95
- function resolveEvidenceType(intent) {
96
- if (intent === "feed.read")
97
- return "platform_browse";
98
- if (intent === "work.discover")
99
- return "task_discovery";
100
- return null;
101
- }
102
- function resolveSensitivity(intent, explicit) {
103
- if (explicit)
104
- return explicit;
105
- if (intent === "message.send" || intent === "comment.reply")
106
- return "private";
107
- return "public";
108
- }
109
- /**
110
- * Produce a single life-evidence candidate from a connector outcome, or null if not mappable.
111
- */
112
- export function mapLifeEvidence(input) {
113
- if (input.result.status !== "success") {
114
- return null;
115
- }
116
- if (input.intent === "message.send") {
117
- return null;
118
- }
119
- const evidenceType = resolveEvidenceType(input.intent);
120
- if (!evidenceType) {
121
- return null;
122
- }
123
- const observedAt = input.observedAt ?? new Date().toISOString();
124
- const refs = extractSourceRefs(input.platformId, input.result.data, observedAt);
125
- if (refs.length === 0) {
126
- return null;
127
- }
128
- return {
129
- timestamp: observedAt,
130
- evidenceType,
131
- platformId: input.platformId,
132
- summary: `${input.platformId}:${input.intent}`,
133
- sourceRefs: refs,
134
- sensitivity: resolveSensitivity(input.intent, input.sensitivityOverride),
135
- producer: "connector-system",
136
- };
137
- }
1
+ const PLATFORM_ARRAY_KEYS = [
2
+ "posts",
3
+ "nodes",
4
+ "agents",
5
+ "edges",
6
+ "results",
7
+ "entries",
8
+ ];
9
+ function tryExtractId(item) {
10
+ if (item && typeof item === "object" && "id" in item) {
11
+ const id = item.id;
12
+ if (id !== undefined && id !== null)
13
+ return String(id);
14
+ }
15
+ return undefined;
16
+ }
17
+ function tryExtractUri(item, platformId, fallbackId) {
18
+ if (item && typeof item === "object") {
19
+ const record = item;
20
+ for (const key of ["url", "uri", "link"]) {
21
+ const value = record[key];
22
+ if (typeof value === "string" && value.trim().length > 0) {
23
+ return value;
24
+ }
25
+ }
26
+ }
27
+ return `platform://${platformId}/item/${encodeURIComponent(fallbackId)}`;
28
+ }
29
+ function extractFromPlatformArray(platformId, record, observedAt) {
30
+ for (const key of PLATFORM_ARRAY_KEYS) {
31
+ const arr = record[key];
32
+ if (Array.isArray(arr) && arr.length > 0) {
33
+ const out = [];
34
+ for (let index = 0; index < arr.length; index += 1) {
35
+ const item = arr[index];
36
+ const id = tryExtractId(item) ?? `${platformId}-${key}-${index}`;
37
+ const uri = tryExtractUri(item, platformId, id);
38
+ out.push({
39
+ id,
40
+ kind: "platform_item",
41
+ uri,
42
+ observedAt,
43
+ });
44
+ }
45
+ if (out.length > 0)
46
+ return out;
47
+ }
48
+ }
49
+ return undefined;
50
+ }
51
+ function extractSourceRefs(platformId, data, observedAt) {
52
+ if (data && typeof data === "object") {
53
+ const record = data;
54
+ if (record.data && typeof record.data === "object") {
55
+ const nested = extractSourceRefs(platformId, record.data, observedAt);
56
+ if (nested.length > 0)
57
+ return nested;
58
+ }
59
+ if (Array.isArray(record.sourceRefs)) {
60
+ const out = [];
61
+ for (const item of record.sourceRefs) {
62
+ if (item && typeof item === "object" && "uri" in item && "id" in item) {
63
+ const ref = item;
64
+ out.push({
65
+ id: String(ref.id),
66
+ kind: ref.kind ?? "platform_item",
67
+ uri: String(ref.uri),
68
+ excerptHash: ref.excerptHash !== undefined ? String(ref.excerptHash) : undefined,
69
+ observedAt: ref.observedAt !== undefined ? String(ref.observedAt) : observedAt,
70
+ });
71
+ }
72
+ }
73
+ if (out.length > 0)
74
+ return out;
75
+ }
76
+ if (Array.isArray(record.items)) {
77
+ return record.items.map((item, index) => {
78
+ const id = item && typeof item === "object" && "id" in item
79
+ ? String(item.id)
80
+ : `${platformId}-item-${index}`;
81
+ return {
82
+ id,
83
+ kind: "platform_item",
84
+ uri: `platform://${platformId}/item/${encodeURIComponent(id)}`,
85
+ observedAt,
86
+ };
87
+ });
88
+ }
89
+ const platformRefs = extractFromPlatformArray(platformId, record, observedAt);
90
+ if (platformRefs)
91
+ return platformRefs;
92
+ }
93
+ return [];
94
+ }
95
+ function resolveEvidenceType(intent) {
96
+ if (intent === "feed.read")
97
+ return "platform_browse";
98
+ if (intent === "work.discover")
99
+ return "task_discovery";
100
+ return null;
101
+ }
102
+ function resolveSensitivity(intent, explicit) {
103
+ if (explicit)
104
+ return explicit;
105
+ if (intent === "message.send" || intent === "comment.reply")
106
+ return "private";
107
+ return "public";
108
+ }
109
+ /**
110
+ * Produce a single life-evidence candidate from a connector outcome, or null if not mappable.
111
+ */
112
+ export function mapLifeEvidence(input) {
113
+ if (input.result.status !== "success") {
114
+ return null;
115
+ }
116
+ if (input.intent === "message.send") {
117
+ return null;
118
+ }
119
+ const evidenceType = resolveEvidenceType(input.intent);
120
+ if (!evidenceType) {
121
+ return null;
122
+ }
123
+ const observedAt = input.observedAt ?? new Date().toISOString();
124
+ const refs = extractSourceRefs(input.platformId, input.result.data, observedAt);
125
+ if (refs.length === 0) {
126
+ return null;
127
+ }
128
+ return {
129
+ timestamp: observedAt,
130
+ evidenceType,
131
+ platformId: input.platformId,
132
+ summary: `${input.platformId}:${input.intent}`,
133
+ sourceRefs: refs,
134
+ sensitivity: resolveSensitivity(input.intent, input.sensitivityOverride),
135
+ producer: "connector-system",
136
+ };
137
+ }