@shogo-ai/core 1.4.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 +21 -0
- package/README.md +34 -0
- package/dist/chat-message.cjs +44 -0
- package/dist/chat-message.d.cts +20 -0
- package/dist/chat-message.d.ts +20 -0
- package/dist/chat-message.js +9 -0
- package/dist/chunk-24AL3V6R.js +57 -0
- package/dist/chunk-4J7NH2WJ.js +19 -0
- package/dist/chunk-ELMG6OXT.js +236 -0
- package/dist/chunk-IDGVRGAL.js +103 -0
- package/dist/chunk-KTDDFWXM.js +39 -0
- package/dist/chunk-VTD7O7YC.js +31 -0
- package/dist/index.cjs +510 -0
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +45 -0
- package/dist/instrumentation.cjs +129 -0
- package/dist/instrumentation.d.cts +43 -0
- package/dist/instrumentation.d.ts +43 -0
- package/dist/instrumentation.js +11 -0
- package/dist/logger.cjs +81 -0
- package/dist/logger.d.cts +32 -0
- package/dist/logger.d.ts +32 -0
- package/dist/logger.js +7 -0
- package/dist/macos-junk.cjs +56 -0
- package/dist/macos-junk.d.cts +20 -0
- package/dist/macos-junk.d.ts +20 -0
- package/dist/macos-junk.js +9 -0
- package/dist/stream-buffer.cjs +261 -0
- package/dist/stream-buffer.d.cts +103 -0
- package/dist/stream-buffer.d.ts +103 -0
- package/dist/stream-buffer.js +9 -0
- package/dist/tech-stack-registry.cjs +67 -0
- package/dist/tech-stack-registry.d.cts +88 -0
- package/dist/tech-stack-registry.d.ts +88 -0
- package/dist/tech-stack-registry.js +15 -0
- package/package.json +118 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Shogo Technologies, Inc.
|
|
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,34 @@
|
|
|
1
|
+
<!-- SPDX-License-Identifier: MIT -->
|
|
2
|
+
<!-- Copyright (C) 2026 Shogo Technologies, Inc. -->
|
|
3
|
+
|
|
4
|
+
# @shogo-ai/core
|
|
5
|
+
|
|
6
|
+
Shogo Core — generic, dependency-light utilities used across the Shogo
|
|
7
|
+
SDK family. Zero required peer dependencies; OpenTelemetry is opt-in.
|
|
8
|
+
|
|
9
|
+
## Subpath exports
|
|
10
|
+
|
|
11
|
+
| Subpath | What |
|
|
12
|
+
| --- | --- |
|
|
13
|
+
| `@shogo-ai/core/logger` | Structured leveled logger with pluggable sinks. |
|
|
14
|
+
| `@shogo-ai/core/instrumentation` | Thin OpenTelemetry tracing wrapper that no-ops if `@opentelemetry/api` isn't installed. |
|
|
15
|
+
| `@shogo-ai/core/stream-buffer` | In-memory ring-buffered text stream. |
|
|
16
|
+
| `@shogo-ai/core/chat-message` | Minimal chat-message types shared by `@shogo-ai/agent` and downstream consumers. |
|
|
17
|
+
|
|
18
|
+
## Optional peers
|
|
19
|
+
|
|
20
|
+
Install OpenTelemetry packages only if you import
|
|
21
|
+
`@shogo-ai/core/instrumentation` and want real spans (otherwise the
|
|
22
|
+
wrapper no-ops):
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
bun add -d @opentelemetry/api @opentelemetry/sdk-node \
|
|
26
|
+
@opentelemetry/exporter-trace-otlp-http \
|
|
27
|
+
@opentelemetry/sdk-trace-base \
|
|
28
|
+
@opentelemetry/resources \
|
|
29
|
+
@opentelemetry/semantic-conventions
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## License
|
|
33
|
+
|
|
34
|
+
MIT — see [LICENSE](./LICENSE).
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/chat-message.ts
|
|
21
|
+
var chat_message_exports = {};
|
|
22
|
+
__export(chat_message_exports, {
|
|
23
|
+
extractUserText: () => extractUserText,
|
|
24
|
+
findLastUserMessage: () => findLastUserMessage
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(chat_message_exports);
|
|
27
|
+
function findLastUserMessage(messages) {
|
|
28
|
+
return [...messages].reverse().find((m) => m.role === "user") ?? null;
|
|
29
|
+
}
|
|
30
|
+
function extractUserText(message) {
|
|
31
|
+
if (typeof message.content === "string") {
|
|
32
|
+
return message.content;
|
|
33
|
+
}
|
|
34
|
+
if (Array.isArray(message.parts)) {
|
|
35
|
+
return message.parts.filter((p) => p.type === "text").map((p) => p.text).join("\n");
|
|
36
|
+
}
|
|
37
|
+
return String(message.content ?? "");
|
|
38
|
+
}
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
extractUserText,
|
|
42
|
+
findLastUserMessage
|
|
43
|
+
});
|
|
44
|
+
//# sourceMappingURL=chat-message.cjs.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User message extraction for AI SDK v3 (`parts`) and legacy (`content`)
|
|
3
|
+
* message shapes. Useful when you need plain text from a chat history —
|
|
4
|
+
* e.g. for fingerprinting, logging, or short-circuit routing decisions
|
|
5
|
+
* before the message hits an LLM.
|
|
6
|
+
*
|
|
7
|
+
* Lifted into the SDK from `@shogo/shared-runtime` (was AGPL) under MIT.
|
|
8
|
+
* The original `@shogo/shared-runtime/chat-message` re-exports this
|
|
9
|
+
* module unchanged for backwards compatibility.
|
|
10
|
+
*/
|
|
11
|
+
/** Find the last user message in a messages array. */
|
|
12
|
+
declare function findLastUserMessage(messages: any[]): any | null;
|
|
13
|
+
/**
|
|
14
|
+
* Extract plain text from a user message object.
|
|
15
|
+
* Handles AI SDK v3 `parts` format, legacy `content` string,
|
|
16
|
+
* and legacy `content` array format.
|
|
17
|
+
*/
|
|
18
|
+
declare function extractUserText(message: any): string;
|
|
19
|
+
|
|
20
|
+
export { extractUserText, findLastUserMessage };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User message extraction for AI SDK v3 (`parts`) and legacy (`content`)
|
|
3
|
+
* message shapes. Useful when you need plain text from a chat history —
|
|
4
|
+
* e.g. for fingerprinting, logging, or short-circuit routing decisions
|
|
5
|
+
* before the message hits an LLM.
|
|
6
|
+
*
|
|
7
|
+
* Lifted into the SDK from `@shogo/shared-runtime` (was AGPL) under MIT.
|
|
8
|
+
* The original `@shogo/shared-runtime/chat-message` re-exports this
|
|
9
|
+
* module unchanged for backwards compatibility.
|
|
10
|
+
*/
|
|
11
|
+
/** Find the last user message in a messages array. */
|
|
12
|
+
declare function findLastUserMessage(messages: any[]): any | null;
|
|
13
|
+
/**
|
|
14
|
+
* Extract plain text from a user message object.
|
|
15
|
+
* Handles AI SDK v3 `parts` format, legacy `content` string,
|
|
16
|
+
* and legacy `content` array format.
|
|
17
|
+
*/
|
|
18
|
+
declare function extractUserText(message: any): string;
|
|
19
|
+
|
|
20
|
+
export { extractUserText, findLastUserMessage };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// src/logger.ts
|
|
2
|
+
var LOG_LEVELS = {
|
|
3
|
+
debug: 0,
|
|
4
|
+
info: 1,
|
|
5
|
+
warn: 2,
|
|
6
|
+
error: 3
|
|
7
|
+
};
|
|
8
|
+
var isProduction = process.env.NODE_ENV === "production" || process.env.NODE_ENV === "staging";
|
|
9
|
+
var minLevel = LOG_LEVELS[process.env.LOG_LEVEL || "info"] ?? 1;
|
|
10
|
+
function shouldLog(level) {
|
|
11
|
+
return LOG_LEVELS[level] >= minLevel;
|
|
12
|
+
}
|
|
13
|
+
function formatEntry(entry) {
|
|
14
|
+
if (isProduction) {
|
|
15
|
+
return JSON.stringify(entry);
|
|
16
|
+
}
|
|
17
|
+
const { level: _level, msg, service, timestamp: _timestamp, ...extra } = entry;
|
|
18
|
+
const extraStr = Object.keys(extra).length > 0 ? " " + JSON.stringify(extra) : "";
|
|
19
|
+
return `[${service}] ${msg}${extraStr}`;
|
|
20
|
+
}
|
|
21
|
+
function createLogger(service, defaultExtra) {
|
|
22
|
+
function log(level, msg, extra) {
|
|
23
|
+
if (!shouldLog(level)) return;
|
|
24
|
+
const entry = {
|
|
25
|
+
level,
|
|
26
|
+
msg,
|
|
27
|
+
service,
|
|
28
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
29
|
+
...defaultExtra,
|
|
30
|
+
...extra
|
|
31
|
+
};
|
|
32
|
+
const formatted = formatEntry(entry);
|
|
33
|
+
switch (level) {
|
|
34
|
+
case "error":
|
|
35
|
+
console.error(formatted);
|
|
36
|
+
break;
|
|
37
|
+
case "warn":
|
|
38
|
+
console.warn(formatted);
|
|
39
|
+
break;
|
|
40
|
+
default:
|
|
41
|
+
console.log(formatted);
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
debug: (msg, extra) => log("debug", msg, extra),
|
|
47
|
+
info: (msg, extra) => log("info", msg, extra),
|
|
48
|
+
warn: (msg, extra) => log("warn", msg, extra),
|
|
49
|
+
error: (msg, extra) => log("error", msg, extra),
|
|
50
|
+
child: (extra) => createLogger(service, { ...defaultExtra, ...extra })
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export {
|
|
55
|
+
createLogger
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=chunk-24AL3V6R.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// src/chat-message.ts
|
|
2
|
+
function findLastUserMessage(messages) {
|
|
3
|
+
return [...messages].reverse().find((m) => m.role === "user") ?? null;
|
|
4
|
+
}
|
|
5
|
+
function extractUserText(message) {
|
|
6
|
+
if (typeof message.content === "string") {
|
|
7
|
+
return message.content;
|
|
8
|
+
}
|
|
9
|
+
if (Array.isArray(message.parts)) {
|
|
10
|
+
return message.parts.filter((p) => p.type === "text").map((p) => p.text).join("\n");
|
|
11
|
+
}
|
|
12
|
+
return String(message.content ?? "");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
findLastUserMessage,
|
|
17
|
+
extractUserText
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=chunk-4J7NH2WJ.js.map
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
// src/stream-buffer.ts
|
|
2
|
+
var CLEANUP_INTERVAL_MS = 6e4;
|
|
3
|
+
var MAX_BUFFER_AGE_MS = 30 * 6e4;
|
|
4
|
+
var COMPLETED_GRACE_MS = 3e4;
|
|
5
|
+
var StreamBufferStore = class {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.buffers = /* @__PURE__ */ new Map();
|
|
8
|
+
this.cleanupTimer = null;
|
|
9
|
+
this.cleanupTimer = setInterval(() => this.cleanup(), CLEANUP_INTERVAL_MS);
|
|
10
|
+
const handle = this.cleanupTimer;
|
|
11
|
+
if (handle && typeof handle.unref === "function") {
|
|
12
|
+
handle.unref();
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Create (or replace) a buffer for the given key. Any existing active
|
|
17
|
+
* buffer is completed and discarded. Returns a writer bound to this
|
|
18
|
+
* specific buffer instance, including the new `turnId`.
|
|
19
|
+
*/
|
|
20
|
+
create(key, opts) {
|
|
21
|
+
const existing = this.buffers.get(key);
|
|
22
|
+
if (existing && existing.status === "active") {
|
|
23
|
+
this.completeBuffer(existing, "replaced");
|
|
24
|
+
}
|
|
25
|
+
const now = Date.now();
|
|
26
|
+
const turnId = opts?.turnId || generateTurnId();
|
|
27
|
+
const buf = {
|
|
28
|
+
turnId,
|
|
29
|
+
frames: [],
|
|
30
|
+
subscribers: /* @__PURE__ */ new Set(),
|
|
31
|
+
status: "active",
|
|
32
|
+
terminal: null,
|
|
33
|
+
createdAt: now,
|
|
34
|
+
completedAt: null,
|
|
35
|
+
lastEventAt: now,
|
|
36
|
+
nextSeq: 1
|
|
37
|
+
};
|
|
38
|
+
this.buffers.set(key, buf);
|
|
39
|
+
return {
|
|
40
|
+
get turnId() {
|
|
41
|
+
return buf.turnId;
|
|
42
|
+
},
|
|
43
|
+
get lastSeq() {
|
|
44
|
+
return buf.nextSeq - 1;
|
|
45
|
+
},
|
|
46
|
+
append: (chunk) => {
|
|
47
|
+
if (buf.status !== "active") return -1;
|
|
48
|
+
const seq = buf.nextSeq++;
|
|
49
|
+
buf.frames.push({ seq, chunk });
|
|
50
|
+
buf.lastEventAt = Date.now();
|
|
51
|
+
for (const ctrl of buf.subscribers) {
|
|
52
|
+
try {
|
|
53
|
+
ctrl.enqueue(chunk);
|
|
54
|
+
} catch {
|
|
55
|
+
buf.subscribers.delete(ctrl);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return seq;
|
|
59
|
+
},
|
|
60
|
+
complete: (reason) => {
|
|
61
|
+
this.completeBuffer(buf, reason);
|
|
62
|
+
},
|
|
63
|
+
fail: (error) => {
|
|
64
|
+
this.failBuffer(buf, error);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Append a chunk by key (loose, untyped writer). Returns the seq assigned,
|
|
70
|
+
* or -1 if the buffer is unknown/inactive.
|
|
71
|
+
*/
|
|
72
|
+
append(key, chunk) {
|
|
73
|
+
const buf = this.buffers.get(key);
|
|
74
|
+
if (!buf || buf.status !== "active") return -1;
|
|
75
|
+
const seq = buf.nextSeq++;
|
|
76
|
+
buf.frames.push({ seq, chunk });
|
|
77
|
+
buf.lastEventAt = Date.now();
|
|
78
|
+
for (const ctrl of buf.subscribers) {
|
|
79
|
+
try {
|
|
80
|
+
ctrl.enqueue(chunk);
|
|
81
|
+
} catch {
|
|
82
|
+
buf.subscribers.delete(ctrl);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return seq;
|
|
86
|
+
}
|
|
87
|
+
/** Mark a buffer as completed by key. Optional terminal reason. */
|
|
88
|
+
complete(key, reason) {
|
|
89
|
+
const buf = this.buffers.get(key);
|
|
90
|
+
if (!buf) return;
|
|
91
|
+
this.completeBuffer(buf, reason);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Abort a stream: complete subscribers and remove the buffer entirely.
|
|
95
|
+
* Future resume/replay requests for this key will return null (→ 204).
|
|
96
|
+
*/
|
|
97
|
+
abort(key) {
|
|
98
|
+
const buf = this.buffers.get(key);
|
|
99
|
+
if (!buf) return;
|
|
100
|
+
this.completeBuffer(buf, "aborted");
|
|
101
|
+
buf.status = "aborted";
|
|
102
|
+
this.buffers.delete(key);
|
|
103
|
+
}
|
|
104
|
+
has(key) {
|
|
105
|
+
return this.buffers.has(key);
|
|
106
|
+
}
|
|
107
|
+
/** Read-only metadata about a buffered turn. Useful for resume responses. */
|
|
108
|
+
snapshot(key) {
|
|
109
|
+
const buf = this.buffers.get(key);
|
|
110
|
+
if (!buf) return null;
|
|
111
|
+
return {
|
|
112
|
+
turnId: buf.turnId,
|
|
113
|
+
status: buf.status,
|
|
114
|
+
lastSeq: buf.nextSeq - 1,
|
|
115
|
+
terminal: buf.terminal,
|
|
116
|
+
createdAt: buf.createdAt,
|
|
117
|
+
completedAt: buf.completedAt,
|
|
118
|
+
lastEventAt: buf.lastEventAt
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Create a ReadableStream that first replays all buffered chunks past
|
|
123
|
+
* `opts.fromSeq` (default: 0 → replay everything), then subscribes for
|
|
124
|
+
* any further live chunks until the stream completes.
|
|
125
|
+
*
|
|
126
|
+
* Returns null if no buffer exists for the key.
|
|
127
|
+
*/
|
|
128
|
+
createReplayStream(key, opts = {}) {
|
|
129
|
+
const buf = this.buffers.get(key);
|
|
130
|
+
if (!buf) return null;
|
|
131
|
+
const fromSeq = Math.max(0, opts.fromSeq ?? 0);
|
|
132
|
+
let subscribedController = null;
|
|
133
|
+
return new ReadableStream({
|
|
134
|
+
start(controller) {
|
|
135
|
+
for (const frame of buf.frames) {
|
|
136
|
+
if (frame.seq <= fromSeq) continue;
|
|
137
|
+
try {
|
|
138
|
+
controller.enqueue(frame.chunk);
|
|
139
|
+
} catch {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (buf.status !== "active") {
|
|
144
|
+
try {
|
|
145
|
+
controller.close();
|
|
146
|
+
} catch {
|
|
147
|
+
}
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
subscribedController = controller;
|
|
151
|
+
buf.subscribers.add(controller);
|
|
152
|
+
},
|
|
153
|
+
cancel() {
|
|
154
|
+
if (subscribedController) {
|
|
155
|
+
buf.subscribers.delete(subscribedController);
|
|
156
|
+
subscribedController = null;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
cleanup() {
|
|
162
|
+
const now = Date.now();
|
|
163
|
+
for (const [key, buf] of this.buffers) {
|
|
164
|
+
if (buf.status !== "active" && buf.completedAt && now - buf.completedAt > COMPLETED_GRACE_MS) {
|
|
165
|
+
this.buffers.delete(key);
|
|
166
|
+
} else if (now - buf.createdAt > MAX_BUFFER_AGE_MS && buf.subscribers.size === 0) {
|
|
167
|
+
this.completeBuffer(buf, "expired");
|
|
168
|
+
this.buffers.delete(key);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
dispose() {
|
|
173
|
+
if (this.cleanupTimer) {
|
|
174
|
+
clearInterval(this.cleanupTimer);
|
|
175
|
+
this.cleanupTimer = null;
|
|
176
|
+
}
|
|
177
|
+
for (const buf of this.buffers.values()) {
|
|
178
|
+
this.completeBuffer(buf, "disposed");
|
|
179
|
+
}
|
|
180
|
+
this.buffers.clear();
|
|
181
|
+
}
|
|
182
|
+
completeBuffer(buf, reason) {
|
|
183
|
+
if (buf.status !== "active") return;
|
|
184
|
+
buf.status = "completed";
|
|
185
|
+
buf.terminal = { reason };
|
|
186
|
+
buf.completedAt = Date.now();
|
|
187
|
+
buf.lastEventAt = buf.completedAt;
|
|
188
|
+
for (const ctrl of buf.subscribers) {
|
|
189
|
+
try {
|
|
190
|
+
ctrl.close();
|
|
191
|
+
} catch {
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
buf.subscribers.clear();
|
|
195
|
+
}
|
|
196
|
+
failBuffer(buf, error) {
|
|
197
|
+
if (buf.status !== "active") return;
|
|
198
|
+
buf.status = "failed";
|
|
199
|
+
buf.terminal = { error };
|
|
200
|
+
buf.completedAt = Date.now();
|
|
201
|
+
buf.lastEventAt = buf.completedAt;
|
|
202
|
+
for (const ctrl of buf.subscribers) {
|
|
203
|
+
try {
|
|
204
|
+
ctrl.close();
|
|
205
|
+
} catch {
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
buf.subscribers.clear();
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
function generateTurnId() {
|
|
212
|
+
try {
|
|
213
|
+
if (typeof globalThis.crypto?.randomUUID === "function") {
|
|
214
|
+
return globalThis.crypto.randomUUID();
|
|
215
|
+
}
|
|
216
|
+
} catch {
|
|
217
|
+
}
|
|
218
|
+
return `turn_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
|
|
219
|
+
}
|
|
220
|
+
function createBufferingTransform(store, key) {
|
|
221
|
+
return new TransformStream({
|
|
222
|
+
transform(chunk, controller) {
|
|
223
|
+
store.append(key, chunk);
|
|
224
|
+
controller.enqueue(chunk);
|
|
225
|
+
},
|
|
226
|
+
flush() {
|
|
227
|
+
store.complete(key);
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export {
|
|
233
|
+
StreamBufferStore,
|
|
234
|
+
createBufferingTransform
|
|
235
|
+
};
|
|
236
|
+
//# sourceMappingURL=chunk-ELMG6OXT.js.map
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// src/instrumentation.ts
|
|
2
|
+
import { diag, DiagConsoleLogger, DiagLogLevel, trace, SpanStatusCode } from "@opentelemetry/api";
|
|
3
|
+
import { NodeSDK } from "@opentelemetry/sdk-node";
|
|
4
|
+
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
|
|
5
|
+
import { BatchSpanProcessor, SimpleSpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
6
|
+
import { resourceFromAttributes } from "@opentelemetry/resources";
|
|
7
|
+
import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } from "@opentelemetry/semantic-conventions";
|
|
8
|
+
var sdk = null;
|
|
9
|
+
function initInstrumentation(config) {
|
|
10
|
+
const endpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
|
|
11
|
+
if (!endpoint) {
|
|
12
|
+
console.log(`[OTEL] Tracing disabled for ${config.serviceName} (OTEL_EXPORTER_OTLP_ENDPOINT not set)`);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const diagLevel = process.env.OTEL_LOG_LEVEL === "debug" ? DiagLogLevel.DEBUG : process.env.OTEL_LOG_LEVEL === "info" ? DiagLogLevel.INFO : DiagLogLevel.WARN;
|
|
16
|
+
diag.setLogger(new DiagConsoleLogger(), diagLevel);
|
|
17
|
+
const headers = {};
|
|
18
|
+
if (process.env.SIGNOZ_INGESTION_KEY) {
|
|
19
|
+
headers["signoz-ingestion-key"] = process.env.SIGNOZ_INGESTION_KEY;
|
|
20
|
+
}
|
|
21
|
+
const serviceName = process.env.OTEL_SERVICE_NAME || config.serviceName;
|
|
22
|
+
console.log(`[OTEL] Configuring ${serviceName} \u2192 ${endpoint}/v1/traces`);
|
|
23
|
+
let traceExporter;
|
|
24
|
+
try {
|
|
25
|
+
traceExporter = new OTLPTraceExporter({
|
|
26
|
+
url: `${endpoint}/v1/traces`,
|
|
27
|
+
headers
|
|
28
|
+
});
|
|
29
|
+
} catch (err) {
|
|
30
|
+
console.error(`[OTEL] Failed to create exporter: ${err.message}`);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const isProduction = process.env.NODE_ENV === "production" || process.env.NODE_ENV === "staging";
|
|
34
|
+
const spanProcessor = isProduction ? new BatchSpanProcessor(traceExporter) : new SimpleSpanProcessor(traceExporter);
|
|
35
|
+
sdk = new NodeSDK({
|
|
36
|
+
resource: resourceFromAttributes({
|
|
37
|
+
[ATTR_SERVICE_NAME]: serviceName,
|
|
38
|
+
[ATTR_SERVICE_VERSION]: config.serviceVersion || "0.1.0",
|
|
39
|
+
"deployment.environment.name": process.env.NODE_ENV || "development"
|
|
40
|
+
}),
|
|
41
|
+
spanProcessors: [spanProcessor],
|
|
42
|
+
instrumentations: []
|
|
43
|
+
});
|
|
44
|
+
try {
|
|
45
|
+
sdk.start();
|
|
46
|
+
console.log(`[OTEL] Tracing enabled for ${serviceName}`);
|
|
47
|
+
} catch (err) {
|
|
48
|
+
console.error(`[OTEL] SDK failed to start: ${err.message}`);
|
|
49
|
+
sdk = null;
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
const tracer = trace.getTracer(serviceName);
|
|
54
|
+
const testSpan = tracer.startSpan("otel.startup-test", {
|
|
55
|
+
attributes: {
|
|
56
|
+
"test.type": "startup-verification",
|
|
57
|
+
"service.name": serviceName,
|
|
58
|
+
// `process.versions.bun` is present under Bun (always undefined
|
|
59
|
+
// under plain Node) — avoids referencing the `Bun` global so
|
|
60
|
+
// this file typechecks without `@types/bun` in tsconfig.
|
|
61
|
+
"runtime": process.versions.bun ? "bun" : "node"
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
testSpan.setStatus({ code: SpanStatusCode.OK });
|
|
65
|
+
testSpan.end();
|
|
66
|
+
console.log(`[OTEL] Startup test span emitted for ${serviceName}`);
|
|
67
|
+
} catch (err) {
|
|
68
|
+
console.error(`[OTEL] Failed to emit test span: ${err.message}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async function shutdownInstrumentation() {
|
|
72
|
+
if (sdk) {
|
|
73
|
+
try {
|
|
74
|
+
await sdk.shutdown();
|
|
75
|
+
console.log("[OTEL] Tracing shut down");
|
|
76
|
+
} catch (err) {
|
|
77
|
+
console.error("[OTEL] Error shutting down:", err.message);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function traceOperation(tracerName, spanName, attributes, fn) {
|
|
82
|
+
const tracer = trace.getTracer(tracerName);
|
|
83
|
+
return tracer.startActiveSpan(spanName, { attributes }, async (span) => {
|
|
84
|
+
try {
|
|
85
|
+
const result = await fn(span);
|
|
86
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
87
|
+
return result;
|
|
88
|
+
} catch (err) {
|
|
89
|
+
span.setStatus({ code: SpanStatusCode.ERROR, message: err.message });
|
|
90
|
+
span.recordException(err);
|
|
91
|
+
throw err;
|
|
92
|
+
} finally {
|
|
93
|
+
span.end();
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export {
|
|
99
|
+
initInstrumentation,
|
|
100
|
+
shutdownInstrumentation,
|
|
101
|
+
traceOperation
|
|
102
|
+
};
|
|
103
|
+
//# sourceMappingURL=chunk-IDGVRGAL.js.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// src/tech-stack-registry.ts
|
|
2
|
+
var TECH_STACK_REGISTRY = {
|
|
3
|
+
// Web (Vite-based) — share a bundled Vite template, so apps/api seeds them.
|
|
4
|
+
"react-app": { id: "react-app", target: "web" },
|
|
5
|
+
"threejs-game": { id: "threejs-game", target: "web" },
|
|
6
|
+
"phaser-game": { id: "phaser-game", target: "web" },
|
|
7
|
+
// Mobile (Metro/Expo) — agent-runtime owns the seed.
|
|
8
|
+
"expo-app": { id: "expo-app", target: "mobile", metro: true, seedsOwnTemplate: true },
|
|
9
|
+
"expo-three": { id: "expo-three", target: "mobile", metro: true, seedsOwnTemplate: true },
|
|
10
|
+
"react-native": { id: "react-native", target: "mobile", metro: true, seedsOwnTemplate: true },
|
|
11
|
+
// Data / scripting
|
|
12
|
+
"python-data": { id: "python-data", target: "data", seedsOwnTemplate: true },
|
|
13
|
+
// Native (full game engines)
|
|
14
|
+
"unity-game": { id: "unity-game", target: "native", seedsOwnTemplate: true },
|
|
15
|
+
// Bare / no-stack
|
|
16
|
+
none: { id: "none", target: "none", seedsOwnTemplate: true }
|
|
17
|
+
};
|
|
18
|
+
function getStackEntry(techStackId) {
|
|
19
|
+
if (!techStackId) return null;
|
|
20
|
+
return TECH_STACK_REGISTRY[techStackId] ?? null;
|
|
21
|
+
}
|
|
22
|
+
function isMobileTechStack(techStackId) {
|
|
23
|
+
return getStackEntry(techStackId)?.target === "mobile";
|
|
24
|
+
}
|
|
25
|
+
function usesMetroBundler(techStackId) {
|
|
26
|
+
return getStackEntry(techStackId)?.metro === true;
|
|
27
|
+
}
|
|
28
|
+
function stackSeedsItself(techStackId) {
|
|
29
|
+
return getStackEntry(techStackId)?.seedsOwnTemplate === true;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export {
|
|
33
|
+
TECH_STACK_REGISTRY,
|
|
34
|
+
getStackEntry,
|
|
35
|
+
isMobileTechStack,
|
|
36
|
+
usesMetroBundler,
|
|
37
|
+
stackSeedsItself
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=chunk-KTDDFWXM.js.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// src/macos-junk.ts
|
|
2
|
+
var MACOS_JUNK_BASENAMES = /* @__PURE__ */ new Set([
|
|
3
|
+
".DS_Store",
|
|
4
|
+
".AppleDouble",
|
|
5
|
+
".LSOverride",
|
|
6
|
+
".Spotlight-V100",
|
|
7
|
+
".Trashes",
|
|
8
|
+
".fseventsd",
|
|
9
|
+
".TemporaryItems",
|
|
10
|
+
".VolumeIcon.icns",
|
|
11
|
+
".com.apple.timemachine.donotpresent",
|
|
12
|
+
"__MACOSX"
|
|
13
|
+
]);
|
|
14
|
+
var ICON_CR = "Icon\r";
|
|
15
|
+
function isMacOSJunkName(name) {
|
|
16
|
+
if (!name) return false;
|
|
17
|
+
if (name.startsWith("._")) return true;
|
|
18
|
+
if (MACOS_JUNK_BASENAMES.has(name)) return true;
|
|
19
|
+
if (name === ICON_CR) return true;
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
function isMacOSJunkPath(relPath) {
|
|
23
|
+
if (!relPath) return false;
|
|
24
|
+
return relPath.split("/").some(isMacOSJunkName);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
isMacOSJunkName,
|
|
29
|
+
isMacOSJunkPath
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=chunk-VTD7O7YC.js.map
|