@h1r-ai/croche-react-native 0.6.0 → 0.7.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/LICENSE +1 -1
- package/README.md +32 -4
- package/THIRD-PARTY-NOTICES +899 -6
- package/android/src/androidTest/java/dev/croche/reactnative/WikiFileBridgeTest.kt +4 -3
- package/android/src/main/AndroidManifest.xml +0 -5
- package/android/src/main/java/dev/croche/reactnative/CoreDispatch.kt +33 -8
- package/android/src/main/java/dev/croche/reactnative/CoreWire.kt +139 -5
- package/android/src/main/java/dev/croche/reactnative/CrocheRuntimeModule.kt +5 -2
- package/android/src/main/java/dev/croche/reactnative/NativePal.kt +23 -6
- package/android/src/test/java/dev/croche/reactnative/AgentMemoryTest.kt +28 -6
- package/android/src/test/java/dev/croche/reactnative/BackgroundDelegationTest.kt +4 -11
- package/android/src/test/java/dev/croche/reactnative/BlobFilesTest.kt +107 -0
- package/android/src/test/java/dev/croche/reactnative/ImageAdapterWireTest.kt +70 -0
- package/android/src/test/java/dev/croche/reactnative/OpenForwardingFixture.kt +19 -4
- package/android/src/test/java/dev/croche/reactnative/ProjectAttestationTest.kt +2 -2
- package/android/src/test/java/dev/croche/reactnative/StorageVersionWireTest.kt +37 -0
- package/android/src/test/java/dev/croche/reactnative/VerificationDispatchTest.kt +24 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/AndroidPlatform.kt +5 -3
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BackgroundWakeWorker.kt +4 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BitmapDecodedImageCodec.kt +11 -11
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BitmapImageCodec.kt +1 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidCoreHost.kt +11 -16
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidPublicPlatform.kt +3 -3
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidStateStore.kt +216 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidStoragePal.kt +45 -10
- package/android/vendor/CrocheRuntimeSDK/consumer-rules.pro +0 -3
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Adapters.kt +75 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/BindingFacts.kt +1 -1
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ContextConfig.kt +9 -23
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Core.kt +11 -2
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Croche.kt +83 -20
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/CrocheAgent.kt +54 -8
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/CrocheRuntime.kt +19 -360
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/CrocheTools.kt +79 -10
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Decision.kt +170 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/DecodedImageCodec.kt +8 -5
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Effects.kt +8 -1
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/EncodedImageCodec.kt +51 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/GeneratedAppStream.kt +426 -33
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Host.kt +1 -351
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Images.kt +15 -29
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/NativeEvent.kt +59 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/NativeHandleOwner.kt +118 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Platform.kt +10 -74
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectTypes.kt +196 -10
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/PublicResults.kt +86 -3
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/RunTool.kt +33 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/SendEncoding.kt +1 -1
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/StateStore.kt +90 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/SubscriptionTypes.kt +68 -4
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ffi/croche_ffi.kt +3403 -6894
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/AppStoragePal.kt +89 -18
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/CoreFactoryCalls.kt +1 -2
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/CoreOptionsEncoding.kt +2 -2
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/CoreStreamCalls.kt +3 -3
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/ForeignCallbacks.kt +17 -18
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/ImageAdapterHost.kt +28 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/JvmCoreHost.kt +12 -14
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/JvmStateStore.kt +125 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/JvmStoragePal.kt +36 -6
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/NativeCoreInitialization.kt +21 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/NativePlatform.kt +21 -6
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/PublicCalls.kt +16 -7
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/StateStoreContract.kt +103 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/StorageVersionContract.kt +40 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/pal/AtomicKeyFiles.kt +25 -4
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/pal/BlobFiles.kt +157 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/pal/InstancePayloadPurge.kt +79 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/pal/VersionedKeyFiles.kt +71 -0
- package/android/vendor/jniLibs/arm64-v8a/libcroche_ffi.so +0 -0
- package/android/vendor/jniLibs/armeabi-v7a/libcroche_ffi.so +0 -0
- package/android/vendor/jniLibs/x86_64/libcroche_ffi.so +0 -0
- package/croche-react-native.podspec +1 -0
- package/dist/react-native/src/core-native.d.ts +3 -0
- package/dist/react-native/src/core-native.js +148 -25
- package/dist/react-native/src/core-wire.d.ts +20 -3
- package/dist/rn-shared-build.json +8 -8
- package/dist/runtime/src/adapters.d.ts +8 -0
- package/dist/runtime/src/adapters.js +29 -0
- package/dist/runtime/src/agent.d.ts +53 -5
- package/dist/runtime/src/agent.js +69 -7
- package/dist/runtime/src/app-api.d.ts +307 -19
- package/dist/runtime/src/cancel.d.ts +2 -2
- package/dist/runtime/src/cancel.js +7 -4
- package/dist/runtime/src/core/foreground.d.ts +3 -0
- package/dist/runtime/src/core/foreground.js +40 -0
- package/dist/runtime/src/core/port.d.ts +48 -35
- package/dist/runtime/src/core/wasm-owner.d.ts +32 -0
- package/dist/runtime/src/core/wasm-owner.js +237 -0
- package/dist/runtime/src/croche.d.ts +64 -9
- package/dist/runtime/src/croche.js +78 -17
- package/dist/runtime/src/errors.d.ts +7 -0
- package/dist/runtime/src/errors.js +15 -1
- package/dist/runtime/src/generated/app-stream.d.ts +155 -1
- package/dist/runtime/src/generated/app-stream.js +7 -4
- package/dist/runtime/src/image-input.d.ts +5 -0
- package/dist/runtime/src/image-input.js +60 -0
- package/dist/runtime/src/index.d.ts +6 -0
- package/dist/runtime/src/index.js +5 -0
- package/dist/runtime/src/index.native.d.ts +1 -21
- package/dist/runtime/src/index.native.js +2 -8
- package/dist/runtime/src/native-adapter.d.ts +1 -1
- package/dist/runtime/src/native-adapter.js +10 -4
- package/dist/runtime/src/pal/host.d.ts +3 -3
- package/dist/runtime/src/pal/host.js +34 -9
- package/dist/runtime/src/pal/platform.d.ts +11 -6
- package/dist/runtime/src/pal/state-store-lock.d.ts +8 -0
- package/dist/runtime/src/pal/state-store-lock.js +2 -0
- package/dist/runtime/src/pal/state-store.d.ts +66 -0
- package/dist/runtime/src/pal/state-store.js +1 -0
- package/dist/runtime/src/pal/storage-version-contract.d.ts +19 -0
- package/dist/runtime/src/pal/storage-version-contract.js +68 -0
- package/dist/runtime/src/pal/transactional-storage.d.ts +3 -0
- package/dist/runtime/src/pal/transactional-storage.js +124 -0
- package/dist/runtime/src/tools.d.ts +20 -4
- package/dist/runtime/src/tools.js +31 -7
- package/ios/CoreAgentTransport.swift +2 -2
- package/ios/CoreNativePal.swift +26 -21
- package/ios/CorePlatformTransport.swift +4 -4
- package/ios/CoreWireDispatch.swift +38 -8
- package/ios/CoreWireSupport.swift +179 -4
- package/ios/CrocheRuntimeBridge.swift +1 -1
- package/ios/ProjectPal.swift +15 -12
- package/ios/vendor/CrocheRuntimeSDK/BlobFiles.swift +124 -0
- package/ios/vendor/CrocheRuntimeSDK/ContextConfig.swift +2 -6
- package/ios/vendor/CrocheRuntimeSDK/EncodedImages.swift +85 -0
- package/ios/vendor/CrocheRuntimeSDK/FFIStreamPort.swift +1 -174
- package/ios/vendor/CrocheRuntimeSDK/GeneratedAppStream.swift +233 -4
- package/ios/vendor/CrocheRuntimeSDK/Host.swift +1 -399
- package/ios/vendor/CrocheRuntimeSDK/ImagePal.swift +3 -3
- package/ios/vendor/CrocheRuntimeSDK/InstancePayloadPurge.swift +88 -0
- package/ios/vendor/CrocheRuntimeSDK/JSON.swift +26 -10
- package/ios/vendor/CrocheRuntimeSDK/OpenOptions.swift +0 -155
- package/ios/vendor/CrocheRuntimeSDK/Platform.swift +1 -27
- package/ios/vendor/CrocheRuntimeSDK/PlatformBackground.swift +8 -4
- package/ios/vendor/CrocheRuntimeSDK/PlatformPal.swift +57 -21
- package/ios/vendor/CrocheRuntimeSDK/PlatformStateStore.swift +253 -0
- package/ios/vendor/CrocheRuntimeSDK/PlatformStorage.swift +96 -10
- package/ios/vendor/CrocheRuntimeSDK/Project.swift +3 -382
- package/ios/vendor/CrocheRuntimeSDK/Runtime.swift +1 -412
- package/ios/vendor/CrocheRuntimeSDK/RuntimeHTTPAdapter.swift +42 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Adapters.swift +110 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Agent.swift +86 -33
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Allowance.swift +20 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1BindingFacts.swift +1 -1
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Core.swift +12 -3
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Croche.swift +135 -56
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Decision.swift +146 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Events.swift +17 -8
- package/ios/vendor/CrocheRuntimeSDK/S1/S1HandleOwner.swift +58 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Options.swift +184 -15
- package/ios/vendor/CrocheRuntimeSDK/S1/S1RunTool.swift +31 -3
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Storage.swift +131 -61
- package/ios/vendor/CrocheRuntimeSDK/S1/S1TestHooks.swift +10 -15
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Tools.swift +86 -17
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Verification.swift +27 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/StateStoreContract.swift +189 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/StorageVersionContract.swift +68 -0
- package/ios/vendor/CrocheRuntimeSDK/Storage.swift +3 -249
- package/ios/vendor/CrocheRuntimeSDK/SubscriptionTypes.swift +40 -8
- package/ios/vendor/CrocheRuntimeSDK/croche_ffi.swift +1720 -3883
- package/ios/vendor/croche_ffiFFI.xcframework/ios-arm64/Headers/croche_ffiFFI.h +816 -1649
- package/ios/vendor/croche_ffiFFI.xcframework/ios-arm64/libcroche_ffi.a +0 -0
- package/ios/vendor/croche_ffiFFI.xcframework/ios-arm64_x86_64-simulator/Headers/croche_ffiFFI.h +816 -1649
- package/ios/vendor/croche_ffiFFI.xcframework/ios-arm64_x86_64-simulator/libcroche_ffi.a +2 -2
- package/package.json +3 -3
- package/scripts/README.md +1 -1
- package/scripts/check-swift-vendor-modules.sh +15 -0
- package/scripts/vendor-native.sh +4 -3
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/CrocheProjectRecordProvider.kt +0 -32
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/WorkManagerScheduler.kt +0 -146
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/AppStreamBranch.kt +0 -113
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/NativeCoreStreamPort.kt +0 -201
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectPalRouting.kt +0 -25
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectRecords.kt +0 -87
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Storage.kt +0 -181
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/StoragePal.kt +0 -18
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/StreamHub.kt +0 -252
- package/dist/runtime/src/pal/codec.d.ts +0 -15
- package/dist/runtime/src/pal/codec.js +0 -52
- package/ios/vendor/CrocheRuntimeSDK/Background.swift +0 -59
- package/ios/vendor/CrocheRuntimeSDK/StreamHub.swift +0 -496
- package/ios/vendor/CrocheRuntimeSDK/SubscriptionRuntime.swift +0 -44
|
@@ -2,14 +2,21 @@ export type { RunToolResult } from './run-tool.js';
|
|
|
2
2
|
export type { ErrorCategory } from './errors.js';
|
|
3
3
|
import type { AgentEvent } from './generated/app-stream.js';
|
|
4
4
|
export type { Attachment, AgentEvent, InputDisposition, MessageEnd, EventError, SendReceipt, RequestResult } from './generated/app-stream.js';
|
|
5
|
+
/** JSON values accepted by the SDK. Use strings for integer IDs beyond the JavaScript safe integer range. */
|
|
5
6
|
export type Json = null | boolean | number | string | Json[] | {
|
|
6
7
|
[k: string]: Json;
|
|
7
8
|
};
|
|
9
|
+
/** Tool metadata and commands supplied to defineTool. Core validates the manifest. */
|
|
8
10
|
export interface ToolManifest {
|
|
11
|
+
/** Manifest grammar version. The current version is 1. */
|
|
9
12
|
manifestVersion: 1 | (number & {});
|
|
13
|
+
/** Name by which the tool is registered and selected. */
|
|
10
14
|
name: string;
|
|
15
|
+
/** Short explanation of what the tool does. */
|
|
11
16
|
summary: string;
|
|
17
|
+
/** Optional instructions for use of the tool. */
|
|
12
18
|
guide?: string;
|
|
19
|
+
/** Commands exposed by this tool, with their routes, arguments and optional timeouts. */
|
|
13
20
|
commands: Array<{
|
|
14
21
|
key: string;
|
|
15
22
|
summary: string;
|
|
@@ -20,35 +27,64 @@ export interface ToolManifest {
|
|
|
20
27
|
flags?: ToolArg[];
|
|
21
28
|
}>;
|
|
22
29
|
}
|
|
30
|
+
/** Argument definition in a tool manifest. Core validates it. */
|
|
23
31
|
export interface ToolArg {
|
|
32
|
+
/** Name used to bind or supply this argument. */
|
|
24
33
|
name: string;
|
|
25
|
-
|
|
34
|
+
/** Argument kind that determines how Core validates its value. */
|
|
35
|
+
type: 'string' | 'integer' | 'number' | 'boolean' | 'duration' | 'attachment' | (string & {});
|
|
36
|
+
/** Whether the command requires a value for this argument. */
|
|
26
37
|
required?: boolean;
|
|
38
|
+
/** When true, the app supplies the argument through a binding and it is hidden from the model. */
|
|
39
|
+
bindOnly?: boolean;
|
|
40
|
+
/** List of allowed argument values. */
|
|
27
41
|
enum?: Json[];
|
|
42
|
+
/** Value to use when no value is supplied. */
|
|
28
43
|
default?: Json;
|
|
44
|
+
/** Explanation for the argument in the tool's schema. */
|
|
29
45
|
description?: string;
|
|
30
46
|
}
|
|
47
|
+
/** Definition for a built-in or app-defined tool that can be registered with Croche. */
|
|
31
48
|
export interface ToolDefinition {
|
|
49
|
+
/** Name used to identify this tool. */
|
|
32
50
|
readonly name: string;
|
|
33
51
|
}
|
|
52
|
+
/** Let the app apply its own permissions and use its own data for an action the agent requests. */
|
|
34
53
|
export type ToolExecute = (call: ToolCall, ctx: ToolContext) => ToolResult | Json | undefined | void | Promise<ToolResult | Json | undefined | void>;
|
|
54
|
+
/** One command and its arguments passed to an app tool handler. */
|
|
35
55
|
export interface ToolCall {
|
|
56
|
+
/** Command key selected for the call. */
|
|
36
57
|
key: string;
|
|
58
|
+
/** JSON arguments supplied to the handler. */
|
|
37
59
|
args: Record<string, Json>;
|
|
38
60
|
}
|
|
61
|
+
/** Context and attachment access for the current app tool call. */
|
|
39
62
|
export interface ToolContext {
|
|
63
|
+
/** Core-assigned call ID shared by the tool event and associated attachments. */
|
|
40
64
|
callId: string;
|
|
65
|
+
/** ID of the agent invoking this tool. */
|
|
41
66
|
agentId: string;
|
|
67
|
+
/** Named instance, or null when the call is for the main instance. */
|
|
42
68
|
instance: string | null;
|
|
69
|
+
/** User ID, or null when it is absent. */
|
|
43
70
|
user: string | null;
|
|
71
|
+
/** IDs of the inputs that contributed to this call. */
|
|
44
72
|
causedBy: string[];
|
|
73
|
+
/** Signal Core uses to request cancellation of the app tool handler. */
|
|
45
74
|
signal: AbortSignal;
|
|
75
|
+
/** Let an app tool read the file the user shared for that action. */
|
|
76
|
+
attachment(id: string): Promise<{
|
|
77
|
+
mediaType: string;
|
|
78
|
+
data: string;
|
|
79
|
+
}>;
|
|
46
80
|
}
|
|
81
|
+
/** Result value made by toolResult, for returning content or JSON to the agent. */
|
|
47
82
|
export type ToolResult = {
|
|
48
83
|
content: ToolContent[];
|
|
49
84
|
} | {
|
|
50
85
|
json: Json;
|
|
51
86
|
};
|
|
87
|
+
/** Text or image content that a tool can return through toolResult. */
|
|
52
88
|
export type ToolContent = {
|
|
53
89
|
type: 'text';
|
|
54
90
|
text: string;
|
|
@@ -56,11 +92,16 @@ export type ToolContent = {
|
|
|
56
92
|
type: 'image';
|
|
57
93
|
mediaType: string;
|
|
58
94
|
data: string;
|
|
95
|
+
alt?: string;
|
|
96
|
+
attach?: true;
|
|
59
97
|
} | {
|
|
60
98
|
type: 'image';
|
|
61
99
|
mediaType: string;
|
|
62
100
|
uri: string;
|
|
101
|
+
alt?: string;
|
|
102
|
+
attach?: true;
|
|
63
103
|
};
|
|
104
|
+
/** A wiki document supplied inline or addressed by a file. */
|
|
64
105
|
export type WikiDoc = {
|
|
65
106
|
path: string;
|
|
66
107
|
description: string;
|
|
@@ -70,46 +111,104 @@ export type WikiDoc = {
|
|
|
70
111
|
description: string;
|
|
71
112
|
file: string;
|
|
72
113
|
};
|
|
114
|
+
/** Scoped configuration for one tool available to an agent. */
|
|
73
115
|
export interface ToolEntryOptions<T> {
|
|
116
|
+
/** Name of the registered tool. */
|
|
74
117
|
tool: T;
|
|
118
|
+
/** Optional bindings supplied for this scoped tool. */
|
|
75
119
|
bind?: Record<string, Json>;
|
|
120
|
+
/** Optional selection of command keys the agent can use. */
|
|
76
121
|
commands?: string[];
|
|
122
|
+
/** Optional guidance for using this tool in the current scope. */
|
|
77
123
|
guide?: string;
|
|
78
124
|
}
|
|
125
|
+
/** Tool definition alone or with app-supplied bindings. */
|
|
79
126
|
export type ToolRegistration = ToolDefinition | {
|
|
80
127
|
tool: ToolDefinition;
|
|
81
128
|
bind: Record<string, Json>;
|
|
82
129
|
};
|
|
130
|
+
/** List of registered tools with optional command, binding and guidance settings. */
|
|
83
131
|
export type ToolScope = Array<string | ToolEntryOptions<string>>;
|
|
132
|
+
/** List of wiki document paths with optional guidance for the agent. */
|
|
84
133
|
export type WikiScope = Array<string | {
|
|
85
134
|
doc: string;
|
|
86
135
|
guide?: string;
|
|
87
136
|
}>;
|
|
137
|
+
/** Options for opening a conversation from an agent definition. */
|
|
88
138
|
export interface AgentOptions {
|
|
139
|
+
/** Named conversation and its optional configuration patch. */
|
|
89
140
|
instance?: {
|
|
141
|
+
/** Name of the conversation within the agent. */
|
|
90
142
|
id: string;
|
|
143
|
+
/** Optional instance-specific patch passed to Core on open. */
|
|
91
144
|
config?: Json;
|
|
92
145
|
};
|
|
146
|
+
/** Tool scope for this agent handle. */
|
|
93
147
|
tools?: ToolScope | 'all' | null;
|
|
148
|
+
/** Wiki scope for this agent handle. */
|
|
94
149
|
wiki?: WikiScope | 'all' | null;
|
|
95
150
|
}
|
|
151
|
+
/** App and host configuration for opening a Croche session. */
|
|
96
152
|
export interface OpenOptions {
|
|
153
|
+
/** Optional per-instance archive budgets. */
|
|
154
|
+
archive?: {
|
|
155
|
+
/** History byte budget for each agent instance. The Core default is 8 MiB. */
|
|
156
|
+
maxBytes?: number;
|
|
157
|
+
/** Shared archive byte budget for retired summary pieces and saved memory facts per instance. The Core default is 4 MiB. */
|
|
158
|
+
notesMaxBytes?: number;
|
|
159
|
+
};
|
|
160
|
+
/** App-wide input and scheduling guards, for every agent. Code-owned: a bundle cannot set them. */
|
|
161
|
+
limits?: {
|
|
162
|
+
/** Total user and app-event text in one send, in UTF-16 units. The Core default is 32,000. */
|
|
163
|
+
userTextChars?: number;
|
|
164
|
+
/** Total app-state text in one send, in UTF-16 units. The Core default is 32,000. */
|
|
165
|
+
appStateChars?: number;
|
|
166
|
+
/** Maximum length of a tool result value as compact JSON. The Core default is 200,000. */
|
|
167
|
+
toolResultChars?: number;
|
|
168
|
+
/** Images per message or tool result, 1–16 (default 4). Image byte limits stay fixed. */
|
|
169
|
+
turnImages?: number;
|
|
170
|
+
/** Schedule notes pending at once, 1–20 (default 20). */
|
|
171
|
+
pendingSchedules?: number;
|
|
172
|
+
};
|
|
173
|
+
/** Keep enough recent stream records for users to replay after reopening. */
|
|
174
|
+
retentionBytes?: number;
|
|
175
|
+
/** Total storage budget for the user’s named instances. Core defaults to 32 MiB. */
|
|
176
|
+
instanceMaxBytes?: number;
|
|
177
|
+
/** Largest app wiki document in markdown bytes; a larger one is refused, so split it. Core defaults to 64 KiB. */
|
|
178
|
+
wikiDocumentMaxBytes?: number;
|
|
179
|
+
/** Total bytes the app wiki may hold in memory: each document's markdown, path and description. Core defaults to 8 MiB. */
|
|
180
|
+
wikiMaxBytes?: number;
|
|
181
|
+
/** Public project key identifying the Croche project. */
|
|
97
182
|
projectKey: string;
|
|
183
|
+
/** Optional user ID for the session. Core validates it for the selected access path. */
|
|
98
184
|
user?: string;
|
|
185
|
+
/** Optional language preference supplied to Core. */
|
|
99
186
|
language?: string;
|
|
187
|
+
/** Bundled project and agent configuration supplied to Core. */
|
|
100
188
|
bundledConfig: Json;
|
|
189
|
+
/** Tool definitions registered by the app. */
|
|
101
190
|
tools?: ToolRegistration[];
|
|
191
|
+
/** Wiki documents supplied with this session. */
|
|
102
192
|
wiki?: WikiDoc[];
|
|
103
|
-
|
|
193
|
+
/** Host adapters to supply for this session. */
|
|
194
|
+
adapters?: readonly Adapter[];
|
|
195
|
+
/** Optional platform-owned handle used by the host integration. */
|
|
104
196
|
platform?: PlatformHandle;
|
|
197
|
+
/** Optional credential for a trusted server host. */
|
|
105
198
|
serverKey?: string;
|
|
106
|
-
|
|
199
|
+
/** Optional development key, used while developing the app. */
|
|
200
|
+
developmentKey?: string;
|
|
107
201
|
}
|
|
202
|
+
/** Evidence and question selection for a decision call. */
|
|
108
203
|
export interface DecideInput {
|
|
204
|
+
/** Optional correlation ID for this decision call. Reusing it after completion can make another paid call. */
|
|
109
205
|
id?: string;
|
|
206
|
+
/** JSON evidence presented to the decision model. */
|
|
110
207
|
state: Json;
|
|
208
|
+
/** Question references for this call. Omit the list to use the configured questions. */
|
|
111
209
|
questions?: Array<string | DecisionQuestion>;
|
|
112
210
|
}
|
|
211
|
+
/** A decision question whose ID identifies its answer in the result. */
|
|
113
212
|
export type DecisionQuestion = {
|
|
114
213
|
id: string;
|
|
115
214
|
} & ({
|
|
@@ -131,10 +230,14 @@ export type DecisionQuestion = {
|
|
|
131
230
|
instructions: string;
|
|
132
231
|
criteria: string[];
|
|
133
232
|
});
|
|
233
|
+
/** Confidence value with the method used to obtain it. */
|
|
134
234
|
export interface DecisionConfidence {
|
|
235
|
+
/** Numeric confidence reported with the answer. */
|
|
135
236
|
value: number;
|
|
237
|
+
/** Method label accompanying the confidence. */
|
|
136
238
|
method: 'typesafe' | 'p_max' | (string & {});
|
|
137
239
|
}
|
|
240
|
+
/** Boolean, choice or numeric answer, a refusal, or an unfamiliar answer type returned by Core. */
|
|
138
241
|
export type DecisionAnswer = {
|
|
139
242
|
type: 'noul';
|
|
140
243
|
value: boolean;
|
|
@@ -158,35 +261,62 @@ export type DecisionAnswer = {
|
|
|
158
261
|
originalType: string;
|
|
159
262
|
fields: Json;
|
|
160
263
|
};
|
|
264
|
+
/** Answers and usage information returned by a decision call. */
|
|
161
265
|
export interface DecisionResult {
|
|
266
|
+
/** Correlation ID for the decision call. */
|
|
162
267
|
id: string;
|
|
268
|
+
/** Model recorded for the decision. */
|
|
163
269
|
model: string;
|
|
270
|
+
/** Answers and refusals keyed by question ID. */
|
|
164
271
|
answers: Record<string, DecisionAnswer>;
|
|
272
|
+
/** Serving provider, when available. */
|
|
165
273
|
provider?: string;
|
|
274
|
+
/** Usage information recorded for this call. */
|
|
166
275
|
usage: Json;
|
|
276
|
+
/** Recorded call cost in credits, or null when unavailable. */
|
|
167
277
|
cost: number | null;
|
|
278
|
+
/** Status of the cost observation. */
|
|
168
279
|
costStatus: 'reported' | 'unknown' | 'none' | (string & {});
|
|
169
280
|
}
|
|
281
|
+
/** User text or an ordered group of text and image elements with an optional input ID. */
|
|
170
282
|
export type SendInput = string | {
|
|
171
283
|
id?: string;
|
|
172
284
|
input: Array<TextInput | ImageInput>;
|
|
173
285
|
};
|
|
286
|
+
/** Text element in an ordered send. */
|
|
174
287
|
export interface TextInput {
|
|
288
|
+
/** Discriminant for a text element. */
|
|
175
289
|
type: 'text';
|
|
290
|
+
/** Text supplied to the agent. */
|
|
176
291
|
text: string;
|
|
292
|
+
/** Input source sent to Core. Defaults to user input. */
|
|
177
293
|
kind?: 'user' | 'app_event' | 'app_state';
|
|
178
294
|
}
|
|
295
|
+
/** Image in an ordered send. Supply a URI or encoded bytes. */
|
|
179
296
|
export interface ImageInput {
|
|
297
|
+
/** Discriminant for an image in an ordered send. */
|
|
180
298
|
type: 'image';
|
|
299
|
+
/** Media type of the encoded image, when supplied. */
|
|
181
300
|
mediaType?: string;
|
|
301
|
+
/** Image bytes encoded as Base64. */
|
|
182
302
|
data?: string;
|
|
303
|
+
/** URI passed to the host to load the image. */
|
|
183
304
|
uri?: string;
|
|
305
|
+
/** Optional text description of the image. */
|
|
184
306
|
alt?: string;
|
|
185
307
|
}
|
|
308
|
+
/** Response and cancellation options for `Agent.send` and `Agent.request`. */
|
|
186
309
|
export interface SendOptions {
|
|
310
|
+
/**
|
|
311
|
+
* Aborting before acceptance prevents the input from being queued. Once `send` accepts it,
|
|
312
|
+
* the signal has no effect on the input. Once `request` accepts it, aborting rejects the wait
|
|
313
|
+
* with `aborted` while the input continues. To cancel the input itself, call `Agent.cancel(id)`.
|
|
314
|
+
*/
|
|
187
315
|
signal?: AbortSignal;
|
|
316
|
+
/** Optional format supplied to Core for structured output. */
|
|
188
317
|
responseFormat?: ResponseFormat;
|
|
189
318
|
}
|
|
319
|
+
/** Structured response format to request from the model, as a JSON object or according to a JSON schema. */
|
|
190
320
|
export type ResponseFormat = {
|
|
191
321
|
type: 'json_schema';
|
|
192
322
|
json_schema: {
|
|
@@ -198,87 +328,245 @@ export type ResponseFormat = {
|
|
|
198
328
|
} | {
|
|
199
329
|
type: 'json_object';
|
|
200
330
|
};
|
|
331
|
+
/** Live agent subscription used to receive updates and request older transcript pages. */
|
|
201
332
|
export interface Subscription {
|
|
333
|
+
/** Load older messages into the same chat view when the user scrolls back. */
|
|
202
334
|
history(options: {
|
|
203
335
|
before?: number;
|
|
204
336
|
limit: number;
|
|
205
337
|
}): Promise<void>;
|
|
338
|
+
/** Stop routing updates to a chat view that has been dismissed. */
|
|
206
339
|
close(): void;
|
|
340
|
+
/** Whether Core has ended this subscription. */
|
|
207
341
|
readonly ended: boolean;
|
|
208
342
|
}
|
|
343
|
+
/** One saved memory item returned by the memory list. */
|
|
209
344
|
export interface MemoryItem {
|
|
345
|
+
/** Item ID used to select the fact for deletion. */
|
|
210
346
|
id: string;
|
|
347
|
+
/** Saved text for this item. */
|
|
211
348
|
text: string;
|
|
212
349
|
[k: string]: Json;
|
|
213
350
|
}
|
|
351
|
+
/**
|
|
352
|
+
* Options of every paged public list: `listAttachments`, `memory.list` and `wiki.list`.
|
|
353
|
+
* `limit` is a positive integer; a page holds at most 128 items, which is also the default.
|
|
354
|
+
* `cursor` is the opaque cursor of the previous page of the same list.
|
|
355
|
+
*/
|
|
356
|
+
export interface ListOptions {
|
|
357
|
+
/** Requested number of items, capped at 128. Omit to use 128. */
|
|
358
|
+
limit?: number;
|
|
359
|
+
/** Cursor returned by the previous page of the same list. */
|
|
360
|
+
cursor?: string;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* One page of a public list, in the list's stable order. `cursor` is present only when more
|
|
364
|
+
* items follow: pass it back with the same list to continue strictly past this page.
|
|
365
|
+
*/
|
|
366
|
+
export interface Page<T> {
|
|
367
|
+
/** Items returned in this page. */
|
|
368
|
+
items: T[];
|
|
369
|
+
/** Opaque cursor to pass back to this list when another page is available. */
|
|
370
|
+
cursor?: string;
|
|
371
|
+
}
|
|
372
|
+
/** Recorded moments use ISO 8601 strings; scheduling deadlines use epoch milliseconds. */
|
|
214
373
|
export type BackgroundEvent = {
|
|
215
374
|
type: 'delivered' | 'deadline' | 'cancelled' | 'skipped' | (string & {});
|
|
375
|
+
/** When the event happened, as an ISO 8601 string. */
|
|
216
376
|
at: string;
|
|
217
377
|
[k: string]: Json;
|
|
218
378
|
} & {
|
|
219
379
|
reason?: 'storage_unavailable' | 'os_registration_failed' | (string & {});
|
|
220
380
|
};
|
|
381
|
+
/** Settings for the host to register background delivery. */
|
|
221
382
|
export interface BackgroundOptions {
|
|
383
|
+
/** Optional receiver of Core background notifications. */
|
|
222
384
|
sink?: {
|
|
385
|
+
/** Let the app react when scheduled work was delivered or could not run. */
|
|
223
386
|
onEvent(event: BackgroundEvent): void;
|
|
224
387
|
};
|
|
225
|
-
storage
|
|
388
|
+
/** Host adapters for the background run. Use the same storage as the foreground session. */
|
|
389
|
+
adapters?: readonly Adapter[];
|
|
226
390
|
}
|
|
391
|
+
/** Action reported as available to the attached debugger. The set can grow. */
|
|
227
392
|
export type DebugCapability = 'agents.list' | 'status' | 'history' | 'send' | 'cancel' | 'tools' | (string & {});
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
393
|
+
import type { StateStore } from './pal/state-store.js';
|
|
394
|
+
export type { StateStore, StateCommitResult, StateCondition, StateEntry, StateListOptions, StateOp, StatePage, StateValue } from './pal/state-store.js';
|
|
395
|
+
export type StorageVersion = string;
|
|
396
|
+
export interface VersionedValue {
|
|
397
|
+
value: string | null;
|
|
398
|
+
version: StorageVersion | null;
|
|
399
|
+
}
|
|
400
|
+
export type WriteOutcome = {
|
|
401
|
+
type: 'written';
|
|
402
|
+
version: StorageVersion | null;
|
|
403
|
+
} | {
|
|
404
|
+
type: 'conflict';
|
|
405
|
+
version: StorageVersion | null;
|
|
406
|
+
};
|
|
407
|
+
/** A page of raw objects in one BlobStore prefix. */
|
|
408
|
+
export interface BlobListPage {
|
|
409
|
+
/** Objects and their sizes in bytes, in ascending UTF-8 key order. */
|
|
410
|
+
entries: Array<{
|
|
411
|
+
key: string;
|
|
412
|
+
size: number;
|
|
413
|
+
}>;
|
|
414
|
+
/** Opaque continuation for the same prefix, omitted on the last page. */
|
|
415
|
+
nextCursor?: string;
|
|
240
416
|
}
|
|
417
|
+
/** Raw objects. Core defines keys, ownership, budgets and cleanup. */
|
|
418
|
+
export interface BlobStore {
|
|
419
|
+
/** Selects the blob adapter. */
|
|
420
|
+
readonly kind: 'blob';
|
|
421
|
+
/**
|
|
422
|
+
* Keep an attachment available when the user returns to the conversation.
|
|
423
|
+
*
|
|
424
|
+
* Stores raw bytes, replacing an existing object at the same key.
|
|
425
|
+
*/
|
|
426
|
+
put(key: string, bytes: Uint8Array): Promise<void>;
|
|
427
|
+
/**
|
|
428
|
+
* Load the stored bytes when the app displays a file or uses it in a request.
|
|
429
|
+
*
|
|
430
|
+
* Returns raw bytes, or null if the object is missing.
|
|
431
|
+
*/
|
|
432
|
+
get(key: string): Promise<Uint8Array | null>;
|
|
433
|
+
/**
|
|
434
|
+
* Reclaim the file when the user deletes its owning data.
|
|
435
|
+
*
|
|
436
|
+
* Removes the object and succeeds if it is already missing.
|
|
437
|
+
*/
|
|
438
|
+
delete(key: string): Promise<void>;
|
|
439
|
+
/**
|
|
440
|
+
* Walk a user’s stored files in pages when measuring storage or completing deletion.
|
|
441
|
+
*
|
|
442
|
+
* Ascending UTF-8 key order. Pass a returned cursor back with the same prefix.
|
|
443
|
+
*/
|
|
444
|
+
list(prefix: string, cursor?: string): Promise<BlobListPage>;
|
|
445
|
+
}
|
|
446
|
+
/** Opaque platform value passed to the host when opening the runtime. */
|
|
241
447
|
export type PlatformHandle = unknown;
|
|
448
|
+
/** Callback and replay options for starting an agent subscription. */
|
|
242
449
|
export interface SubscribeOptions {
|
|
450
|
+
/** Update the transcript and controls together as the agent makes progress. */
|
|
243
451
|
onEvent: (event: AgentEvent) => void;
|
|
452
|
+
/** Number of recent messages to replay on attach. Omit to use Core's default. */
|
|
244
453
|
initialMessages?: number;
|
|
454
|
+
/** Resume after this cursor in its stream log. */
|
|
245
455
|
after?: {
|
|
456
|
+
/** Identifies the stream log to resume. */
|
|
246
457
|
logId: string;
|
|
458
|
+
/** Last sequence the app has already seen in the log. */
|
|
247
459
|
seq: number;
|
|
248
460
|
};
|
|
249
|
-
deltaMs?: number;
|
|
250
461
|
}
|
|
462
|
+
/** Outcome of a background delivery pass. */
|
|
251
463
|
export interface DeliverDueResult {
|
|
464
|
+
/** Whether Core reports that the delivery pass ran. */
|
|
252
465
|
ran: boolean;
|
|
466
|
+
/** Number of usage reports the runtime delivered in this run. */
|
|
253
467
|
delivered: number;
|
|
468
|
+
/** Agents and instances whose due work was deferred, with reasons. */
|
|
254
469
|
deferred: Array<{
|
|
255
|
-
user: string;
|
|
470
|
+
user: string | null;
|
|
256
471
|
agent: string;
|
|
257
472
|
instance: string | null;
|
|
258
473
|
code: 'deadline' | 'cancelled' | (string & {});
|
|
259
474
|
message: string;
|
|
260
475
|
}>;
|
|
261
476
|
}
|
|
477
|
+
/** Page of scheduled wakes returned by the host query. */
|
|
262
478
|
export interface WakeTimes {
|
|
479
|
+
/** Scheduled wakes included in this result. */
|
|
263
480
|
wakes: Array<{
|
|
264
|
-
user: string;
|
|
481
|
+
user: string | null;
|
|
482
|
+
/** Delivery deadline in epoch milliseconds. */
|
|
265
483
|
at: number;
|
|
266
484
|
}>;
|
|
485
|
+
/** Inclusive pagination deadline in epoch milliseconds; pass as wakeTimes query.after. */
|
|
267
486
|
next?: number;
|
|
268
487
|
}
|
|
488
|
+
/** Select an agent or one named instance for local deletion. An empty scope selects the user. */
|
|
269
489
|
export interface DeleteScope {
|
|
490
|
+
/** Agent whose local data is selected for deletion. */
|
|
270
491
|
agent?: string;
|
|
492
|
+
/** Named instance within the selected agent. */
|
|
271
493
|
instance?: string;
|
|
272
494
|
}
|
|
495
|
+
/** Connection details for attaching a debugger. */
|
|
273
496
|
export interface DebugAttachOptions {
|
|
497
|
+
/** Endpoint for the debugger connection. */
|
|
274
498
|
url: string;
|
|
499
|
+
/** Debugger access token. */
|
|
275
500
|
token: string;
|
|
276
501
|
}
|
|
502
|
+
/** Debugger attachment and the capabilities returned by Core. */
|
|
277
503
|
export interface AttachedDebugger {
|
|
504
|
+
/** Identifier returned for the attached debugger. */
|
|
278
505
|
debuggerId: string;
|
|
506
|
+
/** Capabilities that Core reports for the attached debugger. */
|
|
279
507
|
capabilities: DebugCapability[];
|
|
280
508
|
}
|
|
509
|
+
/** Access to the runtime debugger for the current session. */
|
|
281
510
|
export interface CrocheDebugger {
|
|
511
|
+
/** Inspect a running session when a development build behaves unexpectedly. */
|
|
282
512
|
attach(options: DebugAttachOptions): Promise<AttachedDebugger>;
|
|
513
|
+
/** End diagnostic access after the developer is done or the user withdraws permission. */
|
|
283
514
|
detach(): Promise<void>;
|
|
284
515
|
}
|
|
516
|
+
/**
|
|
517
|
+
* How Croche Cloud verified this installation (`croche.verification()`). Verification is not access: a withheld key
|
|
518
|
+
* leaves it unchanged. `unknown`: not registered yet, or Cloud did not say. `lastAttestation` is the device-side code
|
|
519
|
+
* of the last attestor attempt without a usable proof; null does not mean Cloud accepted a proof.
|
|
520
|
+
*/
|
|
521
|
+
export interface Verification {
|
|
522
|
+
/** Open-ended installation verification status reported by Core. */
|
|
523
|
+
status: 'attested' | 'server' | 'development' | 'unverified' | 'unknown' | (string & {});
|
|
524
|
+
/** Device-side code from the last attestor attempt that did not produce usable proof, if present. */
|
|
525
|
+
lastAttestation: 'attestation_unavailable' | 'attestation_unsupported' | 'attestation_failed' | 'attestation_timeout' | 'attestation_unusable' | (string & {}) | null;
|
|
526
|
+
}
|
|
527
|
+
/** App implementations replace host defaults only for their own kind. */
|
|
528
|
+
export type Adapter = BlobStore | ImageAdapter | StateStore;
|
|
529
|
+
/** Format and input capabilities supplied by an image adapter. */
|
|
530
|
+
export interface ImageSupport {
|
|
531
|
+
/** Source media types the adapter can read. */
|
|
532
|
+
inputMediaTypes: readonly string[];
|
|
533
|
+
/** Media types the adapter can produce. */
|
|
534
|
+
outputMediaTypes: readonly string[];
|
|
535
|
+
/** Upper pixel count advertised for input images, when specified. */
|
|
536
|
+
maxInputPixels?: number;
|
|
537
|
+
}
|
|
538
|
+
/** Width, height and alpha describe the orientation-applied (upright) first frame; resize uses the same geometry. mediaType describes the encoded input. */
|
|
539
|
+
export interface ImageInfo {
|
|
540
|
+
/** Detected media type of the source image. */
|
|
541
|
+
mediaType: string;
|
|
542
|
+
/** Upright first-frame width in pixels. */
|
|
543
|
+
width: number;
|
|
544
|
+
/** Upright first-frame height in pixels. */
|
|
545
|
+
height: number;
|
|
546
|
+
/** Whether the source has an alpha channel, when known. */
|
|
547
|
+
hasAlpha?: boolean;
|
|
548
|
+
}
|
|
549
|
+
/** Bounds and output formats for a resized model view. */
|
|
550
|
+
export interface ImageResizeLimits {
|
|
551
|
+
/** Maximum length of the longest side in pixels, when set. */
|
|
552
|
+
maxSide?: number;
|
|
553
|
+
/** Maximum encoded byte length of the resized image. */
|
|
554
|
+
maxBytes: number;
|
|
555
|
+
/** Accepted media types for the resized output. */
|
|
556
|
+
outputMediaTypes: readonly string[];
|
|
557
|
+
}
|
|
558
|
+
/** Host capability for inspecting and preparing encoded image bytes. */
|
|
559
|
+
export interface ImageAdapter {
|
|
560
|
+
/** Host adapter tag for image inspection and resizing. */
|
|
561
|
+
readonly kind: 'image';
|
|
562
|
+
/** Formats and input bounds advertised to Core by this adapter. */
|
|
563
|
+
readonly support: ImageSupport;
|
|
564
|
+
/** Find out whether a photo fits before preparing it for the selected model. */
|
|
565
|
+
info(bytes: Uint8Array, options: {
|
|
566
|
+
signal: AbortSignal;
|
|
567
|
+
}): Promise<ImageInfo>;
|
|
568
|
+
/** Fit a large photo within the model’s limits while keeping the user’s original. */
|
|
569
|
+
resize(bytes: Uint8Array, limits: ImageResizeLimits, options: {
|
|
570
|
+
signal: AbortSignal;
|
|
571
|
+
}): Promise<Uint8Array>;
|
|
572
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { CoreCancel, CoreModule } from './core/port.js';
|
|
2
2
|
/**
|
|
3
3
|
* A fresh Core token for one call, bridged to the app's AbortSignal when there is one (S1: Core borrows a token on
|
|
4
|
-
* every call). Already aborted = cancelled before the call (Core: never queued).
|
|
5
|
-
*
|
|
4
|
+
* every call). Already aborted = cancelled before the call (Core: never queued). Token disposal removes the
|
|
5
|
+
* listener at a request's terminal settlement. A send receipt retains it: the signal is cancel(id) after acceptance too.
|
|
6
6
|
*/
|
|
7
7
|
export declare function tokenFor(core: CoreModule, signal: AbortSignal | undefined): CoreCancel;
|
|
8
8
|
/** Core's token as the AbortSignal a tool's execute sees (`ctx.signal`). */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A fresh Core token for one call, bridged to the app's AbortSignal when there is one (S1: Core borrows a token on
|
|
3
|
-
* every call). Already aborted = cancelled before the call (Core: never queued).
|
|
4
|
-
*
|
|
3
|
+
* every call). Already aborted = cancelled before the call (Core: never queued). Token disposal removes the
|
|
4
|
+
* listener at a request's terminal settlement. A send receipt retains it: the signal is cancel(id) after acceptance too.
|
|
5
5
|
*/
|
|
6
6
|
export function tokenFor(core, signal) {
|
|
7
7
|
const token = core.newCancel();
|
|
@@ -9,8 +9,11 @@ export function tokenFor(core, signal) {
|
|
|
9
9
|
return token;
|
|
10
10
|
if (signal.aborted)
|
|
11
11
|
token.cancel();
|
|
12
|
-
else
|
|
13
|
-
|
|
12
|
+
else {
|
|
13
|
+
const abort = () => token.cancel();
|
|
14
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
15
|
+
token.onDispose?.(() => signal.removeEventListener('abort', abort));
|
|
16
|
+
}
|
|
14
17
|
return token;
|
|
15
18
|
}
|
|
16
19
|
/** Core's token as the AbortSignal a tool's execute sees (`ctx.signal`). */
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const sleeps = new Set();
|
|
2
|
+
let calls = 0;
|
|
3
|
+
let enabled = false;
|
|
4
|
+
export function enableNodeSleepTracking() { enabled = true; }
|
|
5
|
+
function settled() {
|
|
6
|
+
if (--calls === 0)
|
|
7
|
+
for (const timer of sleeps)
|
|
8
|
+
timer.unref?.();
|
|
9
|
+
}
|
|
10
|
+
export function foreground(invoke) {
|
|
11
|
+
if (!enabled)
|
|
12
|
+
return invoke();
|
|
13
|
+
if (calls++ === 0)
|
|
14
|
+
for (const timer of sleeps)
|
|
15
|
+
timer.ref?.();
|
|
16
|
+
let result;
|
|
17
|
+
try {
|
|
18
|
+
result = invoke();
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
settled();
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
if (result instanceof Promise)
|
|
25
|
+
return result.finally(settled);
|
|
26
|
+
settled();
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
// Only the Node PAL opts into keeping references to its pending sleeps.
|
|
30
|
+
export function nodeSleep(ms) {
|
|
31
|
+
return new Promise(resolve => {
|
|
32
|
+
const timer = setTimeout(() => {
|
|
33
|
+
sleeps.delete(timer);
|
|
34
|
+
resolve();
|
|
35
|
+
}, ms);
|
|
36
|
+
sleeps.add(timer);
|
|
37
|
+
if (calls === 0)
|
|
38
|
+
timer.unref?.();
|
|
39
|
+
});
|
|
40
|
+
}
|