@mastra/core 1.5.0 → 1.6.0
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/CHANGELOG.md +386 -0
- package/dist/agent/index.cjs +13 -13
- package/dist/agent/index.js +2 -2
- package/dist/agent/message-list/adapters/AIV5Adapter.d.ts.map +1 -1
- package/dist/agent/message-list/conversion/output-converter.d.ts.map +1 -1
- package/dist/agent/message-list/index.cjs +18 -18
- package/dist/agent/message-list/index.js +1 -1
- package/dist/agent/workflows/prepare-stream/index.d.ts +7 -7
- package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts +7 -7
- package/dist/agent/workflows/prepare-stream/schema.d.ts +11 -11
- package/dist/{chunk-CQ4Z6ZAV.cjs → chunk-3U3XFMGJ.cjs} +7 -7
- package/dist/{chunk-CQ4Z6ZAV.cjs.map → chunk-3U3XFMGJ.cjs.map} +1 -1
- package/dist/{chunk-D57U4II4.js → chunk-4WG5K4CK.js} +9 -8
- package/dist/chunk-4WG5K4CK.js.map +1 -0
- package/dist/{chunk-UZFGMMKU.js → chunk-5K45E5VE.js} +37 -3
- package/dist/chunk-5K45E5VE.js.map +1 -0
- package/dist/{chunk-OQ5LZ6OV.cjs → chunk-5VQPSWPG.cjs} +149 -61
- package/dist/chunk-5VQPSWPG.cjs.map +1 -0
- package/dist/{chunk-AIRMLZ43.js → chunk-7EXW4AAG.js} +4 -4
- package/dist/{chunk-AIRMLZ43.js.map → chunk-7EXW4AAG.js.map} +1 -1
- package/dist/{chunk-S4VVZI4E.cjs → chunk-AYHSPIT6.cjs} +326 -5
- package/dist/chunk-AYHSPIT6.cjs.map +1 -0
- package/dist/{chunk-YW54RH77.cjs → chunk-DB7U2C5B.cjs} +12 -5
- package/dist/chunk-DB7U2C5B.cjs.map +1 -0
- package/dist/{chunk-DST75PA4.js → chunk-DGS2KGDI.js} +4 -4
- package/dist/{chunk-DST75PA4.js.map → chunk-DGS2KGDI.js.map} +1 -1
- package/dist/{chunk-YIN5F7VO.js → chunk-EEU5NHHU.js} +4254 -3958
- package/dist/chunk-EEU5NHHU.js.map +1 -0
- package/dist/{chunk-A6EWCOGA.cjs → chunk-H5S4PS44.cjs} +197 -27
- package/dist/chunk-H5S4PS44.cjs.map +1 -0
- package/dist/{chunk-3YMDR4OL.cjs → chunk-HTAUP7ER.cjs} +4 -4
- package/dist/{chunk-3YMDR4OL.cjs.map → chunk-HTAUP7ER.cjs.map} +1 -1
- package/dist/{chunk-OHLVZVIK.js → chunk-IC5OUWKJ.js} +12 -5
- package/dist/chunk-IC5OUWKJ.js.map +1 -0
- package/dist/{chunk-MZIMV2BB.js → chunk-IHDE4CJV.js} +244 -213
- package/dist/chunk-IHDE4CJV.js.map +1 -0
- package/dist/{chunk-3KJW4EMO.js → chunk-IHEYJDJP.js} +3 -3
- package/dist/{chunk-3KJW4EMO.js.map → chunk-IHEYJDJP.js.map} +1 -1
- package/dist/{chunk-CXVMDV2B.js → chunk-IOY7Y5GV.js} +197 -27
- package/dist/chunk-IOY7Y5GV.js.map +1 -0
- package/dist/{chunk-MDC6VYA6.cjs → chunk-KAVAKMOQ.cjs} +4 -8
- package/dist/chunk-KAVAKMOQ.cjs.map +1 -0
- package/dist/{chunk-7WC7ALDW.cjs → chunk-LNKS4TJ6.cjs} +6 -6
- package/dist/{chunk-7WC7ALDW.cjs.map → chunk-LNKS4TJ6.cjs.map} +1 -1
- package/dist/{chunk-R3364RAL.js → chunk-MWGGSA5Q.js} +4 -4
- package/dist/{chunk-R3364RAL.js.map → chunk-MWGGSA5Q.js.map} +1 -1
- package/dist/{chunk-QSN5KQXZ.cjs → chunk-O7PZ4VOO.cjs} +11 -11
- package/dist/{chunk-QSN5KQXZ.cjs.map → chunk-O7PZ4VOO.cjs.map} +1 -1
- package/dist/chunk-OQDRPRKM.cjs +46 -0
- package/dist/chunk-OQDRPRKM.cjs.map +1 -0
- package/dist/{chunk-YV2YGQRY.js → chunk-RHKNKJNM.js} +101 -13
- package/dist/chunk-RHKNKJNM.js.map +1 -0
- package/dist/{chunk-TPDMP7OD.js → chunk-RHYZ6CQN.js} +4 -8
- package/dist/chunk-RHYZ6CQN.js.map +1 -0
- package/dist/{chunk-G5JVVFIG.cjs → chunk-RZNHRIM7.cjs} +9 -9
- package/dist/{chunk-G5JVVFIG.cjs.map → chunk-RZNHRIM7.cjs.map} +1 -1
- package/dist/{chunk-JZ6TH4HQ.cjs → chunk-TL2TTA4X.cjs} +4260 -3962
- package/dist/chunk-TL2TTA4X.cjs.map +1 -0
- package/dist/{chunk-KNXZ7KYL.cjs → chunk-TVPANHLE.cjs} +40 -2
- package/dist/chunk-TVPANHLE.cjs.map +1 -0
- package/dist/{chunk-7S6LA43E.cjs → chunk-VJWRJWSC.cjs} +278 -248
- package/dist/chunk-VJWRJWSC.cjs.map +1 -0
- package/dist/chunk-X2HAI3OX.js +39 -0
- package/dist/chunk-X2HAI3OX.js.map +1 -0
- package/dist/{chunk-FZ5DRHKE.js → chunk-XB3DA67Q.js} +325 -5
- package/dist/chunk-XB3DA67Q.js.map +1 -0
- package/dist/{chunk-NUV3BLRH.cjs → chunk-XWZAKKFT.cjs} +17 -16
- package/dist/chunk-XWZAKKFT.cjs.map +1 -0
- package/dist/{chunk-4GB2GS4S.js → chunk-YM6245EM.js} +5 -5
- package/dist/{chunk-4GB2GS4S.js.map → chunk-YM6245EM.js.map} +1 -1
- package/dist/datasets/index.cjs +17 -17
- package/dist/datasets/index.js +2 -2
- package/dist/docs/SKILL.md +2 -1
- package/dist/docs/assets/SOURCE_MAP.json +417 -391
- package/dist/docs/references/docs-memory-observational-memory.md +2 -0
- package/dist/docs/references/docs-streaming-tool-streaming.md +6 -0
- package/dist/docs/references/docs-workspace-filesystem.md +21 -1
- package/dist/docs/references/reference-harness-harness-class.md +645 -0
- package/dist/docs/references/reference-memory-memory-class.md +1 -1
- package/dist/docs/references/reference-memory-observational-memory.md +1 -0
- package/dist/docs/references/reference-workspace-local-filesystem.md +25 -0
- package/dist/docs/references/reference-workspace-workspace-class.md +1 -24
- package/dist/docs/references/reference.md +1 -0
- package/dist/editor/types.d.ts +20 -1
- package/dist/editor/types.d.ts.map +1 -1
- package/dist/evals/base.d.ts.map +1 -1
- package/dist/evals/index.cjs +20 -20
- package/dist/evals/index.js +3 -3
- package/dist/evals/scoreTraces/index.cjs +5 -5
- package/dist/evals/scoreTraces/index.js +2 -2
- package/dist/events/index.cjs +6 -2
- package/dist/events/index.d.ts +1 -0
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +1 -1
- package/dist/harness/harness.d.ts +105 -35
- package/dist/harness/harness.d.ts.map +1 -1
- package/dist/harness/index.cjs +472 -64
- package/dist/harness/index.cjs.map +1 -1
- package/dist/harness/index.d.ts +2 -1
- package/dist/harness/index.d.ts.map +1 -1
- package/dist/harness/index.js +468 -62
- package/dist/harness/index.js.map +1 -1
- package/dist/harness/tools.d.ts +38 -0
- package/dist/harness/tools.d.ts.map +1 -1
- package/dist/harness/types.d.ts +64 -9
- package/dist/harness/types.d.ts.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +1 -1
- package/dist/llm/index.cjs +12 -12
- package/dist/llm/index.js +3 -3
- package/dist/llm/model/gateways/models-dev.d.ts.map +1 -1
- package/dist/loop/index.cjs +12 -12
- package/dist/loop/index.js +1 -1
- package/dist/loop/network/index.d.ts +6 -6
- package/dist/loop/network/index.d.ts.map +1 -1
- package/dist/loop/test-utils/options.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/index.d.ts +21 -21
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +14 -14
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts +7 -7
- package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-loop/index.d.ts +21 -21
- package/dist/loop/workflows/agentic-loop/index.d.ts.map +1 -1
- package/dist/loop/workflows/schema.d.ts +30 -30
- package/dist/loop/workflows/stream.d.ts +0 -13
- package/dist/loop/workflows/stream.d.ts.map +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.js +1 -1
- package/dist/memory/index.cjs +14 -14
- package/dist/memory/index.js +1 -1
- package/dist/models-dev-6P4CM74H.js +3 -0
- package/dist/{models-dev-MDI5E2YA.js.map → models-dev-6P4CM74H.js.map} +1 -1
- package/dist/models-dev-CLLSNT5L.cjs +12 -0
- package/dist/{models-dev-BW2GAM3K.cjs.map → models-dev-CLLSNT5L.cjs.map} +1 -1
- package/dist/processor-provider/index.cjs +256 -0
- package/dist/processor-provider/index.cjs.map +1 -0
- package/dist/processor-provider/index.d.ts +5 -0
- package/dist/processor-provider/index.d.ts.map +1 -0
- package/dist/processor-provider/index.js +243 -0
- package/dist/processor-provider/index.js.map +1 -0
- package/dist/processor-provider/phase-filtered-processor.d.ts +22 -0
- package/dist/processor-provider/phase-filtered-processor.d.ts.map +1 -0
- package/dist/processor-provider/providers/index.d.ts +12 -0
- package/dist/processor-provider/providers/index.d.ts.map +1 -0
- package/dist/processor-provider/types.d.ts +65 -0
- package/dist/processor-provider/types.d.ts.map +1 -0
- package/dist/processors/index.cjs +41 -41
- package/dist/processors/index.js +1 -1
- package/dist/processors/memory/message-history.d.ts.map +1 -1
- package/dist/processors/step-schema.d.ts +14 -14
- package/dist/provider-registry-HMTFO5FV.cjs +40 -0
- package/dist/{provider-registry-4PH2JPIA.cjs.map → provider-registry-HMTFO5FV.cjs.map} +1 -1
- package/dist/provider-registry-TTZ2WN2P.js +3 -0
- package/dist/{provider-registry-VEJ3PN4S.js.map → provider-registry-TTZ2WN2P.js.map} +1 -1
- package/dist/relevance/index.cjs +3 -3
- package/dist/relevance/index.js +1 -1
- package/dist/storage/base.d.ts +2 -1
- package/dist/storage/base.d.ts.map +1 -1
- package/dist/storage/constants.cjs +68 -52
- package/dist/storage/constants.d.ts +6 -2
- package/dist/storage/constants.d.ts.map +1 -1
- package/dist/storage/constants.js +1 -1
- package/dist/storage/domains/index.d.ts +1 -0
- package/dist/storage/domains/index.d.ts.map +1 -1
- package/dist/storage/domains/inmemory-db.d.ts +4 -1
- package/dist/storage/domains/inmemory-db.d.ts.map +1 -1
- package/dist/storage/domains/mcp-servers/base.d.ts +47 -0
- package/dist/storage/domains/mcp-servers/base.d.ts.map +1 -0
- package/dist/storage/domains/mcp-servers/index.d.ts +3 -0
- package/dist/storage/domains/mcp-servers/index.d.ts.map +1 -0
- package/dist/storage/domains/mcp-servers/inmemory.d.ts +31 -0
- package/dist/storage/domains/mcp-servers/inmemory.d.ts.map +1 -0
- package/dist/storage/domains/memory/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/observability/types.d.ts +44 -44
- package/dist/storage/domains/operations/inmemory.d.ts.map +1 -1
- package/dist/storage/index.cjs +178 -154
- package/dist/storage/index.js +2 -2
- package/dist/storage/mock.d.ts.map +1 -1
- package/dist/storage/types.d.ts +220 -6
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/stream/MastraAgentNetworkStream.d.ts +1 -1
- package/dist/stream/MastraWorkflowStream.d.ts +1 -1
- package/dist/stream/aisdk/v5/input.d.ts.map +1 -1
- package/dist/stream/base/input.d.ts +19 -0
- package/dist/stream/base/input.d.ts.map +1 -1
- package/dist/stream/base/output.d.ts.map +1 -1
- package/dist/stream/index.cjs +11 -11
- package/dist/stream/index.js +2 -2
- package/dist/tool-loop-agent/index.cjs +4 -4
- package/dist/tool-loop-agent/index.js +1 -1
- package/dist/vector/index.cjs +9 -9
- package/dist/vector/index.js +2 -2
- package/dist/workflows/evented/execution-engine.d.ts.map +1 -1
- package/dist/workflows/evented/index.cjs +10 -10
- package/dist/workflows/evented/index.js +1 -1
- package/dist/workflows/evented/step-executor.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/index.d.ts.map +1 -1
- package/dist/workflows/index.cjs +25 -25
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/step.d.ts.map +1 -1
- package/dist/workspace/constants/index.d.ts +1 -0
- package/dist/workspace/constants/index.d.ts.map +1 -1
- package/dist/workspace/index.cjs +64 -64
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/tools/ast-edit.d.ts +97 -0
- package/dist/workspace/tools/ast-edit.d.ts.map +1 -0
- package/dist/workspace/tools/search.d.ts +1 -1
- package/dist/workspace/tools/tools.d.ts.map +1 -1
- package/package.json +12 -11
- package/processor-provider.d.ts +1 -0
- package/dist/chunk-4D4KB75Y.cjs +0 -9
- package/dist/chunk-4D4KB75Y.cjs.map +0 -1
- package/dist/chunk-7S6LA43E.cjs.map +0 -1
- package/dist/chunk-A6EWCOGA.cjs.map +0 -1
- package/dist/chunk-BVUMKER5.js +0 -7
- package/dist/chunk-BVUMKER5.js.map +0 -1
- package/dist/chunk-CXVMDV2B.js.map +0 -1
- package/dist/chunk-D57U4II4.js.map +0 -1
- package/dist/chunk-FZ5DRHKE.js.map +0 -1
- package/dist/chunk-JZ6TH4HQ.cjs.map +0 -1
- package/dist/chunk-KNXZ7KYL.cjs.map +0 -1
- package/dist/chunk-MDC6VYA6.cjs.map +0 -1
- package/dist/chunk-MZIMV2BB.js.map +0 -1
- package/dist/chunk-NUV3BLRH.cjs.map +0 -1
- package/dist/chunk-OHLVZVIK.js.map +0 -1
- package/dist/chunk-OQ5LZ6OV.cjs.map +0 -1
- package/dist/chunk-S4VVZI4E.cjs.map +0 -1
- package/dist/chunk-TPDMP7OD.js.map +0 -1
- package/dist/chunk-UZFGMMKU.js.map +0 -1
- package/dist/chunk-YIN5F7VO.js.map +0 -1
- package/dist/chunk-YV2YGQRY.js.map +0 -1
- package/dist/chunk-YW54RH77.cjs.map +0 -1
- package/dist/models-dev-BW2GAM3K.cjs +0 -12
- package/dist/models-dev-MDI5E2YA.js +0 -3
- package/dist/provider-registry-4PH2JPIA.cjs +0 -40
- package/dist/provider-registry-VEJ3PN4S.js +0 -3
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import EventEmitter from 'events';
|
|
2
|
+
|
|
3
|
+
// src/events/pubsub.ts
|
|
4
|
+
var PubSub = class {
|
|
5
|
+
};
|
|
6
|
+
var EventEmitterPubSub = class extends PubSub {
|
|
7
|
+
emitter;
|
|
8
|
+
constructor(existingEmitter) {
|
|
9
|
+
super();
|
|
10
|
+
this.emitter = existingEmitter ?? new EventEmitter();
|
|
11
|
+
}
|
|
12
|
+
async publish(topic, event) {
|
|
13
|
+
const id = crypto.randomUUID();
|
|
14
|
+
const createdAt = /* @__PURE__ */ new Date();
|
|
15
|
+
this.emitter.emit(topic, {
|
|
16
|
+
...event,
|
|
17
|
+
id,
|
|
18
|
+
createdAt
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
async subscribe(topic, cb) {
|
|
22
|
+
this.emitter.on(topic, cb);
|
|
23
|
+
}
|
|
24
|
+
async unsubscribe(topic, cb) {
|
|
25
|
+
this.emitter.off(topic, cb);
|
|
26
|
+
}
|
|
27
|
+
async flush() {
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Clean up all listeners during graceful shutdown.
|
|
31
|
+
*/
|
|
32
|
+
async close() {
|
|
33
|
+
this.emitter.removeAllListeners();
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export { EventEmitterPubSub, PubSub };
|
|
38
|
+
//# sourceMappingURL=chunk-X2HAI3OX.js.map
|
|
39
|
+
//# sourceMappingURL=chunk-X2HAI3OX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/events/pubsub.ts","../src/events/event-emitter.ts"],"names":[],"mappings":";;;AAEO,IAAe,SAAf,MAAsB;AAK7B;ACHO,IAAM,kBAAA,GAAN,cAAiC,MAAA,CAAO;AAAA,EACrC,OAAA;AAAA,EAER,YAAY,eAAA,EAAgC;AAC1C,IAAA,KAAA,EAAM;AACN,IAAA,IAAA,CAAK,OAAA,GAAU,eAAA,IAAmB,IAAI,YAAA,EAAa;AAAA,EACrD;AAAA,EAEA,MAAM,OAAA,CAAQ,KAAA,EAAe,KAAA,EAAuD;AAClF,IAAA,MAAM,EAAA,GAAK,OAAO,UAAA,EAAW;AAC7B,IAAA,MAAM,SAAA,uBAAgB,IAAA,EAAK;AAC3B,IAAA,IAAA,CAAK,OAAA,CAAQ,KAAK,KAAA,EAAO;AAAA,MACvB,GAAG,KAAA;AAAA,MACH,EAAA;AAAA,MACA;AAAA,KACD,CAAA;AAAA,EACH;AAAA,EAEA,MAAM,SAAA,CAAU,KAAA,EAAe,EAAA,EAAsE;AACnG,IAAA,IAAA,CAAK,OAAA,CAAQ,EAAA,CAAG,KAAA,EAAO,EAAE,CAAA;AAAA,EAC3B;AAAA,EAEA,MAAM,WAAA,CAAY,KAAA,EAAe,EAAA,EAAsE;AACrG,IAAA,IAAA,CAAK,OAAA,CAAQ,GAAA,CAAI,KAAA,EAAO,EAAE,CAAA;AAAA,EAC5B;AAAA,EAEA,MAAM,KAAA,GAAuB;AAAA,EAE7B;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,KAAA,GAAuB;AAC3B,IAAA,IAAA,CAAK,QAAQ,kBAAA,EAAmB;AAAA,EAClC;AACF","file":"chunk-X2HAI3OX.js","sourcesContent":["import type { Event } from './types';\n\nexport abstract class PubSub {\n abstract publish(topic: string, event: Omit<Event, 'id' | 'createdAt'>): Promise<void>;\n abstract subscribe(topic: string, cb: (event: Event, ack?: () => Promise<void>) => void): Promise<void>;\n abstract unsubscribe(topic: string, cb: (event: Event, ack?: () => Promise<void>) => void): Promise<void>;\n abstract flush(): Promise<void>;\n}\n","import EventEmitter from 'node:events';\nimport { PubSub } from './pubsub';\nimport type { Event } from './types';\n\nexport class EventEmitterPubSub extends PubSub {\n private emitter: EventEmitter;\n\n constructor(existingEmitter?: EventEmitter) {\n super();\n this.emitter = existingEmitter ?? new EventEmitter();\n }\n\n async publish(topic: string, event: Omit<Event, 'id' | 'createdAt'>): Promise<void> {\n const id = crypto.randomUUID();\n const createdAt = new Date();\n this.emitter.emit(topic, {\n ...event,\n id,\n createdAt,\n });\n }\n\n async subscribe(topic: string, cb: (event: Event, ack?: () => Promise<void>) => void): Promise<void> {\n this.emitter.on(topic, cb);\n }\n\n async unsubscribe(topic: string, cb: (event: Event, ack?: () => Promise<void>) => void): Promise<void> {\n this.emitter.off(topic, cb);\n }\n\n async flush(): Promise<void> {\n // no-op\n }\n\n /**\n * Clean up all listeners during graceful shutdown.\n */\n async close(): Promise<void> {\n this.emitter.removeAllListeners();\n }\n}\n"]}
|
|
@@ -13,6 +13,7 @@ import * as childProcess from 'child_process';
|
|
|
13
13
|
import { execFileSync } from 'child_process';
|
|
14
14
|
import * as os from 'os';
|
|
15
15
|
import os__default from 'os';
|
|
16
|
+
import { createRequire } from 'module';
|
|
16
17
|
import { z } from 'zod';
|
|
17
18
|
|
|
18
19
|
// src/workspace/errors.ts
|
|
@@ -4746,7 +4747,8 @@ var WORKSPACE_TOOLS = {
|
|
|
4746
4747
|
DELETE: `${WORKSPACE_TOOLS_PREFIX}_delete`,
|
|
4747
4748
|
FILE_STAT: `${WORKSPACE_TOOLS_PREFIX}_file_stat`,
|
|
4748
4749
|
MKDIR: `${WORKSPACE_TOOLS_PREFIX}_mkdir`,
|
|
4749
|
-
GREP: `${WORKSPACE_TOOLS_PREFIX}_grep
|
|
4750
|
+
GREP: `${WORKSPACE_TOOLS_PREFIX}_grep`,
|
|
4751
|
+
AST_EDIT: `${WORKSPACE_TOOLS_PREFIX}_ast_edit`
|
|
4750
4752
|
},
|
|
4751
4753
|
SANDBOX: {
|
|
4752
4754
|
EXECUTE_COMMAND: `${WORKSPACE_TOOLS_PREFIX}_execute_command`
|
|
@@ -4788,7 +4790,318 @@ async function emitWorkspaceMetadata(context, toolName) {
|
|
|
4788
4790
|
});
|
|
4789
4791
|
}
|
|
4790
4792
|
|
|
4791
|
-
// src/workspace/tools/
|
|
4793
|
+
// src/workspace/tools/ast-edit.ts
|
|
4794
|
+
var astGrepModule;
|
|
4795
|
+
var loadingPromise;
|
|
4796
|
+
async function loadAstGrep() {
|
|
4797
|
+
if (astGrepModule !== void 0) {
|
|
4798
|
+
return astGrepModule;
|
|
4799
|
+
}
|
|
4800
|
+
if (!loadingPromise) {
|
|
4801
|
+
loadingPromise = (async () => {
|
|
4802
|
+
try {
|
|
4803
|
+
const moduleName = "@ast-grep/napi";
|
|
4804
|
+
const mod = await import(
|
|
4805
|
+
/* webpackIgnore: true */
|
|
4806
|
+
moduleName
|
|
4807
|
+
);
|
|
4808
|
+
astGrepModule = { parse: mod.parse, Lang: mod.Lang };
|
|
4809
|
+
return astGrepModule;
|
|
4810
|
+
} catch {
|
|
4811
|
+
astGrepModule = null;
|
|
4812
|
+
return null;
|
|
4813
|
+
}
|
|
4814
|
+
})();
|
|
4815
|
+
}
|
|
4816
|
+
return loadingPromise;
|
|
4817
|
+
}
|
|
4818
|
+
function isAstGrepAvailable() {
|
|
4819
|
+
if (astGrepModule !== void 0) {
|
|
4820
|
+
return astGrepModule !== null;
|
|
4821
|
+
}
|
|
4822
|
+
try {
|
|
4823
|
+
const req = createRequire(import.meta.url);
|
|
4824
|
+
req.resolve("@ast-grep/napi");
|
|
4825
|
+
return true;
|
|
4826
|
+
} catch {
|
|
4827
|
+
return false;
|
|
4828
|
+
}
|
|
4829
|
+
}
|
|
4830
|
+
function getLanguageFromPath(filePath, Lang) {
|
|
4831
|
+
const ext = filePath.split(".").pop()?.toLowerCase();
|
|
4832
|
+
switch (ext) {
|
|
4833
|
+
case "ts":
|
|
4834
|
+
return Lang.TypeScript;
|
|
4835
|
+
case "tsx":
|
|
4836
|
+
case "jsx":
|
|
4837
|
+
return Lang.Tsx;
|
|
4838
|
+
case "js":
|
|
4839
|
+
return Lang.JavaScript;
|
|
4840
|
+
case "html":
|
|
4841
|
+
return Lang.Html;
|
|
4842
|
+
case "css":
|
|
4843
|
+
return Lang.Css;
|
|
4844
|
+
default:
|
|
4845
|
+
return null;
|
|
4846
|
+
}
|
|
4847
|
+
}
|
|
4848
|
+
function escapeRegex(str) {
|
|
4849
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
4850
|
+
}
|
|
4851
|
+
function renameIdentifiers(content, root, oldName, newName) {
|
|
4852
|
+
let modifiedContent = content;
|
|
4853
|
+
let count = 0;
|
|
4854
|
+
const identifiers = root.findAll({
|
|
4855
|
+
rule: {
|
|
4856
|
+
kind: "identifier",
|
|
4857
|
+
regex: `^${escapeRegex(oldName)}$`
|
|
4858
|
+
}
|
|
4859
|
+
});
|
|
4860
|
+
const replacements = [];
|
|
4861
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4862
|
+
for (const id of identifiers) {
|
|
4863
|
+
const range = id.range();
|
|
4864
|
+
if (seen.has(range.start.index)) continue;
|
|
4865
|
+
seen.add(range.start.index);
|
|
4866
|
+
replacements.push({ start: range.start.index, end: range.end.index, text: newName });
|
|
4867
|
+
count++;
|
|
4868
|
+
}
|
|
4869
|
+
replacements.sort((a, b) => b.start - a.start);
|
|
4870
|
+
for (const { start, end, text } of replacements) {
|
|
4871
|
+
modifiedContent = modifiedContent.slice(0, start) + text + modifiedContent.slice(end);
|
|
4872
|
+
}
|
|
4873
|
+
return { content: modifiedContent, count };
|
|
4874
|
+
}
|
|
4875
|
+
function buildImportStatement(defaultName, namedImports, moduleStr) {
|
|
4876
|
+
if (defaultName && namedImports.length > 0) {
|
|
4877
|
+
return `import ${defaultName}, { ${namedImports.join(", ")} } from ${moduleStr};`;
|
|
4878
|
+
} else if (defaultName) {
|
|
4879
|
+
return `import ${defaultName} from ${moduleStr};`;
|
|
4880
|
+
} else {
|
|
4881
|
+
return `import { ${namedImports.join(", ")} } from ${moduleStr};`;
|
|
4882
|
+
}
|
|
4883
|
+
}
|
|
4884
|
+
function mergeIntoExistingImport(content, existingImport, names, isDefault) {
|
|
4885
|
+
const text = existingImport.text();
|
|
4886
|
+
if (/^import\s+\*\s+as\s+/.test(text)) return null;
|
|
4887
|
+
const defaultMatch = text.match(/^import\s+(?!type\s)(?!\{)(\w+)/);
|
|
4888
|
+
const namedMatch = text.match(/\{([^}]*)\}/);
|
|
4889
|
+
const moduleMatch = text.match(/(["'][^"']+["'])\s*;?\s*$/);
|
|
4890
|
+
if (!moduleMatch) return null;
|
|
4891
|
+
const moduleStr = moduleMatch[1] ?? "";
|
|
4892
|
+
let existingDefault = defaultMatch ? defaultMatch[1] ?? null : null;
|
|
4893
|
+
const existingNamed = namedMatch ? (namedMatch[1] ?? "").split(",").map((s) => s.trim()).filter(Boolean) : [];
|
|
4894
|
+
let newDefault = existingDefault;
|
|
4895
|
+
const newNamed = [...existingNamed];
|
|
4896
|
+
if (isDefault && names.length > 0) {
|
|
4897
|
+
if (!existingDefault) {
|
|
4898
|
+
newDefault = names[0] ?? null;
|
|
4899
|
+
}
|
|
4900
|
+
for (const name of names.slice(1)) {
|
|
4901
|
+
if (!newNamed.includes(name)) {
|
|
4902
|
+
newNamed.push(name);
|
|
4903
|
+
}
|
|
4904
|
+
}
|
|
4905
|
+
} else {
|
|
4906
|
+
for (const name of names) {
|
|
4907
|
+
if (!newNamed.includes(name)) {
|
|
4908
|
+
newNamed.push(name);
|
|
4909
|
+
}
|
|
4910
|
+
}
|
|
4911
|
+
}
|
|
4912
|
+
const defaultChanged = newDefault !== existingDefault;
|
|
4913
|
+
const namedChanged = newNamed.length !== existingNamed.length;
|
|
4914
|
+
if (!defaultChanged && !namedChanged) return null;
|
|
4915
|
+
const importStatement = buildImportStatement(newDefault, newNamed, moduleStr);
|
|
4916
|
+
const range = existingImport.range();
|
|
4917
|
+
return content.slice(0, range.start.index) + importStatement + content.slice(range.end.index);
|
|
4918
|
+
}
|
|
4919
|
+
function addImport(content, root, importSpec) {
|
|
4920
|
+
const { module, names, isDefault } = importSpec;
|
|
4921
|
+
const imports = root.findAll({ rule: { kind: "import_statement" } });
|
|
4922
|
+
const existingImport = imports.find((imp) => {
|
|
4923
|
+
const text = imp.text();
|
|
4924
|
+
if (/^import\s+type\s/.test(text)) return false;
|
|
4925
|
+
if (/^import\s+\*\s+as\s+/.test(text)) return false;
|
|
4926
|
+
return text.includes(`'${module}'`) || text.includes(`"${module}"`);
|
|
4927
|
+
});
|
|
4928
|
+
if (existingImport) {
|
|
4929
|
+
return mergeIntoExistingImport(content, existingImport, names, isDefault) ?? content;
|
|
4930
|
+
}
|
|
4931
|
+
const moduleStr = `'${module}'`;
|
|
4932
|
+
const importStatement = buildImportStatement(
|
|
4933
|
+
isDefault ? names[0] : null,
|
|
4934
|
+
isDefault ? names.slice(1) : names,
|
|
4935
|
+
moduleStr
|
|
4936
|
+
);
|
|
4937
|
+
const lastImport = imports.at(-1);
|
|
4938
|
+
if (lastImport) {
|
|
4939
|
+
const pos = lastImport.range().end.index;
|
|
4940
|
+
return content.slice(0, pos) + "\n" + importStatement + content.slice(pos);
|
|
4941
|
+
} else {
|
|
4942
|
+
return importStatement + "\n\n" + content;
|
|
4943
|
+
}
|
|
4944
|
+
}
|
|
4945
|
+
function removeImport(content, root, targetName) {
|
|
4946
|
+
const imports = root.findAll({ rule: { kind: "import_statement" } });
|
|
4947
|
+
for (const imp of imports) {
|
|
4948
|
+
const text = imp.text();
|
|
4949
|
+
if (text.includes(`'${targetName}'`) || text.includes(`"${targetName}"`)) {
|
|
4950
|
+
const range = imp.range();
|
|
4951
|
+
const start = range.start.index;
|
|
4952
|
+
let end = range.end.index;
|
|
4953
|
+
if (content[end] === "\n") end++;
|
|
4954
|
+
return content.slice(0, start) + content.slice(end);
|
|
4955
|
+
}
|
|
4956
|
+
}
|
|
4957
|
+
return content;
|
|
4958
|
+
}
|
|
4959
|
+
function patternReplace(content, root, pattern, replacement) {
|
|
4960
|
+
let modifiedContent = content;
|
|
4961
|
+
let count = 0;
|
|
4962
|
+
try {
|
|
4963
|
+
const matches = root.findAll({ rule: { pattern } });
|
|
4964
|
+
const replacements = [];
|
|
4965
|
+
const metaVars = [...pattern.matchAll(/\$(\w+)/g)].map((m) => m[1]).filter((v) => v !== void 0);
|
|
4966
|
+
for (const match of matches) {
|
|
4967
|
+
const range = match.range();
|
|
4968
|
+
let replacementText = replacement;
|
|
4969
|
+
for (const varName of metaVars) {
|
|
4970
|
+
const matchedNode = match.getMatch(varName);
|
|
4971
|
+
if (matchedNode) {
|
|
4972
|
+
replacementText = replacementText.replace(new RegExp(`\\$${varName}`, "g"), matchedNode.text());
|
|
4973
|
+
}
|
|
4974
|
+
}
|
|
4975
|
+
replacements.push({ start: range.start.index, end: range.end.index, text: replacementText });
|
|
4976
|
+
count++;
|
|
4977
|
+
}
|
|
4978
|
+
replacements.sort((a, b) => b.start - a.start);
|
|
4979
|
+
for (const { start, end, text } of replacements) {
|
|
4980
|
+
modifiedContent = modifiedContent.slice(0, start) + text + modifiedContent.slice(end);
|
|
4981
|
+
}
|
|
4982
|
+
} catch (err) {
|
|
4983
|
+
return {
|
|
4984
|
+
content: modifiedContent,
|
|
4985
|
+
count: 0,
|
|
4986
|
+
error: err instanceof Error ? err.message : "Pattern matching failed"
|
|
4987
|
+
};
|
|
4988
|
+
}
|
|
4989
|
+
return { content: modifiedContent, count };
|
|
4990
|
+
}
|
|
4991
|
+
var astEditTool = createTool({
|
|
4992
|
+
id: WORKSPACE_TOOLS.FILESYSTEM.AST_EDIT,
|
|
4993
|
+
description: `Edit code using AST-based analysis for intelligent transformations.
|
|
4994
|
+
|
|
4995
|
+
Use \`transform\` for structured operations (imports, renames). Use \`pattern\`/\`replacement\` only for general find-and-replace.
|
|
4996
|
+
|
|
4997
|
+
Transforms:
|
|
4998
|
+
- add-import: Add or merge imports. Skips duplicates. For default imports, put the default name first in \`names\`.
|
|
4999
|
+
{ transform: "add-import", importSpec: { module: "react", names: ["useState", "useEffect"] } }
|
|
5000
|
+
{ transform: "add-import", importSpec: { module: "express", names: ["express"], isDefault: true } }
|
|
5001
|
+
{ transform: "add-import", importSpec: { module: "express", names: ["express", "Router"], isDefault: true } } \u2192 import express, { Router } from 'express'
|
|
5002
|
+
- remove-import: Remove an import by module name.
|
|
5003
|
+
{ transform: "remove-import", targetName: "lodash" }
|
|
5004
|
+
- rename: Rename all occurrences of an identifier (not scope-aware).
|
|
5005
|
+
{ transform: "rename", targetName: "oldName", newName: "newName" }
|
|
5006
|
+
|
|
5007
|
+
Pattern replace (for everything else):
|
|
5008
|
+
{ pattern: "console.log($ARG)", replacement: "logger.debug($ARG)" }`,
|
|
5009
|
+
inputSchema: z.object({
|
|
5010
|
+
path: z.string().describe("The path to the file to edit"),
|
|
5011
|
+
pattern: z.string().optional().describe('AST pattern to search for (supports $VARIABLE placeholders, e.g., "console.log($ARG)")'),
|
|
5012
|
+
replacement: z.string().optional().describe('Replacement pattern (can use captured $VARIABLES, e.g., "logger.debug($ARG)")'),
|
|
5013
|
+
transform: z.enum(["add-import", "remove-import", "rename"]).optional().describe("Structured transformation to apply"),
|
|
5014
|
+
targetName: z.string().optional().describe("Required for remove-import and rename transforms. The current name to target."),
|
|
5015
|
+
newName: z.string().optional().describe("Required for rename transform. The new name to replace targetName with."),
|
|
5016
|
+
importSpec: z.object({
|
|
5017
|
+
module: z.string().describe("Module to import from"),
|
|
5018
|
+
names: z.array(z.string()).min(1).describe("Names to import. For default imports, put the default name first."),
|
|
5019
|
+
isDefault: z.boolean().optional().describe("Whether the first name is a default import")
|
|
5020
|
+
}).optional().describe("Required for add-import transform. Specifies the module and names to import.")
|
|
5021
|
+
}),
|
|
5022
|
+
execute: async ({ path: path4, pattern, replacement, transform, targetName, newName, importSpec }, context) => {
|
|
5023
|
+
const { filesystem } = requireFilesystem(context);
|
|
5024
|
+
await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.FILESYSTEM.AST_EDIT);
|
|
5025
|
+
if (filesystem.readOnly) {
|
|
5026
|
+
throw new WorkspaceReadOnlyError("ast_edit");
|
|
5027
|
+
}
|
|
5028
|
+
const astGrep = await loadAstGrep();
|
|
5029
|
+
if (!astGrep) {
|
|
5030
|
+
return "@ast-grep/napi is not available. Install it to use AST editing.";
|
|
5031
|
+
}
|
|
5032
|
+
const { parse, Lang } = astGrep;
|
|
5033
|
+
let content;
|
|
5034
|
+
try {
|
|
5035
|
+
content = await filesystem.readFile(path4, { encoding: "utf-8" });
|
|
5036
|
+
} catch (error) {
|
|
5037
|
+
if (error instanceof FileNotFoundError) {
|
|
5038
|
+
return `File not found: ${path4}. Use ${WORKSPACE_TOOLS.FILESYSTEM.WRITE_FILE} to create it first.`;
|
|
5039
|
+
}
|
|
5040
|
+
throw error;
|
|
5041
|
+
}
|
|
5042
|
+
if (typeof content !== "string") {
|
|
5043
|
+
return `Cannot perform AST edits on binary files. Use ${WORKSPACE_TOOLS.FILESYSTEM.WRITE_FILE} instead.`;
|
|
5044
|
+
}
|
|
5045
|
+
const lang = getLanguageFromPath(path4, Lang);
|
|
5046
|
+
if (!lang) {
|
|
5047
|
+
return `Unsupported file type for AST editing: ${path4}`;
|
|
5048
|
+
}
|
|
5049
|
+
const ast = parse(lang, content);
|
|
5050
|
+
const root = ast.root();
|
|
5051
|
+
let modifiedContent = content;
|
|
5052
|
+
const changes = [];
|
|
5053
|
+
if (transform) {
|
|
5054
|
+
switch (transform) {
|
|
5055
|
+
case "add-import": {
|
|
5056
|
+
if (!importSpec) {
|
|
5057
|
+
return "Error: importSpec is required for add-import transform";
|
|
5058
|
+
}
|
|
5059
|
+
modifiedContent = addImport(content, root, importSpec);
|
|
5060
|
+
changes.push(`Added import from '${importSpec.module}'`);
|
|
5061
|
+
break;
|
|
5062
|
+
}
|
|
5063
|
+
case "remove-import": {
|
|
5064
|
+
if (!targetName) {
|
|
5065
|
+
return "Error: targetName is required for remove-import transform";
|
|
5066
|
+
}
|
|
5067
|
+
modifiedContent = removeImport(content, root, targetName);
|
|
5068
|
+
changes.push(`Removed import '${targetName}'`);
|
|
5069
|
+
break;
|
|
5070
|
+
}
|
|
5071
|
+
case "rename": {
|
|
5072
|
+
if (!targetName || !newName) {
|
|
5073
|
+
return "Error: targetName and newName are required for rename transform";
|
|
5074
|
+
}
|
|
5075
|
+
const renameResult = renameIdentifiers(content, root, targetName, newName);
|
|
5076
|
+
modifiedContent = renameResult.content;
|
|
5077
|
+
changes.push(`Renamed '${targetName}' to '${newName}' (${renameResult.count} occurrences)`);
|
|
5078
|
+
break;
|
|
5079
|
+
}
|
|
5080
|
+
}
|
|
5081
|
+
} else if (pattern && replacement !== void 0) {
|
|
5082
|
+
const result = patternReplace(content, root, pattern, replacement);
|
|
5083
|
+
if (result.error) {
|
|
5084
|
+
return `Error: AST pattern matching failed: ${result.error}`;
|
|
5085
|
+
}
|
|
5086
|
+
modifiedContent = result.content;
|
|
5087
|
+
changes.push(`Replaced ${result.count} occurrences of pattern`);
|
|
5088
|
+
} else if (pattern && replacement === void 0) {
|
|
5089
|
+
return "Error: replacement is required when pattern is provided";
|
|
5090
|
+
} else if (!pattern && replacement !== void 0) {
|
|
5091
|
+
return "Error: pattern is required when replacement is provided";
|
|
5092
|
+
} else {
|
|
5093
|
+
return "Error: Must provide either transform or pattern/replacement";
|
|
5094
|
+
}
|
|
5095
|
+
const wasModified = modifiedContent !== content;
|
|
5096
|
+
if (wasModified) {
|
|
5097
|
+
await filesystem.writeFile(path4, modifiedContent, { overwrite: true });
|
|
5098
|
+
}
|
|
5099
|
+
if (!wasModified) {
|
|
5100
|
+
return `No changes made to ${path4} (${changes.join("; ")})`;
|
|
5101
|
+
}
|
|
5102
|
+
return `${path4}: ${changes.join("; ")}`;
|
|
5103
|
+
}
|
|
5104
|
+
});
|
|
4792
5105
|
var deleteFileTool = createTool({
|
|
4793
5106
|
id: WORKSPACE_TOOLS.FILESYSTEM.DELETE,
|
|
4794
5107
|
description: "Delete a file or directory from the workspace filesystem",
|
|
@@ -5448,7 +5761,8 @@ function createWorkspaceTools(workspace) {
|
|
|
5448
5761
|
let readTracker;
|
|
5449
5762
|
const writeFileConfig = resolveToolConfig(toolsConfig, WORKSPACE_TOOLS.FILESYSTEM.WRITE_FILE);
|
|
5450
5763
|
const editFileConfig = resolveToolConfig(toolsConfig, WORKSPACE_TOOLS.FILESYSTEM.EDIT_FILE);
|
|
5451
|
-
|
|
5764
|
+
const astEditConfig = resolveToolConfig(toolsConfig, WORKSPACE_TOOLS.FILESYSTEM.AST_EDIT);
|
|
5765
|
+
if (writeFileConfig.requireReadBeforeWrite || editFileConfig.requireReadBeforeWrite || astEditConfig.requireReadBeforeWrite) {
|
|
5452
5766
|
readTracker = new InMemoryFileReadTracker();
|
|
5453
5767
|
}
|
|
5454
5768
|
const addTool = (name, tool, opts) => {
|
|
@@ -5476,6 +5790,12 @@ function createWorkspaceTools(workspace) {
|
|
|
5476
5790
|
addTool(WORKSPACE_TOOLS.FILESYSTEM.FILE_STAT, fileStatTool);
|
|
5477
5791
|
addTool(WORKSPACE_TOOLS.FILESYSTEM.MKDIR, mkdirTool, { requireWrite: true });
|
|
5478
5792
|
addTool(WORKSPACE_TOOLS.FILESYSTEM.GREP, grepTool);
|
|
5793
|
+
if (isAstGrepAvailable()) {
|
|
5794
|
+
addTool(WORKSPACE_TOOLS.FILESYSTEM.AST_EDIT, astEditTool, {
|
|
5795
|
+
requireWrite: true,
|
|
5796
|
+
readTrackerMode: "write"
|
|
5797
|
+
});
|
|
5798
|
+
}
|
|
5479
5799
|
}
|
|
5480
5800
|
if (workspace.canBM25 || workspace.canVector) {
|
|
5481
5801
|
addTool(WORKSPACE_TOOLS.SEARCH.SEARCH, searchTool);
|
|
@@ -5499,5 +5819,5 @@ ${pathContext.instructions}` : "";
|
|
|
5499
5819
|
}
|
|
5500
5820
|
|
|
5501
5821
|
export { BM25Index, CompositeFilesystem, CompositeVersionedSkillSource, DirectoryNotEmptyError, DirectoryNotFoundError, FileExistsError, FileNotFoundError, FileReadRequiredError, FilesystemError, FilesystemNotAvailableError, FilesystemNotMountableError, FilesystemNotReadyError, IsDirectoryError, IsolationUnavailableError, LocalFilesystem, LocalSandbox, LocalSkillSource, MastraFilesystem, MastraSandbox, MountError, MountManager, MountNotSupportedError, NotDirectoryError, PermissionError, SandboxError, SandboxExecutionError, SandboxFeatureNotSupportedError, SandboxNotAvailableError, SandboxNotReadyError, SandboxTimeoutError, SearchNotAvailableError, VersionedSkillSource, WORKSPACE_TOOLS, WORKSPACE_TOOLS_PREFIX, Workspace, WorkspaceError, WorkspaceNotAvailableError, WorkspaceNotReadyError, WorkspaceReadOnlyError, callLifecycle, collectSkillForPublish, createGlobMatcher, createWorkspaceTools, deleteFileTool, detectIsolation, editFileTool, executeCommandTool, extractGlobBase, extractLines, fileStatTool, getRecommendedIsolation, indexContentTool, isGlobPattern, isIsolationAvailable, listFilesTool, matchGlob, mkdirTool, publishSkillFromSource, readFileTool, requireFilesystem, requireSandbox, requireWorkspace, resolveToolConfig, searchTool, writeFileTool };
|
|
5502
|
-
//# sourceMappingURL=chunk-
|
|
5503
|
-
//# sourceMappingURL=chunk-
|
|
5822
|
+
//# sourceMappingURL=chunk-XB3DA67Q.js.map
|
|
5823
|
+
//# sourceMappingURL=chunk-XB3DA67Q.js.map
|